/** * All non-specific keeper exceptions should be constructed via * this factory method in order to guarantee consistency in error * codes and such. If you know the error code, then you should * construct the special purpose exception directly. That will * allow you to have the most specific possible declarations of * what exceptions might actually be thrown. * * @param code The error code. * @param path The ZooKeeper path being operated on. * @return The specialized exception, presumably to be thrown by * the caller. */ public static KeeperException create(Code code, String path) { KeeperException r = create(code); r.path = path; return r; }
/** * @deprecated deprecated in 3.1.0, use {@link #create(Code, String)} * instead */ @Deprecated public static KeeperException create(int code, String path) { KeeperException r = create(Code.get(code)); r.path = path; return r; }
/** * @deprecated deprecated in 3.1.0, use {@link #create(Code)} * instead */ @Deprecated public static KeeperException create(int code) { return create(Code.get(code)); }
void checkProgrammedFail() throws KeeperException { if (stepsToFail.getAndDecrement() == 0 || this.alwaysFail) { throw KeeperException.create(failReturnCode); } }
@Override public void processResult(int rc, String path, Object ctx, String name) { if (KeeperException.Code.OK.intValue() == rc) { logger.info("Created zk path {} for default ACL.", zkRootPath); fetchDefaultAccessControlEntry(promise); } else { promise.setException(KeeperException.create(KeeperException.Code.get(rc))); } } }, null);
@Override public void processResult(int rc, String path, Object ctx) { if (Code.OK.intValue() == rc) { fetchSubNamespaces(watcher, promise); } else { promise.setException(KeeperException.create(Code.get(rc))); } } }, null);
@Override public void processResult(int rc, String path, Object ctx, Stat stat) { if (Code.OK.intValue() == rc) { fetchPromise.setValue(Optional.of(uri)); } else if (Code.NONODE.intValue() == rc) { fetchPromise.setValue(Optional.<URI>absent()); } else { fetchPromise.setException(KeeperException.create(Code.get(rc))); } } }, null);
@Override public void processResult(int rc, String path, Object ctx, List<String> children, Stat stat) { if (KeeperException.Code.NONODE.intValue() == rc) { result.setValue(new HashMap<String, DLSN>()); } else if (KeeperException.Code.OK.intValue() != rc) { result.setException(KeeperException.create(KeeperException.Code.get(rc), path)); } else { getLastCommitPositions(result, children); } } }, null);
@Override public void processResult(int rc, String path, Object ctx, String name) { if (KeeperException.Code.OK.intValue() == rc) { ZKAccessControl.this.zkVersion = 0; promise.setValue(ZKAccessControl.this); } else { promise.setException(KeeperException.create(KeeperException.Code.get(rc))); } } }, null);
@Override @SuppressWarnings("unchecked") public void processResult(int rc, String path, Object ctx, List<String> children, Stat stat) { Promise<List<String>> result = ((Promise<List<String>>) ctx); if (KeeperException.Code.OK.intValue() == rc) { result.setValue(children); } else { result.setException(KeeperException.create(KeeperException.Code.get(rc))); } }
@Override public void removeManagedLedger(String ledgerName, MetaStoreCallback<Void> callback) { log.info("[{}] Remove ManagedLedger", ledgerName); zk.delete(prefix + ledgerName, -1, (rc, path, ctx) -> executor.executeOrdered(ledgerName, safeRun(() -> { if (log.isDebugEnabled()) { log.debug("[{}] zk delete done. rc={}", ledgerName, Code.get(rc)); } if (rc == Code.OK.intValue()) { callback.operationComplete(null, null); } else { callback.operationFailed(new MetaStoreException(KeeperException.create(Code.get(rc)))); } })), null); }
@Override public void processResult(int rc, String path, Object ctx) { if (KeeperException.Code.OK.intValue() == rc || KeeperException.Code.NONODE.intValue() == rc) { promise.setValue(null); } else { promise.setException(KeeperException.create(KeeperException.Code.get(rc))); } } }, null);
@Override public void processResult(int rc, String path, Object ctx, Stat stat) { if (KeeperException.Code.OK.intValue() == rc) { ZKAccessControl.this.zkVersion = stat.getVersion(); promise.setValue(ZKAccessControl.this); } else { promise.setException(KeeperException.create(KeeperException.Code.get(rc))); } } }, null);
@Override public void processResult(int rc, String path, Object ctx) { if (KeeperException.Code.OK.intValue() == rc) { promise.updateIfEmpty(new Return<Void>(null)); return; } promise.updateIfEmpty(new Throw<Void>( KeeperException.create(KeeperException.Code.get(rc)))); return; } }, null);
private static void handleKeeperExceptionCode(int rc, String pathOrMessage, Promise<BoxedUnit> result) { if (KeeperException.Code.OK.intValue() == rc) { result.setValue(BoxedUnit.UNIT); } else if (DistributedLogConstants.ZK_CONNECTION_EXCEPTION_RESULT_CODE == rc) { result.setException(new ZooKeeperClient.ZooKeeperConnectionException(pathOrMessage)); } else if (DistributedLogConstants.DL_INTERRUPTED_EXCEPTION_RESULT_CODE == rc) { result.setException(new DLInterruptedException(pathOrMessage)); } else { result.setException(KeeperException.create(KeeperException.Code.get(rc), pathOrMessage)); } }
@Override public void processResult(int rc, String path, Object ctx, Stat stat) { if (KeeperException.Code.OK.intValue() == rc) { promise.updateIfEmpty(new Return<ZkVersion>(new ZkVersion(stat.getVersion()))); return; } promise.updateIfEmpty(new Throw<ZkVersion>( KeeperException.create(KeeperException.Code.get(rc)))); return; } }, null);
private void removeWatches(int opCode, String path, Watcher watcher, WatcherType watcherType, boolean local) throws InterruptedException, KeeperException { PathUtils.validatePath(path); final String clientPath = path; final String serverPath = prependChroot(clientPath); WatchDeregistration wcb = new WatchDeregistration(clientPath, watcher, watcherType, local, watchManager); RequestHeader h = new RequestHeader(); h.setType(opCode); Record request = getRemoveWatchesRequest(opCode, watcherType, serverPath); ReplyHeader r = cnxn.submitRequest(h, request, null, null, wcb); if (r.getErr() != 0) { throw KeeperException.create(KeeperException.Code.get(r.getErr()), clientPath); } }
@Override public void processResult(int rc, String path, Object ctx, String name, Stat stat) { if (KeeperException.Code.OK.intValue() == rc) { promise.setValue(new Versioned<byte[]>(DistributedLogConstants.EMPTY_BYTES, new ZkVersion(stat.getVersion()))); } else if (KeeperException.Code.NODEEXISTS.intValue() == rc) { Utils.zkGetData(zkc, allocatePath, false).proxyTo(promise); } else { promise.setException(FutureUtils.zkException( KeeperException.create(KeeperException.Code.get(rc)), allocatePath)); } } }, null);
private void removeAllWatches(ZooKeeper zk, String path, WatcherType watcherType, boolean local, KeeperException.Code rc) throws InterruptedException, KeeperException { LOG.info("Sending removeWatches req using zk {} path: {} type: {} ", new Object[] { zk, path, watcherType }); if (useAsync) { MyCallback c1 = new MyCallback(rc.intValue(), path); zk.removeAllWatches(path, watcherType, local, c1, null); Assert.assertTrue("Didn't succeeds removeWatch operation", c1.matches()); if (KeeperException.Code.OK.intValue() != c1.rc) { KeeperException ke = KeeperException .create(KeeperException.Code.get(c1.rc)); throw ke; } } else { zk.removeAllWatches(path, watcherType, local); } }
private void removeWatches(ZooKeeper zk, String path, Watcher watcher, WatcherType watcherType, boolean local, KeeperException.Code rc) throws InterruptedException, KeeperException { LOG.info( "Sending removeWatches req using zk {} path: {} type: {} watcher: {} ", new Object[] { zk, path, watcherType, watcher }); if (useAsync) { MyCallback c1 = new MyCallback(rc.intValue(), path); zk.removeWatches(path, watcher, watcherType, local, c1, null); Assert.assertTrue("Didn't succeeds removeWatch operation", c1.matches()); if (KeeperException.Code.OK.intValue() != c1.rc) { KeeperException ke = KeeperException .create(KeeperException.Code.get(c1.rc)); throw ke; } } else { zk.removeWatches(path, watcher, watcherType, local); } }