use of org.apache.curator.RetryPolicy in project BRFS by zhangnianli.
the class Test method main.
public static void main(String[] args) throws Exception {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
CuratorFramework client = CuratorFrameworkFactory.newClient(zk_address, retryPolicy);
client.start();
StorageNameManager snm = new DefaultStorageNameManager(client.usingNamespace("test"));
snm.start();
// Thread.sleep(2000);
StorageNameNode node = snm.createStorageName("sn_1", 2, 100);
System.out.println("create node--" + node);
StorageNameNode node2 = snm.createStorageName("sn_2", 2, 100);
System.out.println("create node--" + node2);
System.out.println("find node--" + snm.findStorageName("sn_1"));
// Thread.sleep(1000);
System.out.println("delete--" + snm.removeStorageName("sn_1"));
// System.out.println("find node--" + snm.findStorageName("sn_1"));
System.out.println("update--" + snm.updateStorageName("sn_2", 110));
synchronized (client) {
client.wait();
}
}
use of org.apache.curator.RetryPolicy in project nifi by apache.
the class Cluster method createCuratorClient.
public CuratorFramework createCuratorClient() {
final RetryPolicy retryPolicy = new RetryNTimes(20, 500);
final CuratorFramework curatorClient = CuratorFrameworkFactory.builder().connectString(getZooKeeperConnectString()).sessionTimeoutMs(3000).connectionTimeoutMs(3000).retryPolicy(retryPolicy).defaultData(new byte[0]).build();
curatorClient.start();
return curatorClient;
}
use of org.apache.curator.RetryPolicy in project metron by apache.
the class ProfileBuilderBolt method setupZookeeper.
private void setupZookeeper() {
try {
if (zookeeperClient == null) {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
zookeeperClient = CuratorFrameworkFactory.newClient(zookeeperUrl, retryPolicy);
}
zookeeperClient.start();
// this is temporary to ensure that any validation passes. the individual bolt
// will reinitialize stellar to dynamically pull from zookeeper.
ConfigurationsUtils.setupStellarStatically(zookeeperClient);
if (zookeeperCache == null) {
ConfigurationsUpdater<ProfilerConfigurations> updater = createUpdater();
SimpleEventListener listener = new SimpleEventListener.Builder().with(updater::update, TreeCacheEvent.Type.NODE_ADDED, TreeCacheEvent.Type.NODE_UPDATED).with(updater::delete, TreeCacheEvent.Type.NODE_REMOVED).build();
zookeeperCache = new ZKCache.Builder().withClient(zookeeperClient).withListener(listener).withRoot(Constants.ZOOKEEPER_TOPOLOGY_ROOT).build();
updater.forceUpdate(zookeeperClient);
zookeeperCache.start();
}
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
use of org.apache.curator.RetryPolicy in project metron by apache.
the class ConfiguredBolt method prepCache.
protected void prepCache() {
try {
if (client == null) {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
client = CuratorFrameworkFactory.newClient(zookeeperUrl, retryPolicy);
}
client.start();
// this is temporary to ensure that any validation passes.
// The individual bolt will reinitialize stellar to dynamically pull from
// zookeeper.
ConfigurationsUtils.setupStellarStatically(client);
if (cache == null) {
ConfigurationsUpdater<CONFIG_T> updater = createUpdater();
SimpleEventListener listener = new SimpleEventListener.Builder().with(updater::update, TreeCacheEvent.Type.NODE_ADDED, TreeCacheEvent.Type.NODE_UPDATED).with(updater::delete, TreeCacheEvent.Type.NODE_REMOVED).build();
cache = new ZKCache.Builder().withClient(client).withListener(listener).withRoot(Constants.ZOOKEEPER_TOPOLOGY_ROOT).build();
updater.forceUpdate(client);
cache.start();
}
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
use of org.apache.curator.RetryPolicy in project xian by happyyangyuan.
the class TestFrameworkEdges method testRetry.
@Test
public void testRetry() throws Exception {
final int MAX_RETRIES = 3;
final CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(10));
client.start();
try {
final AtomicInteger retries = new AtomicInteger(0);
final Semaphore semaphore = new Semaphore(0);
RetryPolicy policy = new RetryPolicy() {
@Override
public boolean allowRetry(int retryCount, long elapsedTimeMs, RetrySleeper sleeper) {
semaphore.release();
if (retries.incrementAndGet() == MAX_RETRIES) {
try {
server.restart();
} catch (Exception e) {
throw new Error(e);
}
}
try {
sleeper.sleepFor(100, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return true;
}
};
client.getZookeeperClient().setRetryPolicy(policy);
server.stop();
// test foreground retry
client.checkExists().forPath("/hey");
Assert.assertTrue(semaphore.tryAcquire(MAX_RETRIES, timing.forWaiting().seconds(), TimeUnit.SECONDS), "Remaining leases: " + semaphore.availablePermits());
// make sure we're reconnected
client.getZookeeperClient().setRetryPolicy(new RetryOneTime(100));
client.checkExists().forPath("/hey");
client.getZookeeperClient().setRetryPolicy(policy);
semaphore.drainPermits();
retries.set(0);
server.stop();
// test background retry
client.checkExists().inBackground().forPath("/hey");
Assert.assertTrue(semaphore.tryAcquire(MAX_RETRIES, timing.forWaiting().seconds(), TimeUnit.SECONDS), "Remaining leases: " + semaphore.availablePermits());
} finally {
CloseableUtils.closeQuietly(client);
}
}
Aggregations