Search in sources :

Example 61 with RetryPolicy

use of org.apache.curator.RetryPolicy in project metron by apache.

the class TestConfig method client.

@Bean(initMethod = "start", destroyMethod = "close")
public CuratorFramework client(ComponentRunner componentRunner) {
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
    ZKServerComponent zkServerComponent = componentRunner.getComponent("zk", ZKServerComponent.class);
    return CuratorFrameworkFactory.newClient(zkServerComponent.getConnectionString(), retryPolicy);
}
Also used : ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ZKServerComponent(org.apache.metron.integration.components.ZKServerComponent) RetryPolicy(org.apache.curator.RetryPolicy) Bean(org.springframework.context.annotation.Bean)

Example 62 with RetryPolicy

use of org.apache.curator.RetryPolicy in project metron by apache.

the class ZookeeperConfig method client.

@Bean(initMethod = "start", destroyMethod = "close")
public CuratorFramework client(Environment environment) {
    int sleepTime = Integer.parseInt(environment.getProperty(MetronRestConstants.CURATOR_SLEEP_TIME));
    int maxRetries = Integer.parseInt(environment.getProperty(MetronRestConstants.CURATOR_MAX_RETRIES));
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(sleepTime, maxRetries);
    CuratorFramework ret = CuratorFrameworkFactory.newClient(environment.getProperty(MetronRestConstants.ZK_URL_SPRING_PROPERTY), retryPolicy);
    return ret;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) RetryPolicy(org.apache.curator.RetryPolicy) Bean(org.springframework.context.annotation.Bean)

Example 63 with RetryPolicy

use of org.apache.curator.RetryPolicy in project tutorials by eugenp.

the class BaseTest method newClient.

protected CuratorFramework newClient() {
    int sleepMsBetweenRetries = 100;
    int maxRetries = 3;
    RetryPolicy retryPolicy = new RetryNTimes(maxRetries, sleepMsBetweenRetries);
    return CuratorFrameworkFactory.newClient("127.0.0.1:2181", retryPolicy);
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) RetryPolicy(org.apache.curator.RetryPolicy)

Example 64 with RetryPolicy

use of org.apache.curator.RetryPolicy in project tutorials by eugenp.

the class ConnectionManagementManualTest method givenRunningZookeeper_whenOpenConnection_thenClientIsOpened.

@Test
public void givenRunningZookeeper_whenOpenConnection_thenClientIsOpened() throws Exception {
    int sleepMsBetweenRetries = 100;
    int maxRetries = 3;
    RetryPolicy retryPolicy = new RetryNTimes(maxRetries, sleepMsBetweenRetries);
    try (CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", retryPolicy)) {
        client.start();
        assertThat(client.checkExists().forPath("/")).isNotNull();
    }
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) CuratorFramework(org.apache.curator.framework.CuratorFramework) AsyncCuratorFramework(org.apache.curator.x.async.AsyncCuratorFramework) RetryPolicy(org.apache.curator.RetryPolicy) Test(org.junit.Test)

Example 65 with RetryPolicy

use of org.apache.curator.RetryPolicy in project tutorials by eugenp.

the class ConnectionManagementManualTest method givenRunningZookeeper_whenOpenConnectionUsingAsyncBlocking_thenClientIsOpened.

@Test
public void givenRunningZookeeper_whenOpenConnectionUsingAsyncBlocking_thenClientIsOpened() throws InterruptedException {
    int sleepMsBetweenRetries = 100;
    int maxRetries = 3;
    RetryPolicy retryPolicy = new RetryNTimes(maxRetries, sleepMsBetweenRetries);
    try (CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", retryPolicy)) {
        client.start();
        AsyncCuratorFramework async = AsyncCuratorFramework.wrap(client);
        AtomicBoolean exists = new AtomicBoolean(false);
        async.checkExists().forPath("/").thenAccept(s -> exists.set(s != null));
        await().until(() -> assertThat(exists.get()).isTrue());
    }
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CuratorFramework(org.apache.curator.framework.CuratorFramework) AsyncCuratorFramework(org.apache.curator.x.async.AsyncCuratorFramework) AsyncCuratorFramework(org.apache.curator.x.async.AsyncCuratorFramework) RetryPolicy(org.apache.curator.RetryPolicy) Test(org.junit.Test)

Aggregations

RetryPolicy (org.apache.curator.RetryPolicy)69 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)47 CuratorFramework (org.apache.curator.framework.CuratorFramework)42 RetryNTimes (org.apache.curator.retry.RetryNTimes)12 IOException (java.io.IOException)10 ACLProvider (org.apache.curator.framework.api.ACLProvider)7 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)6 TestingServer (org.apache.curator.test.TestingServer)5 DefaultZooKeeperClient (com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient)4 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)4 SimpleEventListener (org.apache.metron.zookeeper.SimpleEventListener)4 ZKCache (org.apache.metron.zookeeper.ZKCache)4 ACL (org.apache.zookeeper.data.ACL)4 Before (org.junit.Before)4 DefaultServiceManager (com.bonree.brfs.common.service.impl.DefaultServiceManager)3 AuthInfo (org.apache.curator.framework.AuthInfo)3 PathChildrenCache (org.apache.curator.framework.recipes.cache.PathChildrenCache)3 Test (org.junit.Test)3 Service (com.bonree.brfs.common.service.Service)2 ServiceManager (com.bonree.brfs.common.service.ServiceManager)2