@Override public OperationFuture<String> create(final String path, @Nullable final byte[] data, final CreateMode createMode, final boolean createParent, final Iterable<ACL> acl) { // No retry for any SEQUENTIAL node, as some algorithms depends on only one sequential node being created. if (createMode == CreateMode.PERSISTENT_SEQUENTIAL || createMode == CreateMode.EPHEMERAL_SEQUENTIAL) { return super.create(path, data, createMode, createParent, acl); } final SettableOperationFuture<String> result = SettableOperationFuture.create(path, Threads.SAME_THREAD_EXECUTOR); Futures.addCallback(super.create(path, data, createMode, createParent, acl), new OperationFutureCallback<String>(OperationType.CREATE, System.currentTimeMillis(), path, result, new Supplier<OperationFuture<String>>() { @Override public OperationFuture<String> get() { return FailureRetryZKClient.super.create(path, data, createMode, createParent, acl); } })); return result; }
@Override public OperationFuture<Stat> exists(String path, Watcher watcher) { if (watcher == null) { return super.exists(path, null); } final RewatchOnExpireWatcher wrappedWatcher = new RewatchOnExpireWatcher(this, ActionType.EXISTS, path, watcher); OperationFuture<Stat> result = super.exists(path, wrappedWatcher); Futures.addCallback(result, new FutureCallback<Stat>() { @Override public void onSuccess(Stat result) { wrappedWatcher.setLastResult(result); } @Override public void onFailure(Throwable t) { // No-op } }); return result; }
@Override public OperationFuture<NodeChildren> getChildren(String path, Watcher watcher) { if (watcher == null) { return super.getChildren(path, null); } final RewatchOnExpireWatcher wrappedWatcher = new RewatchOnExpireWatcher(this, ActionType.CHILDREN, path, watcher); OperationFuture<NodeChildren> result = super.getChildren(path, wrappedWatcher); Futures.addCallback(result, new FutureCallback<NodeChildren>() { @Override public void onSuccess(NodeChildren result) { wrappedWatcher.setLastResult(result); } @Override public void onFailure(Throwable t) { // No-op } }); return result; }
@Override public OperationFuture<NodeData> getData(String path, Watcher watcher) { if (watcher == null) { return super.getData(path, null); } final RewatchOnExpireWatcher wrappedWatcher = new RewatchOnExpireWatcher(this, ActionType.DATA, path, watcher); OperationFuture<NodeData> result = super.getData(path, wrappedWatcher); Futures.addCallback(result, new FutureCallback<NodeData>() { @Override public void onSuccess(NodeData result) { wrappedWatcher.setLastResult(result); } @Override public void onFailure(Throwable t) { // No-op } }); return result; } }
@Override public OperationFuture<Stat> setACL(final String path, final Iterable<ACL> acl, final int version) { final SettableOperationFuture<Stat> result = SettableOperationFuture.create(path, Threads.SAME_THREAD_EXECUTOR); Futures.addCallback(super.setACL(path, acl, version), new OperationFutureCallback<Stat>(OperationType.SET_ACL, System.currentTimeMillis(), path, result, new Supplier<OperationFuture<Stat>>() { @Override public OperationFuture<Stat> get() { return FailureRetryZKClient.super.setACL(path, acl, version); } })); return result; }
@Override public OperationFuture<Stat> setData(final String dataPath, final byte[] data, final int version) { final SettableOperationFuture<Stat> result = SettableOperationFuture.create(dataPath, Threads.SAME_THREAD_EXECUTOR); Futures.addCallback(super.setData(dataPath, data, version), new OperationFutureCallback<Stat>(OperationType.SET_DATA, System.currentTimeMillis(), dataPath, result, new Supplier<OperationFuture<Stat>>() { @Override public OperationFuture<Stat> get() { return FailureRetryZKClient.super.setData(dataPath, data, version); } })); return result; }
@Override public OperationFuture<ACLData> getACL(final String path) { final SettableOperationFuture<ACLData> result = SettableOperationFuture.create(path, Threads.SAME_THREAD_EXECUTOR); Futures.addCallback(super.getACL(path), new OperationFutureCallback<ACLData>(OperationType.GET_ACL, System.currentTimeMillis(), path, result, new Supplier<OperationFuture<ACLData>>() { @Override public OperationFuture<ACLData> get() { return FailureRetryZKClient.super.getACL(path); } })); return result; }
@Override public OperationFuture<String> delete(final String deletePath, final int version) { final SettableOperationFuture<String> result = SettableOperationFuture.create(deletePath, Threads.SAME_THREAD_EXECUTOR); Futures.addCallback(super.delete(deletePath, version), new OperationFutureCallback<String>(OperationType.DELETE, System.currentTimeMillis(), deletePath, result, new Supplier<OperationFuture<String>> () { @Override public OperationFuture<String> get() { return FailureRetryZKClient.super.delete(deletePath, version); } })); return result; }
/** * Creates a {@link ZKClientService} from the given {@link ZKClient} if the given {@link ZKClient} is an instance of * {@link ZKClientService} or is a {@link ForwardingZKClient} that eventually trace back to a delegate of type * {@link ZKClientService}. If such a {@link ZKClientService} instance is found, this method returns * an instance by invoking {@link #delegate(ZKClient, ZKClientService)} with the given {@link ZKClient} and * the {@link ZKClientService} found respectively. * * @param client The {@link ZKClient}. * @return A {@link ZKClientService}. * @throws IllegalArgumentException If no {@link ZKClientService} is found. */ public static ZKClientService delegate(ZKClient client) { ZKClient zkClient = client; while (!(zkClient instanceof ZKClientService) && zkClient instanceof ForwardingZKClient) { zkClient = ((ForwardingZKClient) zkClient).getDelegate(); } if (zkClient instanceof ZKClientService) { return delegate(client, (ZKClientService) zkClient); } throw new IllegalArgumentException("No ZKClientService found from the delegation hierarchy"); }
@Override public OperationFuture<NodeData> getData(String path, Watcher watcher) { if (watcher == null) { return super.getData(path, null); } final RewatchOnExpireWatcher wrappedWatcher = new RewatchOnExpireWatcher(this, ActionType.DATA, path, watcher); OperationFuture<NodeData> result = super.getData(path, wrappedWatcher); Futures.addCallback(result, new FutureCallback<NodeData>() { @Override public void onSuccess(NodeData result) { wrappedWatcher.setLastResult(result); } @Override public void onFailure(Throwable t) { // No-op } }); return result; } }
@Override public OperationFuture<Stat> setACL(final String path, final Iterable<ACL> acl, final int version) { final SettableOperationFuture<Stat> result = SettableOperationFuture.create(path, Threads.SAME_THREAD_EXECUTOR); Futures.addCallback(super.setACL(path, acl, version), new OperationFutureCallback<Stat>(OperationType.SET_ACL, System.currentTimeMillis(), path, result, new Supplier<OperationFuture<Stat>>() { @Override public OperationFuture<Stat> get() { return FailureRetryZKClient.super.setACL(path, acl, version); } })); return result; }
@Override public OperationFuture<Stat> setData(final String dataPath, final byte[] data, final int version) { final SettableOperationFuture<Stat> result = SettableOperationFuture.create(dataPath, Threads.SAME_THREAD_EXECUTOR); Futures.addCallback(super.setData(dataPath, data, version), new OperationFutureCallback<Stat>(OperationType.SET_DATA, System.currentTimeMillis(), dataPath, result, new Supplier<OperationFuture<Stat>>() { @Override public OperationFuture<Stat> get() { return FailureRetryZKClient.super.setData(dataPath, data, version); } })); return result; }
@Override public OperationFuture<ACLData> getACL(final String path) { final SettableOperationFuture<ACLData> result = SettableOperationFuture.create(path, Threads.SAME_THREAD_EXECUTOR); Futures.addCallback(super.getACL(path), new OperationFutureCallback<ACLData>(OperationType.GET_ACL, System.currentTimeMillis(), path, result, new Supplier<OperationFuture<ACLData>>() { @Override public OperationFuture<ACLData> get() { return FailureRetryZKClient.super.getACL(path); } })); return result; }
@Override public OperationFuture<String> delete(final String deletePath, final int version) { final SettableOperationFuture<String> result = SettableOperationFuture.create(deletePath, Threads.SAME_THREAD_EXECUTOR); Futures.addCallback(super.delete(deletePath, version), new OperationFutureCallback<String>(OperationType.DELETE, System.currentTimeMillis(), deletePath, result, new Supplier<OperationFuture<String>> () { @Override public OperationFuture<String> get() { return FailureRetryZKClient.super.delete(deletePath, version); } })); return result; }
/** * Creates a {@link ZKClientService} from the given {@link ZKClient} if the given {@link ZKClient} is an instance of * {@link ZKClientService} or is a {@link ForwardingZKClient} that eventually trace back to a delegate of type * {@link ZKClientService}. If such a {@link ZKClientService} instance is found, this method returns * an instance by invoking {@link #delegate(ZKClient, ZKClientService)} with the given {@link ZKClient} and * the {@link ZKClientService} found respectively. * * @param client The {@link ZKClient}. * @return A {@link ZKClientService}. * @throws IllegalArgumentException If no {@link ZKClientService} is found. */ public static ZKClientService delegate(ZKClient client) { ZKClient zkClient = client; while (!(zkClient instanceof ZKClientService) && zkClient instanceof ForwardingZKClient) { zkClient = ((ForwardingZKClient) zkClient).getDelegate(); } if (zkClient instanceof ZKClientService) { return delegate(client, (ZKClientService) zkClient); } throw new IllegalArgumentException("No ZKClientService found from the delegation hierarchy"); }
@Override public OperationFuture<Stat> exists(String path, Watcher watcher) { if (watcher == null) { return super.exists(path, null); } final RewatchOnExpireWatcher wrappedWatcher = new RewatchOnExpireWatcher(this, ActionType.EXISTS, path, watcher); OperationFuture<Stat> result = super.exists(path, wrappedWatcher); Futures.addCallback(result, new FutureCallback<Stat>() { @Override public void onSuccess(Stat result) { wrappedWatcher.setLastResult(result); } @Override public void onFailure(Throwable t) { // No-op } }); return result; }
@Override public OperationFuture<NodeData> getData(final String path, final Watcher watcher) { final SettableOperationFuture<NodeData> result = SettableOperationFuture.create(path, Threads.SAME_THREAD_EXECUTOR); Futures.addCallback(super.getData(path, watcher), new OperationFutureCallback<NodeData>(OperationType.GET_DATA, System.currentTimeMillis(), path, result, new Supplier<OperationFuture<NodeData>>() { @Override public OperationFuture<NodeData> get() { return FailureRetryZKClient.super.getData(path, watcher); } })); return result; }
@Override public OperationFuture<NodeChildren> getChildren(String path, Watcher watcher) { if (watcher == null) { return super.getChildren(path, null); } final RewatchOnExpireWatcher wrappedWatcher = new RewatchOnExpireWatcher(this, ActionType.CHILDREN, path, watcher); OperationFuture<NodeChildren> result = super.getChildren(path, wrappedWatcher); Futures.addCallback(result, new FutureCallback<NodeChildren>() { @Override public void onSuccess(NodeChildren result) { wrappedWatcher.setLastResult(result); } @Override public void onFailure(Throwable t) { // No-op } }); return result; }
@Override public OperationFuture<String> create(final String path, @Nullable final byte[] data, final CreateMode createMode, final boolean createParent, final Iterable<ACL> acl) { // No retry for any SEQUENTIAL node, as some algorithms depends on only one sequential node being created. if (createMode == CreateMode.PERSISTENT_SEQUENTIAL || createMode == CreateMode.EPHEMERAL_SEQUENTIAL) { return super.create(path, data, createMode, createParent, acl); } final SettableOperationFuture<String> result = SettableOperationFuture.create(path, Threads.SAME_THREAD_EXECUTOR); Futures.addCallback(super.create(path, data, createMode, createParent, acl), new OperationFutureCallback<String>(OperationType.CREATE, System.currentTimeMillis(), path, result, new Supplier<OperationFuture<String>>() { @Override public OperationFuture<String> get() { return FailureRetryZKClient.super.create(path, data, createMode, createParent, acl); } })); return result; }
@Override public OperationFuture<Stat> exists(final String path, final Watcher watcher) { final SettableOperationFuture<Stat> result = SettableOperationFuture.create(path, Threads.SAME_THREAD_EXECUTOR); Futures.addCallback(super.exists(path, watcher), new OperationFutureCallback<Stat>(OperationType.EXISTS, System.currentTimeMillis(), path, result, new Supplier<OperationFuture<Stat>>() { @Override public OperationFuture<Stat> get() { return FailureRetryZKClient.super.exists(path, watcher); } })); return result; }