use of org.apache.curator.retry.RetryNTimes in project microservices by pwillhan.
the class Zookeeper method register.
public void register() {
CuratorFramework curator = CuratorFrameworkFactory.newClient(host + ":" + port, new RetryNTimes(3, 3000));
curator.start();
try {
final ServiceInstance<Object> serviceInstance = ServiceInstance.builder().uriSpec(new UriSpec("{scheme}://{address}:{port}")).address(getIp()).port(getPort()).name("geolocation").build();
final ServiceDiscovery<Object> serviceDiscovery = ServiceDiscoveryBuilder.builder(Object.class).basePath("com.packt.microservices").client(curator).thisInstance(serviceInstance).build();
serviceDiscovery.start();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
serviceDiscovery.unregisterService(serviceInstance);
} catch (Exception e) {
System.err.println("Error while unregistering service in Zookeeper. Details: " + e.getMessage());
e.printStackTrace();
}
}));
} catch (Exception e) {
System.err.println("Error while registering service in Zookeeper. Details: " + e.getMessage());
e.printStackTrace();
}
}
use of org.apache.curator.retry.RetryNTimes in project pravega by pravega.
the class ZKStoreHelperTest method testEphemeralNode.
@Test(timeout = 30000)
public void testEphemeralNode() {
CuratorFramework cli2 = CuratorFrameworkFactory.newClient(zkServer.getConnectString(), new RetryNTimes(0, 0));
cli2.start();
ZKStoreHelper zkStoreHelper2 = new ZKStoreHelper(cli2, executor);
assertTrue(zkStoreHelper2.createEphemeralZNode("/testEphemeral", new byte[0]).join());
Assert.assertNotNull(zkStoreHelper2.getData("/testEphemeral", x -> x).join());
zkStoreHelper2.getClient().getZookeeperClient().close();
zkStoreHelper2.getClient().close();
// let session get expired.
// now read the data again. Verify that node no longer exists
AssertExtensions.assertFutureThrows("", Futures.delayedFuture(() -> zkStoreHelper.getData("/testEphemeral", x -> x), 1000, executor), e -> e instanceof StoreException.DataNotFoundException);
}
use of org.apache.curator.retry.RetryNTimes in project pravega by pravega.
the class ZkOrderedStoreTest method setup.
@Before
public void setup() throws Exception {
zkServer = new TestingServerStarter().start();
cli = CuratorFrameworkFactory.newClient(zkServer.getConnectString(), 10000, 10000, new RetryNTimes(0, 0));
cli.start();
zkStoreHelper = new ZKStoreHelper(cli, executor);
}
use of org.apache.curator.retry.RetryNTimes in project Saturn by vipshop.
the class NestedZkUtils method createClient.
public CuratorFramework createClient(String namespace) throws InterruptedException {
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
CuratorFramework curatorFramework = builder.connectString("127.0.0.1:" + PORT).sessionTimeoutMs(// long long, could to debug
600 * 1000).retryPolicy(new RetryNTimes(3, 1000)).namespace(namespace).build();
curatorFramework.start();
curatorFramework.blockUntilConnected();
return curatorFramework;
}
use of org.apache.curator.retry.RetryNTimes in project yyl_example by Relucent.
the class CuratorClientTest method main.
public static void main(String[] args) throws Exception {
// 1.Connect to zk
CuratorFramework client = CuratorFrameworkFactory.newClient(ZK_ADDRESS, new RetryNTimes(10, 5000));
client.start();
System.out.println("zk client start successfully!");
// 2.Client API test
// 2.1 Create node
String data1 = "hello";
print("create", ZK_PATH, data1);
client.create().creatingParentsIfNeeded().forPath(ZK_PATH, data1.getBytes());
// 2.2 Get node and data
print("ls", "/");
print(client.getChildren().forPath("/"));
print("get", ZK_PATH);
print(client.getData().forPath(ZK_PATH));
// 2.3 Modify data
String data2 = "world";
print("set", ZK_PATH, data2);
client.setData().forPath(ZK_PATH, data2.getBytes());
print("get", ZK_PATH);
print(client.getData().forPath(ZK_PATH));
// 2.4 Remove node
print("delete", ZK_PATH);
client.delete().forPath(ZK_PATH);
print("ls", "/");
print(client.getChildren().forPath("/"));
client.close();
}
Aggregations