@Override @SuppressWarnings("unchecked") public void processResult(int rc, String path, Object ctx) { SettableOperationFuture<String> result = (SettableOperationFuture<String>) ctx; KeeperException.Code code = KeeperException.Code.get(rc); if (code == KeeperException.Code.OK) { result.set(result.getRequestPath()); return; } // Otherwise, it is an error result.setException(KeeperException.create(code, result.getRequestPath())); } };
public static <V> SettableOperationFuture<V> create(String path, Executor executor) { return new SettableOperationFuture<>(path, executor); }
@Override public void onFailure(Throwable t) { if (exceptionType.isAssignableFrom(t.getClass())) { resultFuture.set(errorResult); } else if (t instanceof CancellationException) { resultFuture.cancel(true); } else { resultFuture.setException(t); } } }, Threads.SAME_THREAD_EXECUTOR);
@Override public void run() { try { String relativePath = from.get().substring(namespace.length()); to.set(relativePath.isEmpty() ? "/" : relativePath); } catch (Exception e) { to.setException(e.getCause()); } } }, Threads.SAME_THREAD_EXECUTOR);
@Override public OperationFuture<Stat> setACL(String path, Iterable<ACL> acl, int version) { SettableOperationFuture<Stat> result = SettableOperationFuture.create(path, eventExecutor); getZooKeeper().setACL(path, ImmutableList.copyOf(acl), version, Callbacks.STAT, result); return result; }
@Override public void onSuccess(String result) { // Path deleted successfully. Operation done. resultFuture.set(result); }
@Override public void onFailure(Throwable t) { to.setException(t); } });
@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; }
@Override public void run() { try { String relativePath = from.get().substring(namespace.length()); to.set(relativePath.isEmpty() ? "/" : relativePath); } catch (Exception e) { to.setException(e.getCause()); } } }, Threads.SAME_THREAD_EXECUTOR);
@Override public void onSuccess(String path) { // Propagate if creation was successful result.set(path); }
@Override public void onFailure(Throwable t) { to.setException(t); } });
@Override @SuppressWarnings("unchecked") public void processResult(int rc, String path, Object ctx) { SettableOperationFuture<String> result = (SettableOperationFuture<String>) ctx; KeeperException.Code code = KeeperException.Code.get(rc); if (code == KeeperException.Code.OK) { result.set(result.getRequestPath()); return; } // Otherwise, it is an error result.setException(KeeperException.create(code, result.getRequestPath())); } };
@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; }
/** * Updates the result future based on the given {@link Throwable}. * @param t Cause of the failure * @param result Future to be updated * @param path Request path for the operation * @return {@code true} if it is a failure, {@code false} otherwise. */ private boolean updateFailureResult(Throwable t, SettableOperationFuture<String> result, String path, boolean ignoreNodeExists) { // Propagate if there is error if (!(t instanceof KeeperException)) { result.setException(t); return true; } KeeperException.Code code = ((KeeperException) t).code(); // Node already exists, simply return success if it allows for ignoring node exists (for parent node creation). if (ignoreNodeExists && code == KeeperException.Code.NODEEXISTS) { // The requested path could be used because it only applies to non-sequential node result.set(path); return false; } if (code != KeeperException.Code.NONODE) { result.setException(t); return true; } return false; }
@Override public void onFailure(Throwable t) { if (exceptionType.isAssignableFrom(t.getClass())) { resultFuture.set(errorResult); } else if (t instanceof CancellationException) { resultFuture.cancel(true); } else { resultFuture.setException(t); } } }, Threads.SAME_THREAD_EXECUTOR);
@Override public void onSuccess(String path) { // Propagate if creation was successful result.set(path); }
@Override public void onFailure(Throwable t) { if (!doRetry(t)) { result.setException(t); } }
public static <V> SettableOperationFuture<V> create(String path, Executor executor) { return new SettableOperationFuture<>(path, executor); }
@Override @SuppressWarnings("unchecked") public void processResult(int rc, String path, Object ctx) { SettableOperationFuture<String> result = (SettableOperationFuture<String>) ctx; KeeperException.Code code = KeeperException.Code.get(rc); if (code == KeeperException.Code.OK) { result.set(result.getRequestPath()); return; } // Otherwise, it is an error result.setException(KeeperException.create(code, result.getRequestPath())); } };
@Override public OperationFuture<Stat> exists(String path, Watcher watcher) { SettableOperationFuture<Stat> result = SettableOperationFuture.create(path, eventExecutor); getZooKeeper().exists(path, wrapWatcher(watcher), Callbacks.STAT_NONODE, result); return result; }