List of usage examples for org.apache.zookeeper KeeperException getMessage
@Override
public String getMessage()
From source file:org.apache.blur.zookeeper.WatchChildren.java
License:Apache License
private void startDoubleCheckThread() { _doubleCheckThread = new Thread(new Runnable() { @Override/*from www.j av a 2 s.c o m*/ public void run() { while (_running.get()) { try { synchronized (_running) { _running.wait(_delay); } if (!_running.get()) { return; } if (_zooKeeper.exists(_path, false) == null) { LOG.debug("Path for watching not found [{0}], no longer double checking.", _path); return; } List<String> children = _zooKeeper.getChildren(_path, false); if (!isCorrect(children)) { LOG.error("Double check triggered for [" + _path + "] [" + instance + "]"); synchronized (_lock) { _lock.notify(); } } } catch (KeeperException e) { if (!_running.get()) { LOG.info("Error [{0}]", e.getMessage()); return; } if (e.code() == Code.SESSIONEXPIRED) { LOG.warn("Session expired for [" + _path + "] [" + instance + "]"); return; } LOG.error("Unknown error", e); throw new RuntimeException(e); } catch (InterruptedException e) { return; } } } }); _doubleCheckThread.setName("Poll Watch Children [" + _path + "][" + instance + "]"); _doubleCheckThread.setDaemon(true); _doubleCheckThread.start(); }
From source file:org.apache.blur.zookeeper.WatchNodeData.java
License:Apache License
public WatchNodeData watch(final OnChange onChange) { _watchThread = new Thread(new Runnable() { @Override// w w w. j a v a2 s .co m public void run() { Watcher watcher = new Watcher() { @Override public void process(WatchedEvent event) { synchronized (_lock) { _lock.notify(); } } }; startDoubleCheckThread(); while (_running.get()) { synchronized (_lock) { try { Stat stat = _zooKeeper.exists(_path, false); if (stat == null) { LOG.debug("Path [{0}] not found.", _path); return; } byte[] data = _zooKeeper.getData(_path, watcher, stat); try { onChange.action(data); _data = data; } catch (Throwable t) { LOG.error("Unknown error during onchange action [" + this + "].", t); } _lock.wait(); } catch (KeeperException e) { if (!_running.get()) { LOG.info("Error [{0}]", e.getMessage()); return; } LOG.error("Unknown error", e); throw new RuntimeException(e); } catch (InterruptedException e) { return; } } } } }); _watchThread.setName("Watch Data [" + _path + "][" + instance + "]"); _watchThread.setDaemon(true); _watchThread.start(); return this; }
From source file:org.apache.blur.zookeeper.WatchNodeData.java
License:Apache License
private void startDoubleCheckThread() { _doubleCheckThread = new Thread(new Runnable() { @Override/*from w w w. j a va 2 s .com*/ public void run() { while (_running.get()) { try { synchronized (_running) { _running.wait(_delay); } if (!_running.get()) { return; } Stat stat = _zooKeeper.exists(_path, false); if (stat == null) { LOG.debug("Path [{0}] not found.", _path); synchronized (_lock) { _lock.notify(); } return; } byte[] data = _zooKeeper.getData(_path, false, stat); if (!isCorrect(data)) { LOG.debug("Double check triggered for [" + _path + "]"); synchronized (_lock) { _lock.notify(); } } } catch (KeeperException e) { if (!_running.get()) { LOG.info("Error [{0}]", e.getMessage()); return; } if (e.code() == Code.SESSIONEXPIRED) { LOG.warn("Session expired for [" + _path + "] [" + instance + "]"); return; } LOG.error("Unknown error", e); throw new RuntimeException(e); } catch (InterruptedException e) { return; } } } }); _doubleCheckThread.setName("Poll Watch Data [" + _path + "][" + instance + "]"); _doubleCheckThread.setDaemon(true); _doubleCheckThread.start(); }
From source file:org.apache.blur.zookeeper.WatchNodeExistance.java
License:Apache License
public WatchNodeExistance watch(final OnChange onChange) { _watchThread = new Thread(new Runnable() { @Override//from w ww . j a va 2s . c om public void run() { Watcher watcher = new Watcher() { @Override public void process(WatchedEvent event) { synchronized (_lock) { _lock.notify(); } } }; startDoubleCheckThread(); while (_running.get()) { synchronized (_lock) { try { Stat stat = _zooKeeper.exists(_path, watcher); try { onChange.action(stat); _stat = stat; } catch (Throwable t) { LOG.error("Unknown error during onchange action [" + this + "].", t); } _lock.wait(); } catch (KeeperException e) { if (!_running.get()) { LOG.info("Error [{0}]", e.getMessage()); return; } LOG.error("Unknown error", e); throw new RuntimeException(e); } catch (InterruptedException e) { return; } } } } }); _watchThread.setName("Watch Existance [" + _path + "][" + instance + "]"); _watchThread.setDaemon(true); _watchThread.start(); return this; }
From source file:org.apache.blur.zookeeper.WatchNodeExistance.java
License:Apache License
private void startDoubleCheckThread() { _doubleCheckThread = new Thread(new Runnable() { @Override/*from w w w .j ava2 s. c o m*/ public void run() { while (_running.get()) { try { synchronized (_running) { _running.wait(_delay); } if (!_running.get()) { return; } Stat stat = _zooKeeper.exists(_path, false); if (!isCorrect(stat)) { LOG.debug("Double check triggered for [" + _path + "]"); synchronized (_lock) { _lock.notify(); } } } catch (KeeperException e) { if (!_running.get()) { LOG.info("Error [{0}]", e.getMessage()); return; } if (e.code() == Code.SESSIONEXPIRED) { LOG.warn("Session expired for [" + _path + "] [" + instance + "]"); return; } LOG.error("Unknown error", e); throw new RuntimeException(e); } catch (InterruptedException e) { return; } } } }); _doubleCheckThread.setName("Poll Watch Existance [" + _path + "][" + instance + "]"); _doubleCheckThread.setDaemon(true); _doubleCheckThread.start(); }
From source file:org.apache.cxf.dosgi.discovery.zookeeper.InterfaceDataMonitorListenerImpl.java
License:Apache License
/** * iterates through all child nodes of the given node and tries to find endpoints. If the recursive flag * is set it also traverses into the child nodes. * //from w w w. j av a 2s.c o m * @return true if an endpoint was found and if the node therefore needs to be monitored for changes */ private boolean processChildren(String znode, Map<String, Map<String, Object>> newNodes, Map<String, Map<String, Object>> prevNodes) { List<String> children; try { LOG.info("Processing the children of " + znode); children = zookeeper.getChildren(znode, false); boolean foundANode = false; for (String child : children) { Map<String, Object> p = processChild(znode, child, prevNodes.get(child)); if (p != null) { LOG.fine("found new node " + znode + "/[" + child + "] ( []->child ) props: " + p.values()); newNodes.put(child, p); prevNodes.remove(child); foundANode = true; } if (recursive) { String newNode = znode + '/' + child; if (processChildren(newNode, newNodes, prevNodes)) zookeeper.getChildren(newNode, parent); } } return foundANode; } catch (KeeperException e) { LOG.log(Level.SEVERE, "Problem processing Zookeeper node: " + e.getMessage(), e); } catch (InterruptedException e) { LOG.log(Level.SEVERE, "Problem processing Zookeeper node: " + e.getMessage(), e); } return false; }
From source file:org.apache.giraph.zk.GiraphZooKeeperAdmin.java
License:Apache License
/** * Clean the ZooKeeper of all failed and cancelled in-memory * job remnants that pile up on the ZK quorum over time. * @param args the input command line arguments, if any. * @return the System.exit value to return to the console. *//*ww w . j av a 2s. c o m*/ @Override public int run(String[] args) { final GiraphConfiguration giraphConf = new GiraphConfiguration(getConf()); final int zkPort = ZOOKEEPER_SERVER_PORT.get(giraphConf); final String zkBasePath = giraphConf.get(GiraphConstants.BASE_ZNODE_KEY, "") + BspService.BASE_DIR; final String[] zkServerList; String zkServerListStr = giraphConf.getZookeeperList(); if (zkServerListStr.isEmpty()) { throw new IllegalStateException( "GiraphZooKeeperAdmin requires a list " + "of ZooKeeper servers to clean."); } zkServerList = zkServerListStr.split(","); out.println("[GIRAPH-ZKADMIN] Attempting to clean Zookeeper " + "hosts at: " + Arrays.deepToString(zkServerList)); out.println("[GIRAPH-ZKADMIN] Connecting on port: " + zkPort); out.println("[GIRAPH-ZKADMIN] to ZNode root path: " + zkBasePath); try { ZooKeeperExt zooKeeper = new ZooKeeperExt(formatZkServerList(zkServerList, zkPort), GiraphConstants.ZOOKEEPER_SESSION_TIMEOUT.getDefaultValue(), GiraphConstants.ZOOKEEPER_OPS_MAX_ATTEMPTS.getDefaultValue(), GiraphConstants.ZOOKEEPER_SERVERLIST_POLL_MSECS.getDefaultValue(), this); doZooKeeperCleanup(zooKeeper, zkBasePath); return 0; } catch (KeeperException e) { System.err.println( "[ERROR] Failed to do cleanup of " + zkBasePath + " due to KeeperException: " + e.getMessage()); } catch (InterruptedException e) { System.err.println("[ERROR] Failed to do cleanup of " + zkBasePath + " due to InterruptedException: " + e.getMessage()); } catch (UnknownHostException e) { System.err.println("[ERROR] Failed to do cleanup of " + zkBasePath + " due to UnknownHostException: " + e.getMessage()); } catch (IOException e) { System.err.println( "[ERROR] Failed to do cleanup of " + zkBasePath + " due to IOException: " + e.getMessage()); } return -1; }
From source file:org.apache.hadoop.eclipse.release.ZooKeeperClientRelease.java
License:Apache License
@Override public List<ZNode> getChildren(ZNode node) throws IOException, InterruptedException { if (logger.isDebugEnabled()) logger.debug("getChildren(" + node.getPath() + ")"); List<ZNode> childNodes = new ArrayList<ZNode>(); try {/*from w w w. ja v a 2 s .com*/ Stat nodeStat = new Stat(); List<String> children = client.getChildren(node.getPath(), false, nodeStat); copyFromStat(nodeStat, node); if (children != null) { for (String child : children) { ZNode cNode = HadoopFactory.eINSTANCE.createZNode(); cNode.setNodeName(child); cNode.setParent(node); Stat exists = client.exists(cNode.getPath(), false); if (exists != null) { copyFromStat(exists, cNode); childNodes.add(cNode); } } } } catch (KeeperException e) { logger.debug(e.getMessage(), e); throw new IOException(e.getMessage(), e); } if (logger.isDebugEnabled()) logger.debug("getChildren(" + node.getPath() + "): ChildCount=" + childNodes.size()); return childNodes; }
From source file:org.apache.hadoop.eclipse.release.ZooKeeperClientRelease.java
License:Apache License
@Override public void delete(ZNode zkn) throws IOException, InterruptedException { if (logger.isDebugEnabled()) logger.debug("delete(" + zkn.getPath() + ")"); try {//w ww . jav a2s. c om client.delete(zkn.getPath(), -1); } catch (KeeperException e) { throw new IOException(e.getMessage(), e); } }
From source file:org.apache.hadoop.eclipse.release.ZooKeeperClientRelease.java
License:Apache License
@Override public byte[] open(ZNode node) throws InterruptedException, IOException { if (logger.isDebugEnabled()) logger.debug("open(" + node.getPath() + ")"); Stat stat = new Stat(); byte[] nd;//from w ww . ja v a 2 s. c o m try { nd = client.getData(node.getPath(), false, stat); } catch (KeeperException e) { throw new IOException(e.getMessage(), e); } return nd; }