List of usage examples for org.apache.zookeeper KeeperException code
Code code
To view the source code for org.apache.zookeeper KeeperException code.
Click Source Link
From source file:com.facebook.zookeeper.RecoveringZooKeeper.java
License:Apache License
private String createNonSequential(String path, byte[] data, List<ACL> acl, CreateMode createMode) throws KeeperException, InterruptedException { RetryCounter retryCounter = retryCounterFactory.create(); while (true) { try {//from w w w .j a v a 2s . com return zk.create(path, data, acl, createMode); } catch (KeeperException e) { switch (e.code()) { case NODEEXISTS: // Non-sequential node was successfully created return path; case CONNECTIONLOSS: case OPERATIONTIMEOUT: LOG.warn("Possibly transient ZooKeeper exception: " + e); if (!retryCounter.shouldRetry()) { LOG.error("ZooKeeper create failed after " + retryCounter.getMaxRetries() + " retries"); throw e; } break; default: throw e; } } LOG.info("Retrying ZooKeeper after sleeping..."); retryCounter.sleepUntilNextRetry(); retryCounter.useRetry(); } }
From source file:com.facebook.zookeeper.RecoveringZooKeeper.java
License:Apache License
private String createEphemeralSequential(String path, byte[] data, List<ACL> acl, CreateMode createMode) throws KeeperException, InterruptedException { RetryCounter retryCounter = retryCounterFactory.create(); boolean first = true; while (true) { try {//w w w.jav a 2s. c o m if (!first) { // Check if we succeeded on a previous attempt String myNode = findMyEphemeralSequentialNode(path); if (myNode != null) { return myNode; } } first = false; return zk.create(path, data, acl, createMode); } catch (KeeperException e) { switch (e.code()) { case CONNECTIONLOSS: case OPERATIONTIMEOUT: LOG.warn("Possibly transient ZooKeeper exception: " + e); if (!retryCounter.shouldRetry()) { LOG.error("ZooKeeper create failed after " + retryCounter.getMaxRetries() + " retries"); throw e; } break; default: throw e; } } LOG.info("Retrying ZooKeeper after sleeping..."); retryCounter.sleepUntilNextRetry(); retryCounter.useRetry(); } }
From source file:com.github.zkclient.exception.ZkException.java
License:Apache License
public static ZkException create(KeeperException e) { switch (e.code()) { // case DATAINCONSISTENCY: // return new DataInconsistencyException(); // case CONNECTIONLOSS: // return new ConnectionLossException(); case NONODE://w w w .ja va 2 s . c o m return new ZkNoNodeException(e); // case NOAUTH: // return new ZkNoAuthException(); case BADVERSION: return new ZkBadVersionException(e); // case NOCHILDRENFOREPHEMERALS: // return new NoChildrenForEphemeralsException(); case NODEEXISTS: return new ZkNodeExistsException(e); // case INVALIDACL: // return new ZkInvalidACLException(); // case AUTHFAILED: // return new AuthFailedException(); // case NOTEMPTY: // return new NotEmptyException(); // case SESSIONEXPIRED: // return new SessionExpiredException(); // case INVALIDCALLBACK: // return new InvalidCallbackException(); default: return new ZkException(e); } }
From source file:com.jxt.web.cluster.zookeeper.ZookeeperClient.java
License:Apache License
/** * do not create node in path suffix/*from ww w .jav a2 s. com*/ * * @throws PinpointZookeeperException * @throws InterruptedException */ public void createPath(String path) throws PinpointZookeeperException, InterruptedException { checkState(); ZooKeeper zookeeper = this.zookeeper; int pos = 1; do { pos = path.indexOf('/', pos + 1); if (pos != -1) { try { String subPath = path.substring(0, pos); if (zookeeper.exists(subPath, false) != null) { continue; } zookeeper.create(subPath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } catch (KeeperException exception) { if (exception.code() != Code.NODEEXISTS) { handleException(exception); } } } else { pos = path.length(); } } while (pos < path.length()); }
From source file:com.jxt.web.cluster.zookeeper.ZookeeperClient.java
License:Apache License
public String createNode(String zNodePath, byte[] data, CreateMode createMode) throws PinpointZookeeperException, InterruptedException { checkState();/* ww w . ja va2s. com*/ ZooKeeper zookeeper = this.zookeeper; try { if (zookeeper.exists(zNodePath, false) != null) { return zNodePath; } String pathName = zookeeper.create(zNodePath, data, Ids.OPEN_ACL_UNSAFE, createMode); return pathName; } catch (KeeperException exception) { if (exception.code() != Code.NODEEXISTS) { handleException(exception); } } return zNodePath; }
From source file:com.jxt.web.cluster.zookeeper.ZookeeperClient.java
License:Apache License
public List<String> getChildren(String path, boolean watch) throws PinpointZookeeperException, InterruptedException { checkState();/*w w w . jav a2 s .c o m*/ ZooKeeper zookeeper = this.zookeeper; try { return zookeeper.getChildren(path, watch); } catch (KeeperException exception) { if (exception.code() != Code.NONODE) { handleException(exception); } } return Collections.emptyList(); }
From source file:com.jxt.web.cluster.zookeeper.ZookeeperClient.java
License:Apache License
public void delete(String path) throws PinpointZookeeperException, InterruptedException { checkState();// w w w .j av a 2 s . co m ZooKeeper zookeeper = this.zookeeper; try { zookeeper.delete(path, -1); } catch (KeeperException exception) { if (exception.code() != Code.NONODE) { handleException(exception); } } }
From source file:com.jxt.web.cluster.zookeeper.ZookeeperClient.java
License:Apache License
public boolean exists(String path) throws PinpointZookeeperException, InterruptedException { checkState();//from ww w . ja va 2 s .co m ZooKeeper zookeeper = this.zookeeper; try { Stat stat = zookeeper.exists(path, false); if (stat == null) { return false; } } catch (KeeperException exception) { if (exception.code() != Code.NODEEXISTS) { handleException(exception); } } return true; }
From source file:com.jxt.web.cluster.zookeeper.ZookeeperClient.java
License:Apache License
private void handleException(KeeperException keeperException) throws PinpointZookeeperException { switch (keeperException.code()) { case CONNECTIONLOSS: case SESSIONEXPIRED: throw new ConnectionException(keeperException.getMessage(), keeperException); case AUTHFAILED: case INVALIDACL: case NOAUTH:/*from www . j ava 2 s. c o m*/ throw new AuthException(keeperException.getMessage(), keeperException); case BADARGUMENTS: case BADVERSION: case NOCHILDRENFOREPHEMERALS: case NOTEMPTY: case NODEEXISTS: throw new BadOperationException(keeperException.getMessage(), keeperException); case NONODE: throw new NoNodeException(keeperException.getMessage(), keeperException); case OPERATIONTIMEOUT: throw new TimeoutException(keeperException.getMessage(), keeperException); default: throw new UnknownException(keeperException.getMessage(), keeperException); } }
From source file:com.lami.tuomatuo.mq.zookeeper.server.auth.SASLAuthenticationProvider.java
License:Apache License
public KeeperException.Code handleAuthentication(ServerCnxn cnxn, byte[] authData) { // Should never call this: SASL authentication is negotiated at session initiation. // TODO: consider substituting current implementation of direct ClientCnxn manipulation with // a call to this method (SASLAuthenticationProvider:handleAuthentication()) at session initiation. return KeeperException.Code.AUTHFAILED; }