List of usage examples for org.apache.zookeeper KeeperException create
@Deprecated public static KeeperException create(int code, String path)
From source file:com.linkedin.parseq.zk.client.ZKClientImpl.java
License:Apache License
/** * {@inheritDoc}/* w w w . j ava 2 s . com*/ */ @Override public WatchableTask<Optional<Stat>> exists(String path) { return new WatchableTask<Optional<Stat>>("zkExists: " + path) { @Override protected Promise run(Context context) throws Throwable { SettablePromise<Optional<Stat>> promise = Promises.settable(); _zkClient.exists(path, _watcher, (int rc, String p, Object ctx, Stat stat) -> { KeeperException.Code code = KeeperException.Code.get(rc); switch (code) { case OK: promise.done(Optional.of(stat)); break; case NONODE: promise.done(Optional.empty()); break; default: promise.fail(KeeperException.create(code, p)); } }, null); return promise; } }; }
From source file:com.linkedin.parseq.zk.client.ZKClientImpl.java
License:Apache License
/** * {@inheritDoc}/*from ww w . j a va2 s. c om*/ */ @Override public Task<Void> delete(String path, int version) { return Task.async("zkDelete: " + path, () -> { SettablePromise<Void> promise = Promises.settable(); _zkClient.delete(path, version, (int rc, String p, Object ctx) -> { KeeperException.Code code = KeeperException.Code.get(rc); switch (code) { case OK: promise.done(null); break; default: promise.fail(KeeperException.create(code, p)); } }, null); return promise; }); }
From source file:com.twitter.distributedlog.subscription.ZKSubscriptionsStore.java
License:Apache License
@Override public Future<Map<String, DLSN>> getLastCommitPositions() { final Promise<Map<String, DLSN>> result = new Promise<Map<String, DLSN>>(); try {//from ww w . jav a 2 s .c o m this.zkc.get().getChildren(this.zkPath, false, new AsyncCallback.Children2Callback() { @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); } catch (ZooKeeperClient.ZooKeeperConnectionException zkce) { result.setException(zkce); } catch (InterruptedException ie) { result.setException(new DLInterruptedException("getLastCommitPositions was interrupted", ie)); } return result; }
From source file:com.twitter.distributedlog.subscription.ZKSubscriptionStateStore.java
License:Apache License
Future<DLSN> getLastCommitPositionFromZK() { final Promise<DLSN> result = new Promise<DLSN>(); try {//from w w w.j a v a 2 s. co m logger.debug("Reading last commit position from path {}", zkPath); zooKeeperClient.get().getData(zkPath, false, new AsyncCallback.DataCallback() { @Override public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) { logger.debug("Read last commit position from path {}: rc = {}", zkPath, rc); if (KeeperException.Code.NONODE.intValue() == rc) { result.setValue(DLSN.NonInclusiveLowerBound); } else if (KeeperException.Code.OK.intValue() != rc) { result.setException(KeeperException.create(KeeperException.Code.get(rc), path)); } else { try { DLSN dlsn = DLSN.deserialize(new String(data, Charsets.UTF_8)); result.setValue(dlsn); } catch (Exception t) { logger.warn("Invalid last commit position found from path {}", zkPath, t); // invalid dlsn recorded in subscription state store result.setValue(DLSN.NonInclusiveLowerBound); } } } }, null); } catch (ZooKeeperClient.ZooKeeperConnectionException zkce) { result.setException(zkce); } catch (InterruptedException ie) { result.setException(new DLInterruptedException("getLastCommitPosition was interrupted", ie)); } return result; }
From source file:com.twitter.distributedlog.util.FutureUtils.java
License:Apache License
/** * Convert the <i>throwable</i> to zookeeper related exceptions. * * @param throwable cause/*from w ww. j ava 2 s.com*/ * @param path zookeeper path * @return zookeeper related exceptions */ public static Throwable zkException(Throwable throwable, String path) { if (throwable instanceof KeeperException) { return throwable; } else if (throwable instanceof ZooKeeperClient.ZooKeeperConnectionException) { return KeeperException.create(KeeperException.Code.CONNECTIONLOSS, path); } else if (throwable instanceof InterruptedException) { return new DLInterruptedException("Interrupted on operating " + path, throwable); } else { return new UnexpectedException("Encountered unexpected exception on operatiing " + path, throwable); } }
From source file:com.twitter.distributedlog.util.Utils.java
License:Apache License
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 {//from ww w .j av a 2 s. c o m result.setException(KeeperException.create(KeeperException.Code.get(rc), pathOrMessage)); } }
From source file:com.yihaodian.architecture.zkclient.InMemoryConnection.java
License:Apache License
@Override public List<String> getChildren(String path, boolean watch) throws KeeperException, InterruptedException { if (!exists(path, false)) { throw KeeperException.create(Code.NONODE, path); }/*from www .java2s . c o m*/ if (exists(path, false) && watch) { installWatch(_nodeWatches, path); } ArrayList<String> children = new ArrayList<String>(); String[] directoryStack = path.split("/"); Set<String> keySet = _data.keySet(); for (String string : keySet) { if (string.startsWith(path)) { String[] stack = string.split("/"); // is one folder level below the one we loockig for and starts // with path... if (stack.length == directoryStack.length + 1) { children.add(stack[stack.length - 1]); } } } return children; }
From source file:com.zookeeper.web.inspector.manager.ZooInspectorManagerImpl.java
License:Apache License
Item getChildrenAndStat(String nodePath) throws KeeperException { // System.out.println("getChildrenAndStat(), path: " + nodePath); if (zooKeeper.getState() != States.CONNECTED) { throw KeeperException.create(KeeperException.Code.CONNECTIONLOSS, nodePath); }// w w w . j av a 2s.c om try { Stat stat = new Stat(); List<String> childs = zooKeeper.getChildren(nodePath, false, stat); return new Item(childs, stat); } catch (NoNodeException e) { // OK to return null } catch (KeeperException e) { throw e; } catch (Exception e) { LoggerFactory.getLogger().error("Error occurred retrieving children of node: " + nodePath, e); } return null; }
From source file:com.zookeeper.zkclient.InMemoryConnection.java
License:Apache License
@Override public List<String> getChildren(String path, boolean watch) throws KeeperException, InterruptedException { if (!exists(path, false)) { throw KeeperException.create(Code.NONODE, path); }/*from w ww. j a va 2s. c o m*/ if (exists(path, false) && watch) { installWatch(_nodeWatches, path); } checkACL(path, ZooDefs.Perms.READ); ArrayList<String> children = new ArrayList<String>(); String[] directoryStack = path.split("/"); Set<String> keySet = _data.keySet(); for (String string : keySet) { if (string.startsWith(path)) { String[] stack = string.split("/"); // is one folder level below the one we loockig for and starts // with path... if (stack.length == directoryStack.length + 1) { children.add(stack[stack.length - 1]); } } } return children; }
From source file:io.pravega.controller.store.index.ZKHostIndex.java
License:Apache License
private StoreException translateErrorCode(String path, CuratorEvent event) { StoreException ex;// ww w . ja v a 2s. c o m if (event.getResultCode() == KeeperException.Code.CONNECTIONLOSS.intValue() || event.getResultCode() == KeeperException.Code.SESSIONEXPIRED.intValue() || event.getResultCode() == KeeperException.Code.SESSIONMOVED.intValue() || event.getResultCode() == KeeperException.Code.OPERATIONTIMEOUT.intValue()) { ex = StoreException.create(StoreException.Type.CONNECTION_ERROR, path); } else if (event.getResultCode() == KeeperException.Code.NODEEXISTS.intValue()) { ex = StoreException.create(StoreException.Type.DATA_EXISTS, path); } else if (event.getResultCode() == KeeperException.Code.BADVERSION.intValue()) { ex = StoreException.create(StoreException.Type.WRITE_CONFLICT, path); } else if (event.getResultCode() == KeeperException.Code.NONODE.intValue()) { ex = StoreException.create(StoreException.Type.DATA_NOT_FOUND, path); } else if (event.getResultCode() == KeeperException.Code.NOTEMPTY.intValue()) { ex = StoreException.create(StoreException.Type.DATA_CONTAINS_ELEMENTS, path); } else { ex = StoreException.create(StoreException.Type.UNKNOWN, KeeperException.create(KeeperException.Code.get(event.getResultCode()), path)); } return ex; }