Search in sources :

Example 51 with ExponentialBackoffRetry

use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project airavata by apache.

the class Factory method getCuratorClient.

public static CuratorFramework getCuratorClient() throws ApplicationSettingsException {
    if (curatorClient == null) {
        synchronized (Factory.class) {
            if (curatorClient == null) {
                String connectionSting = ServerSettings.getZookeeperConnection();
                RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 5);
                curatorClient = CuratorFrameworkFactory.newClient(connectionSting, retryPolicy);
            }
        }
    }
    return curatorClient;
}
Also used : ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) LoggerFactory(org.slf4j.LoggerFactory) MessagingFactory(org.apache.airavata.messaging.core.MessagingFactory) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) RegistryFactory(org.apache.airavata.registry.core.experiment.catalog.impl.RegistryFactory) RetryPolicy(org.apache.curator.RetryPolicy)

Example 52 with ExponentialBackoffRetry

use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project airavata by apache.

the class DbEventManagerZkUtils method getCuratorClient.

/**
 *  Get curatorFramework instance
 * @return
 * @throws ApplicationSettingsException
 */
public static CuratorFramework getCuratorClient() throws ApplicationSettingsException {
    if (curatorClient == null) {
        synchronized (DbEventManagerZkUtils.class) {
            if (curatorClient == null) {
                String connectionSting = ServerSettings.getZookeeperConnection();
                RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 5);
                curatorClient = CuratorFrameworkFactory.newClient(connectionSting, retryPolicy);
            }
        }
    }
    return curatorClient;
}
Also used : ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) RetryPolicy(org.apache.curator.RetryPolicy)

Example 53 with ExponentialBackoffRetry

use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project airavata by apache.

the class OrchestratorServerHandler method startCurator.

private void startCurator() throws ApplicationSettingsException {
    String connectionSting = ServerSettings.getZookeeperConnection();
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 5);
    curatorClient = CuratorFrameworkFactory.newClient(connectionSting, retryPolicy);
    curatorClient.start();
}
Also used : ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) RetryPolicy(org.apache.curator.RetryPolicy)

Example 54 with ExponentialBackoffRetry

use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project Mycat_plus by coderczp.

the class ZKUtils method createConnection.

private static CuratorFramework createConnection() {
    String url = ZkConfig.getInstance().getZkURL();
    CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(url, new ExponentialBackoffRetry(100, 6));
    // start connection
    curatorFramework.start();
    // wait 3 second to establish connect
    try {
        curatorFramework.blockUntilConnected(3, TimeUnit.SECONDS);
        if (curatorFramework.getZookeeperClient().isConnected()) {
            return curatorFramework;
        }
    } catch (InterruptedException ignored) {
        Thread.currentThread().interrupt();
    }
    // fail situation
    curatorFramework.close();
    throw new RuntimeException("failed to connect to zookeeper service : " + url);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry)

Example 55 with ExponentialBackoffRetry

use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project Mycat_plus by coderczp.

the class DistributedSequenceHandler method initializeZK.

public void initializeZK(String zkAddress) {
    this.client = CuratorFrameworkFactory.newClient(zkAddress, new ExponentialBackoffRetry(1000, 3));
    this.client.start();
    try {
        if (client.checkExists().forPath(PATH.concat(INSTANCE_PATH)) == null) {
            client.create().creatingParentContainersIfNeeded().forPath(PATH.concat(INSTANCE_PATH));
        }
    } catch (Exception e) {
    // do nothing
    }
    this.leaderSelector = new LeaderSelector(client, PATH.concat(LEADER_PATH), this);
    this.leaderSelector.autoRequeue();
    this.leaderSelector.start();
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            try {
                while (leaderSelector.getLeader() == null) {
                    Thread.currentThread().yield();
                }
                if (!leaderSelector.hasLeadership()) {
                    isLeader = false;
                    if (slavePath != null && client.checkExists().forPath(slavePath) != null) {
                        return;
                    }
                    slavePath = client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath(PATH.concat("/instance/node"), "ready".getBytes());
                    while ("ready".equals(new String(client.getData().forPath(slavePath)))) {
                        Thread.currentThread().yield();
                    }
                    instanceId = Long.parseLong(new String(client.getData().forPath(slavePath)));
                    ready = true;
                }
            } catch (Exception e) {
                LOGGER.warn("Caught exception while handling zk!", e);
            }
        }
    };
    timerExecutor.scheduleAtFixedRate(runnable, 1L, 10L, TimeUnit.SECONDS);
}
Also used : ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) LeaderSelector(org.apache.curator.framework.recipes.leader.LeaderSelector) IOException(java.io.IOException) CancelLeadershipException(org.apache.curator.framework.recipes.leader.CancelLeadershipException)

Aggregations

ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)189 CuratorFramework (org.apache.curator.framework.CuratorFramework)113 RetryPolicy (org.apache.curator.RetryPolicy)46 Before (org.junit.Before)31 TestingCluster (org.apache.curator.test.TestingCluster)28 Test (org.testng.annotations.Test)23 TestingServer (org.apache.curator.test.TestingServer)19 IOException (java.io.IOException)18 Timing (org.apache.curator.test.Timing)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 ArrayList (java.util.ArrayList)14 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)12 ACLProvider (org.apache.curator.framework.api.ACLProvider)12 Test (org.junit.Test)12 ConnectionState (org.apache.curator.framework.state.ConnectionState)11 ExecutorService (java.util.concurrent.ExecutorService)10 ConnectionStateListener (org.apache.curator.framework.state.ConnectionStateListener)10 TestingServerStarter (io.pravega.test.common.TestingServerStarter)9 HashMap (java.util.HashMap)8 KeeperException (org.apache.zookeeper.KeeperException)8