use of org.apache.curator.retry.ExponentialBackoffRetry in project xian by happyyangyuan.
the class TestRetryLoop method testExponentialBackoffRetryLimit.
@Test
public void testExponentialBackoffRetryLimit() {
RetrySleeper sleeper = new RetrySleeper() {
@Override
public void sleepFor(long time, TimeUnit unit) throws InterruptedException {
Assert.assertTrue(unit.toMillis(time) <= 100);
}
};
ExponentialBackoffRetry retry = new ExponentialBackoffRetry(1, Integer.MAX_VALUE, 100);
for (int i = 0; i >= 0; ++i) {
retry.allowRetry(i, 0, sleeper);
}
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project xian by happyyangyuan.
the class TestExhibitorEnsembleProvider method testSimple.
@Test
public void testSimple() throws Exception {
Exhibitors exhibitors = new Exhibitors(Lists.newArrayList("foo", "bar"), 1000, dummyConnectionStringProvider);
ExhibitorRestClient mockRestClient = new ExhibitorRestClient() {
@Override
public String getRaw(String hostname, int port, String uriPath, String mimeType) throws Exception {
return "count=1&port=" + server.getPort() + "&server0=localhost";
}
};
ExhibitorEnsembleProvider provider = new ExhibitorEnsembleProvider(exhibitors, mockRestClient, "/foo", 10, new RetryOneTime(1));
provider.pollForInitialEnsemble();
Timing timing = new Timing();
CuratorZookeeperClient client = new CuratorZookeeperClient(provider, timing.session(), timing.connection(), null, new ExponentialBackoffRetry(timing.milliseconds(), 3));
client.start();
try {
client.blockUntilConnectedOrTimedOut();
client.getZooKeeper().exists("/", false);
} catch (Exception e) {
Assert.fail("provider.getConnectionString(): " + provider.getConnectionString() + " server.getPort(): " + server.getPort(), e);
} finally {
client.close();
}
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project xian by happyyangyuan.
the class ZkConnection method start.
// 仅供内部测试使用
public static void start(String connectionStr) {
synchronized (zkConnectionStartStopLock) {
if (connected.get()) {
LOG.info("zkConnection已经启动,不再重复启动");
return;
}
try {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
client = CuratorFrameworkFactory.newClient(connectionStr, retryPolicy);
client.start();
LOG.info("阻塞直到与zookeeper连接建立完毕!");
client.blockUntilConnected();
} catch (Throwable e) {
LOG.error(e);
} finally {
connected.set(true);
}
}
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project xian by happyyangyuan.
the class DiscoveryExample method main.
public static void main(String[] args) throws Exception {
// This method is scaffolding to get the example up and running
TestingServer server = new TestingServer();
CuratorFramework client = null;
ServiceDiscovery<InstanceDetails> serviceDiscovery = null;
Map<String, ServiceProvider<InstanceDetails>> providers = Maps.newHashMap();
try {
client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3));
client.start();
JsonInstanceSerializer<InstanceDetails> serializer = new JsonInstanceSerializer<InstanceDetails>(InstanceDetails.class);
serviceDiscovery = ServiceDiscoveryBuilder.builder(InstanceDetails.class).client(client).basePath(PATH).serializer(serializer).build();
serviceDiscovery.start();
processCommands(serviceDiscovery, providers, client);
} finally {
for (ServiceProvider<InstanceDetails> cache : providers.values()) {
CloseableUtils.closeQuietly(cache);
}
CloseableUtils.closeQuietly(serviceDiscovery);
CloseableUtils.closeQuietly(client);
CloseableUtils.closeQuietly(server);
}
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project phoenix by apache.
the class LoadBalancer method start.
private void start() throws Exception {
curaFramework = CuratorFrameworkFactory.newClient(getZkConnectString(), new ExponentialBackoffRetry(1000, 3));
curaFramework.start();
curaFramework.setACL().withACL(CONFIG.getAcls());
connectionStateListener = getConnectionStateListener();
curaFramework.getConnectionStateListenable().addListener(connectionStateListener);
unhandledErrorListener = getUnhandledErrorListener();
curaFramework.getUnhandledErrorListenable().addListener(unhandledErrorListener);
cache = new PathChildrenCache(curaFramework, CONFIG.getParentPath(), true);
cache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
closeAbles.add(cache);
closeAbles.add(curaFramework);
}
Aggregations