Search in sources :

Example 1 with CONFIG_PROP_ZK_ADDRESS

use of org.apache.rocketmq.redis.replicator.conf.ReplicatorConstants.CONFIG_PROP_ZK_ADDRESS in project rocketmq-externals by apache.

the class RocketMQRedisReplicator method open.

@Override
public void open() throws IOException {
    if (this.replicator instanceof RedisSocketReplicator) {
        boolean single = configure.getString(DEPLOY_MODEL).equals(DEPLOY_MODEL_SINGLE);
        if (single) {
            this.replicator.open();
        } else {
            String address = configure.getString(CONFIG_PROP_ZK_ADDRESS);
            final CuratorFramework client = newClient(address, new ExponentialBackoffRetry(1000, 3));
            client.start();
            String path = ROOT_DIR + "/" + uri.getHost() + "-" + uri.getPort();
            final LeaderSelector selector = new LeaderSelector(client, path, new LeaderSelectorListenerAdapter() {

                @Override
                public void takeLeadership(final CuratorFramework client) throws Exception {
                    RocketMQRedisReplicator.this.addCloseListener(r -> client.close());
                    replicator.open();
                }
            });
            selector.start();
        }
    } else {
        this.replicator.open();
    }
}
Also used : Configuration(com.moilioncircle.redis.replicator.Configuration) RocketMQRedisProducer(org.apache.rocketmq.redis.replicator.mq.RocketMQRedisProducer) RdbVisitor(com.moilioncircle.redis.replicator.rdb.RdbVisitor) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) RedisReplicator(com.moilioncircle.redis.replicator.RedisReplicator) DEPLOY_MODEL_SINGLE(org.apache.rocketmq.redis.replicator.conf.ReplicatorConstants.DEPLOY_MODEL_SINGLE) LeaderSelector(org.apache.curator.framework.recipes.leader.LeaderSelector) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) REDIS_URI(org.apache.rocketmq.redis.replicator.conf.ReplicatorConstants.REDIS_URI) EventListener(com.moilioncircle.redis.replicator.event.EventListener) AbstractReplicator(com.moilioncircle.redis.replicator.AbstractReplicator) Logger(org.slf4j.Logger) Module(com.moilioncircle.redis.replicator.rdb.datatype.Module) IOException(java.io.IOException) ROOT_DIR(org.apache.rocketmq.redis.replicator.conf.ReplicatorConstants.ROOT_DIR) Command(com.moilioncircle.redis.replicator.cmd.Command) Configure(org.apache.rocketmq.redis.replicator.conf.Configure) CloseListener(com.moilioncircle.redis.replicator.CloseListener) Objects(java.util.Objects) DEPLOY_MODEL(org.apache.rocketmq.redis.replicator.conf.ReplicatorConstants.DEPLOY_MODEL) CuratorFramework(org.apache.curator.framework.CuratorFramework) CONFIG_PROP_ZK_ADDRESS(org.apache.rocketmq.redis.replicator.conf.ReplicatorConstants.CONFIG_PROP_ZK_ADDRESS) RedisSocketReplicator(com.moilioncircle.redis.replicator.RedisSocketReplicator) Replicator(com.moilioncircle.redis.replicator.Replicator) ModuleParser(com.moilioncircle.redis.replicator.rdb.module.ModuleParser) CommandName(com.moilioncircle.redis.replicator.cmd.CommandName) CommandParser(com.moilioncircle.redis.replicator.cmd.CommandParser) RedisURI(com.moilioncircle.redis.replicator.RedisURI) LeaderSelectorListenerAdapter(org.apache.curator.framework.recipes.leader.LeaderSelectorListenerAdapter) CuratorFrameworkFactory.newClient(org.apache.curator.framework.CuratorFrameworkFactory.newClient) ExceptionListener(com.moilioncircle.redis.replicator.ExceptionListener) CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) LeaderSelector(org.apache.curator.framework.recipes.leader.LeaderSelector) LeaderSelectorListenerAdapter(org.apache.curator.framework.recipes.leader.LeaderSelectorListenerAdapter) RedisSocketReplicator(com.moilioncircle.redis.replicator.RedisSocketReplicator) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Aggregations

AbstractReplicator (com.moilioncircle.redis.replicator.AbstractReplicator)1 CloseListener (com.moilioncircle.redis.replicator.CloseListener)1 Configuration (com.moilioncircle.redis.replicator.Configuration)1 ExceptionListener (com.moilioncircle.redis.replicator.ExceptionListener)1 RedisReplicator (com.moilioncircle.redis.replicator.RedisReplicator)1 RedisSocketReplicator (com.moilioncircle.redis.replicator.RedisSocketReplicator)1 RedisURI (com.moilioncircle.redis.replicator.RedisURI)1 Replicator (com.moilioncircle.redis.replicator.Replicator)1 Command (com.moilioncircle.redis.replicator.cmd.Command)1 CommandName (com.moilioncircle.redis.replicator.cmd.CommandName)1 CommandParser (com.moilioncircle.redis.replicator.cmd.CommandParser)1 EventListener (com.moilioncircle.redis.replicator.event.EventListener)1 RdbVisitor (com.moilioncircle.redis.replicator.rdb.RdbVisitor)1 Module (com.moilioncircle.redis.replicator.rdb.datatype.Module)1 ModuleParser (com.moilioncircle.redis.replicator.rdb.module.ModuleParser)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 Objects (java.util.Objects)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 CuratorFrameworkFactory.newClient (org.apache.curator.framework.CuratorFrameworkFactory.newClient)1