client = CuratorFrameworkFactory.newClient(zkQuorum, retryPolicy); client.start(); MaaSConfig config = ConfigUtil.INSTANCE.read(client, zkRoot, new MaaSConfig(), MaaSConfig.class); JsonInstanceSerializer<ModelEndpoint> serializer = new JsonInstanceSerializer<>(ModelEndpoint.class); CloseableUtils.closeQuietly(serviceDiscovery); CloseableUtils.closeQuietly(client);
public static void main(String[] args) throws Exception { TestingServer server = new TestingServer(); CuratorFramework client = null; NodeCache cache = null; try { client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3)); client.start(); cache = new NodeCache(client, PATH); cache.start(); processCommands(client, cache); } finally { CloseableUtils.closeQuietly(cache); CloseableUtils.closeQuietly(client); CloseableUtils.closeQuietly(server); } }
public static void main(String[] args) throws Exception { TestingServer server = new TestingServer(); CuratorFramework client = null; try { client = createSimple(server.getConnectString()); client.start(); client.create().creatingParentsIfNeeded().forPath(PATH, "test".getBytes()); CloseableUtils.closeQuietly(client); client = createWithOptions(server.getConnectString(), new ExponentialBackoffRetry(1000, 3), 1000, 1000); client.start(); System.out.println(new String(client.getData().forPath(PATH))); } catch (Exception ex) { ex.printStackTrace(); } finally { CloseableUtils.closeQuietly(client); CloseableUtils.closeQuietly(server); } }
private void initialClient() { if (!isInitialized.compareAndSet(false, true)) { return; } if (client == null && StringUtils.isEmpty(address)) { throw new RuntimeException("zookeeper server address is not set."); } boolean connected = false; try { if (client == null) { RetryPolicy retryPolicy = new ExponentialBackoffRetry(baseSleepTimeMs, maxRetries); client = CuratorFrameworkFactory.builder().connectString(address).retryPolicy(retryPolicy) .connectionTimeoutMs(connectionTimeout).sessionTimeoutMs(sessionTimeout).build(); } client.start(); connected = client.blockUntilConnected(connectionTimeout, TimeUnit.MILLISECONDS); if (!connected) { throw new RuntimeException("connect zookeeper failed."); } } catch (Exception e) { CloseableUtils.closeQuietly(client); isInitialized.compareAndSet(true, false); throw new RuntimeException("init zookeeper client error.", e); } }
public static void main(String[] args) throws Exception { TestingServer server = new TestingServer(); CuratorFramework client = null; TreeCache cache = null; try { client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3)); client.start(); cache = new TreeCache(client, PATH); cache.start(); processCommands(client, cache); } finally { CloseableUtils.closeQuietly(cache); CloseableUtils.closeQuietly(client); CloseableUtils.closeQuietly(server); } }
public static void main(String[] args) throws Exception { TestingServer server = new TestingServer(); CuratorFramework client = null; try { client = createSimple(server.getConnectString()); client.start(); ZKPaths.mkdirs(client.getZookeeperClient().getZooKeeper(),"/a"); ZKPaths.mkdirs(client.getZookeeperClient().getZooKeeper(),"/another/path"); ZKPaths.mkdirs(client.getZookeeperClient().getZooKeeper(),"/yet/another/path"); transaction(client); } catch (Exception ex) { ex.printStackTrace(); } finally { CloseableUtils.closeQuietly(client); CloseableUtils.closeQuietly(server); } }
public static void main(String[] args) throws Exception { TestingServer server = new TestingServer(); CuratorFramework client = null; PathChildrenCache cache = null; try { client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3)); client.start(); // in this example we will cache data. Notice that this is optional. cache = new PathChildrenCache(client, PATH, true); cache.start(); processCommands(client, cache); } finally { CloseableUtils.closeQuietly(cache); CloseableUtils.closeQuietly(client); CloseableUtils.closeQuietly(server); } }
public static void main(String[] args) throws Exception { List<CuratorFramework> clients = Lists.newArrayList(); List<ExampleClient> examples = Lists.newArrayList(); TestingServer server = new TestingServer(); try { for (int i = 0; i < CLIENT_QTY; ++i) { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3)); clients.add(client); ExampleClient example = new ExampleClient(client, PATH, "Client #" + i); examples.add(example); client.start(); example.start(); } System.out.println("Press enter/return to quit\n"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } finally { System.out.println("Shutting down..."); for (ExampleClient exampleClient : examples) { CloseableUtils.closeQuietly(exampleClient); } for (CuratorFramework client : clients) { CloseableUtils.closeQuietly(client); } CloseableUtils.closeQuietly(server); } } }
public static void main(String[] args) throws Exception { TestingServer server = new TestingServer(); CuratorFramework client = null; PathChildrenCache cache = null; try { client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3)); client.start(); // in this example we will cache data. Notice that this is optional. cache = new PathChildrenCache(client, PATH, true); cache.start(); processCommands(client, cache); } finally { CloseableUtils.closeQuietly(cache); CloseableUtils.closeQuietly(client); CloseableUtils.closeQuietly(server); } }
@Override public Void call() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3)); try { client.start(); final ExampleClientReentrantLocks example = new ExampleClientReentrantLocks(client, PATH, resource, "Client " + index); for (int j = 0; j < REPETITIONS; ++j) { example.doWork(10, TimeUnit.SECONDS); } }catch ( InterruptedException e ) { Thread.currentThread().interrupt(); } catch (Throwable e) { e.printStackTrace(); } finally { CloseableUtils.closeQuietly(client); } return null; } };
@Override public Void call() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3)); try { client.start(); final ExampleClientReadWriteLocks example = new ExampleClientReadWriteLocks(client, PATH, resource, "Client " + index); for (int j = 0; j < REPETITIONS; ++j) { example.doWork(10, TimeUnit.SECONDS); } }catch ( InterruptedException e ) { Thread.currentThread().interrupt(); } catch (Throwable e) { e.printStackTrace(); } finally { CloseableUtils.closeQuietly(client); } return null; } };
@Override public Void call() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3)); try { client.start(); ExampleClientThatLocks example = new ExampleClientThatLocks(client, PATH, resource, "Client " + index); for ( int j = 0; j < REPETITIONS; ++j ) { example.doWork(10, TimeUnit.SECONDS); } } catch ( InterruptedException e ) { Thread.currentThread().interrupt(); } catch ( Exception e ) { e.printStackTrace(); // log or do something } finally { CloseableUtils.closeQuietly(client); } return null; } };
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3)); clients.add(client); examples.add(example); client.start(); example.start(); CloseableUtils.closeQuietly(exampleClient); CloseableUtils.closeQuietly(client); CloseableUtils.closeQuietly(server);
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); } }
PersistentNode node = null; try { client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3)); client.getConnectionStateListenable().addListener(new ConnectionStateListener() { client.start(); ex.printStackTrace(); } finally { CloseableUtils.closeQuietly(node); CloseableUtils.closeQuietly(client); CloseableUtils.closeQuietly(server);
SimpleDistributedQueue queue = null; try { client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3)); client.getCuratorListenable().addListener(new CuratorListener() { @Override client.start(); queue = new SimpleDistributedQueue(client, PATH); for (int i = 0; i < 10; i++) { CloseableUtils.closeQuietly(client); CloseableUtils.closeQuietly(server);
try { for (int i = 0; i < CLIENT_QTY; ++i) { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3)); clients.add(client); LeaderLatch example = new LeaderLatch(client, PATH, "Client #" + i); examples.add(example); client.start(); example.start(); System.out.println("Shutting down..."); for (LeaderLatch exampleClient : examples) { CloseableUtils.closeQuietly(exampleClient); CloseableUtils.closeQuietly(client); CloseableUtils.closeQuietly(server);
DistributedDelayQueue<String> queue = null; try { client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3)); client.getCuratorListenable().addListener(new CuratorListener() { @Override client.start(); QueueConsumer<String> consumer = createQueueConsumer(); QueueBuilder<String> builder = QueueBuilder.builder(client, consumer, createQueueSerializer(), PATH); CloseableUtils.closeQuietly(queue); CloseableUtils.closeQuietly(client); CloseableUtils.closeQuietly(server);
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); } }
DistributedPriorityQueue<String> queue = null; try { client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3)); client.getCuratorListenable().addListener(new CuratorListener() { @Override client.start(); QueueConsumer<String> consumer = createQueueConsumer(); QueueBuilder<String> builder = QueueBuilder.builder(client, consumer, createQueueSerializer(), PATH); CloseableUtils.closeQuietly(queue); CloseableUtils.closeQuietly(client); CloseableUtils.closeQuietly(server);