org.apache.curator.framework.CuratorFramework - java examples

Here are the examples of the java api org.apache.curator.framework.CuratorFramework taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

19 View Complete Implementation : BlockingQueueConsumer.java
Copyright Apache License 2.0
Author : apache
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
    connectionStateListener.stateChanged(client, newState);
}

19 View Complete Implementation : TestInterProcessSemaphoreMutex.java
Copyright Apache License 2.0
Author : apache
@Override
protected InterProcessLock makeLock(CuratorFramework client) {
    return new InterProcessSemapreplacedMutex(client, LOCK_PATH);
}

19 View Complete Implementation : ServiceCacheLeakTester.java
Copyright Apache License 2.0
Author : apache
private static void doWork(CuratorFramework curatorFramework) throws Exception {
    ServiceInstance<Void> thisInstance = ServiceInstance.<Void>builder().name("myservice").build();
    final ServiceDiscovery<Void> serviceDiscovery = ServiceDiscoveryBuilder.builder(Void.clreplaced).client(curatorFramework.usingNamespace("dev")).basePath("/instances").thisInstance(thisInstance).build();
    serviceDiscovery.start();
    for (int i = 0; i < 100000; i++) {
        final ServiceProvider<Void> s = serviceProvider(serviceDiscovery, "myservice");
        s.start();
        try {
            s.getInstance().buildUriSpec();
        } finally {
            s.close();
        }
    }
}

19 View Complete Implementation : TestInterProcessMutexBase.java
Copyright Apache License 2.0
Author : apache
protected abstract InterProcessLock makeLock(CuratorFramework client);

19 View Complete Implementation : TestPersistentEphemeralNode.java
Copyright Apache License 2.0
Author : apache
private void replacedertNodeDoesNotExist(CuratorFramework curator, String path) throws Exception {
    replacedertTrue(curator.checkExists().forPath(path) == null);
}

19 View Complete Implementation : TestCompatibility.java
Copyright Apache License 2.0
Author : apache
@Test(expectedExceptions = IllegalStateException.clreplaced)
public void testGetConfig() throws Exception {
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    client.start();
    try {
        client.getConfig().forEnsemble();
    } finally {
        CloseableUtils.closeQuietly(client);
    }
}

19 View Complete Implementation : CrudExamples.java
Copyright Apache License 2.0
Author : apache
public static void setData(CuratorFramework client, String path, byte[] payload) throws Exception {
    // set data for the given node
    client.setData().forPath(path, payload);
}

19 View Complete Implementation : StandardLockInternalsDriver.java
Copyright Apache License 2.0
Author : apache
@Override
public String createsTheLock(CuratorFramework client, String path, byte[] lockNodeBytes) throws Exception {
    String ourPath;
    if (lockNodeBytes != null) {
        ourPath = client.create().creatingParentContainersIfNeeded().withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath(path, lockNodeBytes);
    } else {
        ourPath = client.create().creatingParentContainersIfNeeded().withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath(path);
    }
    return ourPath;
}

19 View Complete Implementation : ParserUpdater.java
Copyright Apache License 2.0
Author : apache
@Override
public void forceUpdate(CuratorFramework client) {
    try {
        ConfigurationsUtils.updateParserConfigsFromZookeeper(getConfigurations(), client);
    } catch (KeeperException.NoNodeException nne) {
        LOG.warn("No current parser configs in zookeeper, but the cache should load lazily...");
    } catch (Exception e) {
        LOG.warn("Unable to load configs from zookeeper, but the cache should load lazily...", e);
    }
}

19 View Complete Implementation : CrudExamples.java
Copyright Apache License 2.0
Author : apache
public static void guaranteedDelete(CuratorFramework client, String path) throws Exception {
    // delete the given node and guarantee that it completes
    /*
            Guaranteed Delete

            Solves this edge case: deleting a node can fail due to connection issues. Further, if the node was
            ephemeral, the node will not get auto-deleted as the session is still valid. This can wreak havoc
            with lock implementations.


            When guaranteed is set, Curator will record failed node deletions and attempt to delete them in the
            background until successful. NOTE: you will still get an exception when the deletion fails. But, you
            can be replacedured that as long as the CuratorFramework instance is open attempts will be made to delete
            the node.
         */
    client.delete().guaranteed().forPath(path);
}

19 View Complete Implementation : GroupMember.java
Copyright Apache License 2.0
Author : apache
protected PersistentEphemeralNode newPersistentEphemeralNode(CuratorFramework client, String membershipPath, String thisId, byte[] payload) {
    return new PersistentEphemeralNode(client, PersistentEphemeralNode.Mode.EPHEMERAL, ZKPaths.makePath(membershipPath, thisId), payload);
}

19 View Complete Implementation : AsyncExamples.java
Copyright Apache License 2.0
Author : apache
public static AsyncCuratorFramework wrap(CuratorFramework client) {
    // wrap a CuratorFramework instance so that it can be used async.
    // do this once and re-use the returned AsyncCuratorFramework instance
    return AsyncCuratorFramework.wrap(client);
}

19 View Complete Implementation : TreeCache.java
Copyright Apache License 2.0
Author : apache
/**
 * Create a TreeCache builder for the given client and path to configure advanced options.
 * <p/>
 * If the client is namespaced, all operations on the resulting TreeCache will be in terms of
 * the namespace, including all published events.  The given path is the root at which the
 * TreeCache will watch and explore.  If no node exists at the given path, the TreeCache will
 * be initially empty.
 *
 * @param client the client to use; may be namespaced
 * @param path   the path to the root node to watch/explore; this path need not actually exist on
 *               the server
 * @return a new builder
 */
public static Builder newBuilder(CuratorFramework client, String path) {
    return new Builder(client, path);
}

19 View Complete Implementation : AsyncCuratorFrameworkImpl.java
Copyright Apache License 2.0
Author : apache
private static CuratorFrameworkImpl reveal(CuratorFramework client) {
    try {
        return (CuratorFrameworkImpl) Objects.requireNonNull(client, "client cannot be null");
    } catch (Exception e) {
        throw new IllegalArgumentException("Only Curator clients created through CuratorFrameworkFactory are supported: " + client.getClreplaced().getName());
    }
}

19 View Complete Implementation : TestSimpleDistributedQueue.java
Copyright Apache License 2.0
Author : apache
public void createNremoveMelementTest(String dir, int n, int m) throws Exception {
    CuratorFramework[] clients = null;
    try {
        String testString = "Hello World";
        final int num_clients = 2;
        clients = new CuratorFramework[num_clients];
        SimpleDistributedQueue[] queueHandles = new SimpleDistributedQueue[num_clients];
        for (int i = 0; i < clients.length; i++) {
            clients[i] = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
            clients[i].start();
            queueHandles[i] = new SimpleDistributedQueue(clients[i], dir);
        }
        for (int i = 0; i < n; i++) {
            String offerString = testString + i;
            queueHandles[0].offer(offerString.getBytes());
        }
        for (int i = 0; i < m; i++) {
            queueHandles[1].remove();
        }
        replacedertEquals(new String(queueHandles[1].element()), testString + m);
    } finally {
        closeAll(clients);
    }
}

19 View Complete Implementation : LeaderSelector.java
Copyright Apache License 2.0
Author : apache
private static Participant participantForPath(CuratorFramework client, String path, boolean markAsLeader) throws Exception {
    try {
        byte[] bytes = client.getData().forPath(path);
        String thisId = new String(bytes, "UTF-8");
        return new Participant(thisId, markAsLeader);
    } catch (KeeperException.NoNodeException e) {
        return null;
    }
}

19 View Complete Implementation : TestTreeCacheEventOrdering.java
Copyright Apache License 2.0
Author : apache
@Override
protected TreeCache newCache(CuratorFramework client, String path, final BlockingQueue<Event> events) throws Exception {
    TreeCache cache = new TreeCache(client, path);
    TreeCacheListener listener = new TreeCacheListener() {

        @Override
        public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception {
            if ((event.getData() != null) && (event.getData().getPath().startsWith("/root/"))) {
                if (event.getType() == TreeCacheEvent.Type.NODE_ADDED) {
                    events.add(new Event(EventType.ADDED, event.getData().getPath()));
                }
                if (event.getType() == TreeCacheEvent.Type.NODE_REMOVED) {
                    events.add(new Event(EventType.DELETED, event.getData().getPath()));
                }
            }
        }
    };
    cache.getListenable().addListener(listener);
    cache.start();
    return cache;
}

19 View Complete Implementation : CrudExamples.java
Copyright Apache License 2.0
Author : apache
public static List<String> watchedGetChildren(CuratorFramework client, String path, Watcher watcher) throws Exception {
    /**
     * Get children and set the given watcher on the node.
     */
    return client.getChildren().usingWatcher(watcher).forPath(path);
}

19 View Complete Implementation : TransactionExamples.java
Copyright Apache License 2.0
Author : apache
public static Collection<CuratorTransactionResult> transaction(CuratorFramework client) throws Exception {
    // this example shows how to use ZooKeeper's transactions
    CuratorOp createOp = client.transactionOp().create().forPath("/a/path", "some data".getBytes());
    CuratorOp setDataOp = client.transactionOp().setData().forPath("/another/path", "other data".getBytes());
    CuratorOp deleteOp = client.transactionOp().delete().forPath("/yet/another/path");
    Collection<CuratorTransactionResult> results = client.transaction().forOperations(createOp, setDataOp, deleteOp);
    for (CuratorTransactionResult result : results) {
        System.out.println(result.getForPath() + " - " + result.getType());
    }
    return results;
}

19 View Complete Implementation : GroupMember.java
Copyright Apache License 2.0
Author : apache
protected PathChildrenCache newPathChildrenCache(CuratorFramework client, String membershipPath) {
    return new PathChildrenCache(client, membershipPath, true);
}

19 View Complete Implementation : TestPersistentEphemeralNode.java
Copyright Apache License 2.0
Author : apache
private void replacedertNodeExists(CuratorFramework curator, String path) throws Exception {
    replacedertNotNull(path);
    replacedertTrue(curator.checkExists().forPath(path) != null);
}

19 View Complete Implementation : StandardLockInternalsDriver.java
Copyright Apache License 2.0
Author : apache
@Override
public PredicateResults getsTheLock(CuratorFramework client, List<String> children, String sequenceNodeName, int maxLeases) throws Exception {
    int ourIndex = children.indexOf(sequenceNodeName);
    validateOurIndex(sequenceNodeName, ourIndex);
    boolean getsTheLock = ourIndex < maxLeases;
    String pathToWatch = getsTheLock ? null : children.get(ourIndex - maxLeases);
    return new PredicateResults(pathToWatch, getsTheLock);
}

19 View Complete Implementation : TestCompressionInTransactionOld.java
Copyright Apache License 2.0
Author : apache
@Test
public void testSetData() throws Exception {
    final String path = "/a";
    final byte[] data = "here's a string".getBytes();
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    try {
        client.start();
        // Create uncompressed data in a transaction
        client.inTransaction().create().forPath(path, data).and().commit();
        replacedert.replacedertEquals(data, client.getData().forPath(path));
        // Create compressed data in transaction
        client.inTransaction().setData().compressed().forPath(path, data).and().commit();
        replacedert.replacedertEquals(data, client.getData().decompressed().forPath(path));
    } finally {
        CloseableUtils.closeQuietly(client);
    }
}

19 View Complete Implementation : TestPersistentEphemeralNode.java
Copyright Apache License 2.0
Author : apache
@Test(expectedExceptions = IllegalArgumentException.clreplaced)
public void testNullPath() throws Exception {
    CuratorFramework curator = newCurator();
    new PersistentEphemeralNode(curator, PersistentEphemeralNode.Mode.EPHEMERAL, null, new byte[0]);
}

19 View Complete Implementation : SchemaSet.java
Copyright Apache License 2.0
Author : apache
/**
 * Utility to return a ZNode path for the given name
 *
 * @param client Curator client
 * @param name path/schema name
 * @return ZNode path
 */
public static String getNamedPath(CuratorFramework client, String name) {
    return client.getSchemaSet().getNamedSchema(name).getRawPath();
}

19 View Complete Implementation : Reaper.java
Copyright Apache License 2.0
Author : apache
private static LeaderLatch makeLeaderLatchIfPathNotNull(CuratorFramework client, String leaderPath) {
    if (leaderPath == null) {
        return null;
    } else {
        return new LeaderLatch(client, leaderPath);
    }
}

19 View Complete Implementation : CircuitBreakingConnectionStateListener.java
Copyright Apache License 2.0
Author : apache
@Override
public synchronized void stateChanged(CuratorFramework client, ConnectionState newState) {
    if (circuitBreaker.isOpen()) {
        handleOpenStateChange(newState);
    } else {
        handleClosedStateChange(newState);
    }
}

19 View Complete Implementation : TestCleanState.java
Copyright Apache License 2.0
Author : apache
public static void test(CuratorFramework client, Callable<Void> proc) throws Exception {
    boolean succeeded = false;
    try {
        proc.call();
        succeeded = true;
    } finally {
        if (succeeded) {
            closeAndTestClean(client);
        } else {
            CloseableUtils.closeQuietly(client);
        }
    }
}

19 View Complete Implementation : TestEventOrdering.java
Copyright Apache License 2.0
Author : apache
protected abstract T newCache(CuratorFramework client, String path, BlockingQueue<Event> events) throws Exception;

19 View Complete Implementation : TestServiceDiscoveryBuilder.java
Copyright Apache License 2.0
Author : apache
@Test
public void testSetSerializer() throws Exception {
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    ServiceDiscoveryBuilder<Object> builder = ServiceDiscoveryBuilder.builder(Object.clreplaced).client(client);
    builder.serializer(new InstanceSerializer<Object>() {

        @Override
        public byte[] serialize(ServiceInstance<Object> instance) {
            return null;
        }

        @Override
        public ServiceInstance<Object> deserialize(byte[] bytes) {
            return null;
        }
    });
    ServiceDiscoveryImpl<?> discovery = (ServiceDiscoveryImpl<?>) builder.basePath("/path").build();
    replacedert.replacedertNotNull(discovery.getSerializer(), "default serializer not set");
    replacedert.replacedertFalse(discovery.getSerializer() instanceof JsonInstanceSerializer, "set serializer is JSON");
}

19 View Complete Implementation : CrudExamples.java
Copyright Apache License 2.0
Author : apache
public static List<String> watchedGetChildren(CuratorFramework client, String path) throws Exception {
    /**
     * Get children and set a watcher on the node. The watcher notification will come through the
     * CuratorListener (see setDataAsync() above).
     */
    return client.getChildren().watched().forPath(path);
}

19 View Complete Implementation : ServiceDiscoveryBuilder.java
Copyright Apache License 2.0
Author : apache
/**
 * Required - set the client to use
 *
 * @param client client
 * @return this
 */
public ServiceDiscoveryBuilder<T> client(CuratorFramework client) {
    this.client = client;
    return this;
}

19 View Complete Implementation : SemaphoreClient.java
Copyright Apache License 2.0
Author : apache
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
    hasAcquired = false;
}

19 View Complete Implementation : QueueBuilder.java
Copyright Apache License 2.0
Author : apache
/**
 * Allocate a new builder
 *
 * @param client the curator client
 * @param consumer functor to consume messages - NOTE: preplaced <code>null</code> to make this a producer-only queue
 * @param serializer serializer to use for items
 * @param queuePath path to store queue
 * @return builder
 */
public static <T> QueueBuilder<T> builder(CuratorFramework client, QueueConsumer<T> consumer, QueueSerializer<T> serializer, String queuePath) {
    return new QueueBuilder<T>(client, consumer, serializer, queuePath);
}

19 View Complete Implementation : InternalCallback.java
Copyright Apache License 2.0
Author : apache
@Override
public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
    event = (resultFilter != null) ? resultFilter.apply(event) : event;
    resultFunction.apply(event, this);
}

19 View Complete Implementation : AsyncExamples.java
Copyright Apache License 2.0
Author : apache
public static void create(CuratorFramework client, String path, byte[] payload) {
    // normally you'd wrap early in your app and reuse the instance
    AsyncCuratorFramework async = AsyncCuratorFramework.wrap(client);
    // create a node at the given path with the given payload asynchronously
    async.create().forPath(path, payload).whenComplete((name, exception) -> {
        if (exception != null) {
            // there was a problem
            exception.printStackTrace();
        } else {
            System.out.println("Created node name is: " + name);
        }
    });
}

19 View Complete Implementation : CrudExamples.java
Copyright Apache License 2.0
Author : apache
public static void delete(CuratorFramework client, String path) throws Exception {
    // delete the given node
    client.delete().forPath(path);
}

19 View Complete Implementation : TestPathChildrenCacheEventOrdering.java
Copyright Apache License 2.0
Author : apache
@Override
protected PathChildrenCache newCache(CuratorFramework client, String path, final BlockingQueue<Event> events) throws Exception {
    PathChildrenCache cache = new PathChildrenCache(client, path, false);
    PathChildrenCacheListener listener = new PathChildrenCacheListener() {

        @Override
        public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
            if (event.getType() == PathChildrenCacheEvent.Type.CHILD_ADDED) {
                events.add(new Event(EventType.ADDED, event.getData().getPath()));
            }
            if (event.getType() == PathChildrenCacheEvent.Type.CHILD_REMOVED) {
                events.add(new Event(EventType.DELETED, event.getData().getPath()));
            }
        }
    };
    cache.getListenable().addListener(listener);
    cache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
    return cache;
}

19 View Complete Implementation : LeaderSelectorListenerAdapter.java
Copyright Apache License 2.0
Author : apache
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
    if (client.getConnectionStateErrorPolicy().isErrorState(newState)) {
        throw new CancelLeadershipException();
    }
}

19 View Complete Implementation : TestModeledFrameworkBase.java
Copyright Apache License 2.0
Author : apache
public clreplaced TestModeledFrameworkBase extends CompletableBaseClreplacedForTests {

    protected static final ZPath path = ZPath.parse("/test/path");

    protected CuratorFramework rawClient;

    protected ModelSpec<TestModel> modelSpec;

    protected ModelSpec<TestNewerModel> newModelSpec;

    protected AsyncCuratorFramework async;

    @BeforeMethod
    @Override
    public void setup() throws Exception {
        super.setup();
        rawClient = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
        rawClient.start();
        async = AsyncCuratorFramework.wrap(rawClient);
        JacksonModelSerializer<TestModel> serializer = JacksonModelSerializer.build(TestModel.clreplaced);
        JacksonModelSerializer<TestNewerModel> newSerializer = JacksonModelSerializer.build(TestNewerModel.clreplaced);
        modelSpec = ModelSpec.builder(path, serializer).build();
        newModelSpec = ModelSpec.builder(path, newSerializer).build();
    }

    @AfterMethod
    @Override
    public void teardown() throws Exception {
        CloseableUtils.closeQuietly(rawClient);
        super.teardown();
    }
}

19 View Complete Implementation : TestInterProcessMultiMutex.java
Copyright Apache License 2.0
Author : apache
@Override
protected InterProcessLock makeLock(CuratorFramework client) {
    return new InterProcessMultiLock(client, Arrays.asList(LOCK_PATH_1, LOCK_PATH_2));
}

19 View Complete Implementation : TestPersistentEphemeralNode.java
Copyright Apache License 2.0
Author : apache
@AfterMethod
@Override
public void teardown() throws Exception {
    try {
        for (PersistentEphemeralNode node : createdNodes) {
            CloseableUtils.closeQuietly(node);
        }
        for (CuratorFramework curator : curatorInstances) {
            TestCleanState.closeAndTestClean(curator);
        }
    } finally {
        super.teardown();
    }
}

19 View Complete Implementation : InterProcessMultiLock.java
Copyright Apache License 2.0
Author : apache
private static List<InterProcessLock> makeLocks(CuratorFramework client, List<String> paths) {
    ImmutableList.Builder<InterProcessLock> builder = ImmutableList.builder();
    for (String path : paths) {
        InterProcessLock lock = new InterProcessMutex(client, path);
        builder.add(lock);
    }
    return builder.build();
}

19 View Complete Implementation : BaseTestTreeCache.java
Copyright Apache License 2.0
Author : apache
/**
 * Construct a TreeCache that records exceptions and automatically listens.
 */
protected TreeCache newTreeCacheWithListeners(CuratorFramework client, String path) {
    TreeCache result = new TreeCache(client, path);
    result.getListenable().addListener(eventListener);
    result.getUnhandledErrorListenable().addListener(errorListener);
    return result;
}

19 View Complete Implementation : TestCompatibility.java
Copyright Apache License 2.0
Author : apache
@Test(expectedExceptions = IllegalStateException.clreplaced)
public void testReconfig() throws Exception {
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    client.start();
    try {
        client.reconfig().withNewMembers("a", "b");
    } finally {
        CloseableUtils.closeQuietly(client);
    }
}

19 View Complete Implementation : TestSimpleDistributedQueue.java
Copyright Apache License 2.0
Author : apache
public void createNremoveMtest(String dir, int n, int m) throws Exception {
    CuratorFramework[] clients = null;
    try {
        String testString = "Hello World";
        final int num_clients = 2;
        clients = new CuratorFramework[num_clients];
        SimpleDistributedQueue[] queueHandles = new SimpleDistributedQueue[num_clients];
        for (int i = 0; i < clients.length; i++) {
            clients[i] = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
            clients[i].start();
            queueHandles[i] = new SimpleDistributedQueue(clients[i], dir);
        }
        for (int i = 0; i < n; i++) {
            String offerString = testString + i;
            queueHandles[0].offer(offerString.getBytes());
        }
        byte[] data = null;
        for (int i = 0; i < m; i++) {
            data = queueHandles[1].remove();
        }
        replacedertEquals(new String(data), testString + (m - 1));
    } finally {
        closeAll(clients);
    }
}

19 View Complete Implementation : AsyncExamples.java
Copyright Apache License 2.0
Author : apache
public static void createThenWatch(CuratorFramework client, String path) {
    // normally you'd wrap early in your app and reuse the instance
    AsyncCuratorFramework async = AsyncCuratorFramework.wrap(client);
    // this example shows to asynchronously use watchers for both event
    // triggering and connection problems. If you don't need to be notified
    // of connection problems, use the simpler approach shown in createThenWatchSimple()
    // create a node at the given path with the given payload asynchronously
    // then watch the created node
    async.create().forPath(path).whenComplete((name, exception) -> {
        if (exception != null) {
            // there was a problem creating the node
            exception.printStackTrace();
        } else {
            handleWatchedStage(async.watched().checkExists().forPath(path).event());
        }
    });
}

19 View Complete Implementation : Revoker.java
Copyright Apache License 2.0
Author : apache
/**
 * Utility to mark a lock for revocation. replaceduming that the lock has been registered with
 * a {@link RevocationListener}, it will get called and the lock should be released. Note,
 * however, that revocation is cooperative.
 *
 * @param client the client
 * @param path the path of the lock - usually from something like
 * {@link InterProcessMutex#getParticipantNodes()}
 * @throws Exception errors
 */
public static void attemptRevoke(CuratorFramework client, String path) throws Exception {
    try {
        client.setData().forPath(path, LockInternals.REVOKE_MESSAGE);
    } catch (KeeperException.NoNodeException ignore) {
    // ignore
    }
}

19 View Complete Implementation : TestCompatibility.java
Copyright Apache License 2.0
Author : apache
@Test(expectedExceptions = IllegalStateException.clreplaced)
public void testRemoveWatches() throws Exception {
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    client.start();
    try {
        client.watches().removeAll();
    } finally {
        CloseableUtils.closeQuietly(client);
    }
}

19 View Complete Implementation : CrudExamples.java
Copyright Apache License 2.0
Author : apache
public static void setDataAsyncWithCallback(CuratorFramework client, BackgroundCallback callback, String path, byte[] payload) throws Exception {
    // this is another method of getting notification of an async completion
    client.setData().inBackground(callback).forPath(path, payload);
}