use of org.apache.curator.retry.ExponentialBackoffRetry in project BRFS by zhangnianli.
the class DiscoveryExample method main.
public static void main(String[] args) throws Exception {
// This method is scaffolding to get the example up and running
CuratorFramework client = null;
ServiceDiscovery<InstanceDetails> serviceDiscovery = null;
Map<String, ServiceProvider<InstanceDetails>> providers = Maps.newHashMap();
try {
client = CuratorFrameworkFactory.newClient("192.168.101.86:2181", 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);
}
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project BRFS by zhangnianli.
the class TestServiceManager method main.
public static void main(String[] args) throws Exception {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
CuratorFramework client = CuratorFrameworkFactory.newClient(zk_address, 5 * 1000, 30 * 1000, retryPolicy);
client.start();
client.blockUntilConnected();
ServiceManager sm = new DefaultServiceManager(client.usingNamespace("test_c"));
sm.start();
sm.addServiceStateListener("ss_g", new ServiceStateListener() {
@Override
public void serviceRemoved(Service service) {
// TODO Auto-generated method stub
}
@Override
public void serviceAdded(Service service) {
System.out.println("##########################################before add " + service);
}
});
sm.registerService(new Service("ss_1", "ss_g", "localhost", 999));
Thread.sleep(1000);
sm.addServiceStateListener("ss_g", new ServiceStateListener() {
@Override
public void serviceRemoved(Service service) {
// TODO Auto-generated method stub
}
@Override
public void serviceAdded(Service service) {
System.out.println("##########################################after add " + service);
}
});
sm.addServiceStateListener("ss_g", new ServiceStateListener() {
@Override
public void serviceRemoved(Service service) {
// TODO Auto-generated method stub
}
@Override
public void serviceAdded(Service service) {
System.out.println("##########################################after_2 add " + service);
}
});
sm.registerService(new Service("ss_2", "ss_g", "localhost", 1222));
synchronized (sm) {
sm.wait();
}
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project BRFS by zhangnianli.
the class TestService method main.
public static void main(String[] args) throws Exception {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
CuratorFramework client = CuratorFrameworkFactory.newClient("192.168.101.86:2181", 3000, 3000, retryPolicy);
client.start();
client.blockUntilConnected();
ServiceManager sm = new DefaultServiceManager(client.usingNamespace("test"));
sm.start();
Service s = new Service();
s.setServiceGroup("group");
s.setServiceId("ser_" + ID);
s.setHost("local");
sm.registerService(s);
Service tmp = sm.getServiceById(s.getServiceGroup(), s.getServiceId());
System.out.println(tmp);
sm.addServiceStateListener("group", new ServiceStateListener() {
@Override
public void serviceRemoved(Service service) {
System.out.println("remove--" + service.getServiceId());
}
@Override
public void serviceAdded(Service service) {
System.out.println("add--" + service.getServiceId());
}
});
System.out.println(sm.getServiceById(s.getServiceGroup(), s.getServiceId()));
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project pravega by pravega.
the class ClusterZKTest method deregisterNode.
@Test(timeout = TEST_TIMEOUT)
public void deregisterNode() throws Exception {
LinkedBlockingQueue<String> nodeAddedQueue = new LinkedBlockingQueue<>();
LinkedBlockingQueue<String> nodeRemovedQueue = new LinkedBlockingQueue<>();
LinkedBlockingQueue<Exception> exceptionsQueue = new LinkedBlockingQueue<>();
@Cleanup CuratorFramework client2 = CuratorFrameworkFactory.builder().connectString(zkUrl).retryPolicy(new ExponentialBackoffRetry(RETRY_SLEEP_MS, MAX_RETRY)).namespace(CLUSTER_NAME_2).build();
@Cleanup Cluster clusterListener = new ClusterZKImpl(client2, ClusterType.HOST);
clusterListener.addListener((eventType, host) -> {
switch(eventType) {
case HOST_ADDED:
nodeAddedQueue.offer(host.getIpAddr());
break;
case HOST_REMOVED:
nodeRemovedQueue.offer(host.getIpAddr());
break;
case ERROR:
exceptionsQueue.offer(new RuntimeException("Encountered error"));
break;
default:
exceptionsQueue.offer(new RuntimeException("Unhandled case"));
break;
}
});
@Cleanup CuratorFramework client = CuratorFrameworkFactory.builder().connectString(zkUrl).retryPolicy(new ExponentialBackoffRetry(RETRY_SLEEP_MS, MAX_RETRY)).namespace(CLUSTER_NAME_2).build();
// Create Add a node to the cluster.
@Cleanup Cluster clusterZKInstance1 = new ClusterZKImpl(client, ClusterType.HOST);
clusterZKInstance1.registerHost(new Host(HOST_1, PORT, null));
assertEquals(HOST_1, nodeAddedQueue.poll(5, TimeUnit.SECONDS));
clusterZKInstance1.deregisterHost(new Host(HOST_1, PORT, null));
assertEquals(HOST_1, nodeRemovedQueue.poll(5, TimeUnit.SECONDS));
Exception exception = exceptionsQueue.poll();
if (exception != null) {
throw exception;
}
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project pravega by pravega.
the class ZKSegmentContainerMonitorTest method startClient.
private CuratorFramework startClient() {
val client = CuratorFrameworkFactory.newClient(zkUrl, new ExponentialBackoffRetry(RETRY_SLEEP_MS, MAX_RETRY));
client.start();
return client;
}
Aggregations