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:io.reign.coord.CoordinationService.java
License:Apache License
public List<String> getBarriers(String clusterId) { String path = getPathScheme().getAbsolutePath(PathType.COORD, clusterId, ReservationType.BARRIER.category()); List<String> children = Collections.EMPTY_LIST; try {// w w w. j a v a 2 s .c om Stat stat = new Stat(); children = getZkClient().getChildren(path, true, stat); } catch (KeeperException e) { if (e.code() == Code.NONODE) { logger.warn("getBarriers(): " + e + ": node does not exist: path={}", path); } else { logger.warn("getBarriers(): " + e, e); } return Collections.EMPTY_LIST; } catch (InterruptedException e) { logger.warn("lookupClusters(): " + e, e); return Collections.EMPTY_LIST; } return children != null ? children : Collections.EMPTY_LIST; }
From source file:io.reign.coord.CoordinationService.java
License:Apache License
public List<String> getSemaphores(String clusterId) { String path = getPathScheme().getAbsolutePath(PathType.COORD, clusterId, ReservationType.SEMAPHORE.category()); List<String> children = Collections.EMPTY_LIST; try {//from w w w . j ava 2 s . c o m Stat stat = new Stat(); children = getZkClient().getChildren(path, true, stat); } catch (KeeperException e) { if (e.code() == Code.NONODE) { logger.warn("getSemaphores(): " + e + ": node does not exist: path={}", path); } else { logger.warn("getSemaphores(): " + e, e); } return Collections.EMPTY_LIST; } catch (InterruptedException e) { logger.warn("lookupClusters(): " + e, e); return Collections.EMPTY_LIST; } return children != null ? children : Collections.EMPTY_LIST; }
From source file:io.reign.coord.ZkDistributedBarrier.java
License:Apache License
@Override public synchronized void reset() { // delete all barrier nodes List<String> childList = getChildList(); for (String child : childList) { String childPath = context.getPathScheme().joinPaths(entityPath, child); try {/* w ww . j a va2s.c om*/ context.getZkClient().delete(childPath, -1); } catch (KeeperException e) { if (e.code() != KeeperException.Code.NONODE) { throw new IllegalStateException(e); } else { logger.trace("Already deleted ZK barrier node: " + e + "; path=" + childPath); } } catch (Exception e) { throw new IllegalStateException(e); } } // delete entity node to reset broken state try { context.getZkClient().delete(entityPath, -1); } catch (KeeperException e) { if (e.code() != KeeperException.Code.NONODE) { throw new IllegalStateException(e); } else { logger.trace("Already deleted ZK barrier node: " + e + "; path=" + entityPath); } } catch (Exception e) { throw new IllegalStateException(e); } // wait for full reset while (conditionsMet || broken) { logger.debug("reset(): conditionsMet={}; broken={}", conditionsMet, broken); try { wait(); } catch (InterruptedException e) { logger.warn("Interrupted while waiting: " + e, e); } } }
From source file:io.reign.coord.ZkDistributedBarrier.java
License:Apache License
private List<String> getChildList() { List<String> childList = Collections.EMPTY_LIST; try {//from w w w . ja v a2s .co m childList = context.getZkClient().getChildren(entityPath, true); } catch (KeeperException e) { if (e.code() != KeeperException.Code.NONODE) { throw new IllegalStateException(e); } } catch (Exception e) { throw new IllegalStateException(e); } return childList; }
From source file:io.reign.coord.ZkReservationManager.java
License:Apache License
/** * /* w w w.j av a2 s .co m*/ * @param reservationPath * @return */ public boolean relinquish(String reservationPath) { if (reservationPath == null) { // likely already deleted logger.trace("Trying to delete ZK reservation node with invalid path: path={}", reservationPath); return true; } // if try { logger.trace("Relinquishing: path={}", reservationPath); zkClient.delete(reservationPath, -1); logger.debug("Relinquished: path={}", reservationPath); return true; } catch (KeeperException e) { if (e.code() == KeeperException.Code.NONODE) { // already deleted, so just log if (logger.isDebugEnabled()) { logger.debug("Already deleted ZK reservation node: " + e + "; path=" + reservationPath, e); } return true; } else { logger.error("Error while deleting ZK reservation node: " + e + "; path=" + reservationPath, e); throw new IllegalStateException( "Error while deleting ZK reservation node: " + e + "; path=" + reservationPath, e); } } catch (Exception e) { logger.error("Error while deleting ZK reservation node: " + e + "; path=" + reservationPath, e); throw new IllegalStateException( "Error while deleting ZK reservation node: " + e + "; path=" + reservationPath, e); } // try }
From source file:io.reign.data.ZkClientLinkedListDataUtil.java
License:Apache License
<V> V readData(String absoluteDataPath, int ttlMillis, Class<V> typeClass) { try {/*from w w w. j a v a2s . c o m*/ // try to get from path cache, use stat modified timestamp instead of cache entry modified timestamp because // we are more interested in when the data last changed byte[] bytes = null; if (bytes == null) { // read data from ZK Stat stat = new Stat(); bytes = zkClient.getData(absoluteDataPath, true, stat); // see if item is expired if (isExpired(stat.getMtime(), ttlMillis)) { return null; } // // update in path cache // pathCache.put(absoluteDataPath, stat, bytes, Collections.EMPTY_LIST); } // deserialize V data = null; if (bytes != null) { data = transcodingScheme.fromBytes(bytes, typeClass); } // logger.debug("readData(): absoluteDataPath={}; index={}; value={}", new Object[] { absoluteDataPath, // index, data }); return data; } catch (KeeperException e) { if (e.code() != KeeperException.Code.NONODE) { logger.error("" + e, e); } return null; } catch (Exception e) { logger.error("" + e, e); return null; } }
From source file:io.reign.data.ZkClientLinkedListDataUtil.java
License:Apache License
String deleteData(String absoluteDataPath, int ttlMillis) { try {/* w w w. ja v a 2 s.c o m*/ // try to get from path cache, use stat modified timestamp instead of cache entry modified timestamp because // we are more interested in when the data last changed Stat stat = null; if (ttlMillis > 0) { // read data from ZK stat = zkClient.exists(absoluteDataPath, true); // see if item is expired if (isExpired(stat.getMtime(), ttlMillis)) { stat = null; } } // if bytes == null, meaning that data for this index is expired or that we are removing regardless of data // age, delete data node String deletedPath = null; if (stat == null) { zkClient.delete(absoluteDataPath, -1); deletedPath = absoluteDataPath; // // remove node entry in path cache // pathCache.remove(absoluteDataPath); // // // update parent children in path cache if parent node exists in cache // String absoluteParentPath = pathScheme.getParentPath(absoluteDataPath); // SimplePathCacheEntry pathCacheEntry = pathCache.get(absoluteParentPath); // if (pathCacheEntry != null) { // List<String> currentChildList = pathCacheEntry.getChildList(); // List<String> newChildList = new ArrayList<String>(currentChildList.size()); // for (String child : currentChildList) { // if (!deletedPath.endsWith(child)) { // newChildList.add(child); // } // } // // pathCache.put(absoluteParentPath, pathCacheEntry.getStat(), pathCacheEntry.getData(), newChildList); // } } return deletedPath; } catch (KeeperException e) { if (e.code() != KeeperException.Code.NONODE) { logger.error("" + e, e); } return null; } catch (Exception e) { logger.error("" + e, e); return null; } }
From source file:io.reign.data.ZkClientMultiDataUtil.java
License:Apache License
/** * //w w w . j av a2 s .c om * @param absoluteBasePath * @param index * @param thresholdMillis * remove data older than given threshold * @return */ String deleteData(String absoluteBasePath, String index, int ttlMillis) { try { String absoluteDataPath = pathScheme.joinPaths(absoluteBasePath, index); // try to get from path cache, use stat modified timestamp instead of cache entry modified timestamp because // we are more interested in when the data last changed byte[] bytes = null; if (ttlMillis > 0) { bytes = null; // if (usePathCache) { // bytes = getDataFromPathCache(absoluteDataPath, ttlMillis); // } if (bytes == null) { // read data from ZK Stat stat = new Stat(); bytes = zkClient.getData(absoluteDataPath, true, stat); // see if item is expired if (isExpired(stat.getMtime(), ttlMillis)) { bytes = null; } } } // if bytes == null, meaning that data for this index is expired or that we are removing regardless of data // age, delete data node String deletedPath = null; if (bytes == null) { // remove node entry in path cache // pathCache.remove(absoluteDataPath); // delete from zk zkClient.delete(absoluteDataPath, -1); deletedPath = absoluteDataPath; // update parent children in path cache if parent node exists in cache String absoluteParentPath = pathScheme.getParentPath(absoluteDataPath); // SimplePathCacheEntry pathCacheEntry = pathCache.get(absoluteParentPath); // if (pathCacheEntry != null) { // List<String> currentChildList = pathCacheEntry.getChildList(); // List<String> newChildList = new ArrayList<String>(currentChildList.size()); // for (String child : currentChildList) { // if (!child.equals(index)) { // newChildList.add(child); // } // } // // // if parent child list is null, that means there are no longer any entries under this key, so // // remove // if (newChildList == null || newChildList.size() == 0) { // // remove from cache // pathCache.remove(absoluteParentPath); // // // remove from ZK // deleteKey(absoluteParentPath); // // } else { // // still entries, so update cache entry // pathCache.put(absoluteParentPath, pathCacheEntry.getStat(), pathCacheEntry.getData(), // newChildList); // } // } else { Stat stat = new Stat(); List<String> childList = Collections.EMPTY_LIST; try { childList = zkClient.getChildren(absoluteParentPath, true, stat); // // update in path cache // pathCache.put(absoluteParentPath, stat, null, childList); // if no children, remove if (childList == null || childList.size() == 0) { deleteKey(absoluteParentPath); } } catch (KeeperException e) { logger.info("" + e, e); } // } } return deletedPath; } catch (KeeperException e) { if (e.code() != KeeperException.Code.NONODE) { logger.error("" + e, e); } return null; } catch (Exception e) { logger.error("" + e, e); return null; } }
From source file:io.reign.data.ZkClientMultiDataUtil.java
License:Apache License
<V> V readData(String absoluteBasePath, String index, int ttlMillis, Class<V> typeClass) { try {// w ww . j a va2 s.c o m String absoluteDataPath = pathScheme.joinPaths(absoluteBasePath, index); // try to get from path cache, use stat modified timestamp instead of cache entry modified timestamp because // we are more interested in when the data last changed byte[] bytes = null; // if (usePathCache) { // bytes = getDataFromPathCache(absoluteDataPath, ttlMillis); // } if (bytes == null) { // read data from ZK Stat stat = new Stat(); bytes = zkClient.getData(absoluteDataPath, true, stat); // see if item is expired if (isExpired(stat.getMtime(), ttlMillis)) { return null; } // update in path cache // pathCache.put(absoluteDataPath, stat, bytes, Collections.EMPTY_LIST); } // deserialize V data = null; if (bytes != null && bytes != EMPTY_BYTE_ARRAY) { data = transcodingScheme.fromBytes(bytes, typeClass); } // logger.debug("readData(): absoluteBasePath={}; index={}; value={}", new Object[] { absoluteBasePath, // index, data }); return data; } catch (KeeperException e) { if (e.code() != KeeperException.Code.NONODE) { logger.error("" + e, e); } return null; } catch (Exception e) { logger.error("" + e, e); return null; } }
From source file:io.reign.data.ZkMultiMapData.java
License:Apache License
@Override public synchronized int size() { Stat stat = null;//from w ww . j a va 2 s . co m zkClientMultiDataUtil.lockForRead(readWriteLock, absoluteBasePath, this); try { stat = new Stat(); List<String> children = zkClient.getChildren(absoluteBasePath, true, stat); } catch (KeeperException e) { if (e.code() == KeeperException.Code.NONODE) { if (logger.isDebugEnabled()) { logger.debug("Path does not exist for data update: " + e + ": path=" + absoluteBasePath); } } else { logger.error("" + e, e); } } catch (InterruptedException e) { logger.warn("Interrupted: " + e, e); } finally { zkClientMultiDataUtil.unlockForRead(readWriteLock); } return stat != null ? stat.getNumChildren() : 0; }