/** * The Asynchronous version of getConfig. * * @see #getData(String, boolean, Stat) */ public void getConfig(boolean watch, DataCallback cb, Object ctx) { getConfig(watch ? watchManager.defaultWatcher : null, cb, ctx); }
/** * Return the last committed configuration (as known to the server to which the client is connected) * and the stat of the configuration. * <p> * If the watch is true and the call is successful (no exception is * thrown), a watch will be left on the configuration node (ZooDefs.CONFIG_NODE). The watch * will be triggered by a successful reconfig operation * <p> * A KeeperException with error code KeeperException.NoNode will be thrown * if no node with the given path exists. * * @param watch whether need to watch this node * @param stat the stat of the configuration node ZooDefs.CONFIG_NODE * @return configuration data stored in ZooDefs.CONFIG_NODE * @throws KeeperException If the server signals an error with a non-zero error code * @throws InterruptedException If the server transaction is interrupted. */ public byte[] getConfig(boolean watch, Stat stat) throws KeeperException, InterruptedException { return getConfig(watch ? watchManager.defaultWatcher : null, stat); }
@Override public boolean exec() throws CliException { boolean watch = cl.hasOption("w"); Stat stat = new Stat(); byte data[]; try { data = zk.getConfig(watch, stat); } catch (KeeperException|InterruptedException ex) { throw new CliWrapperException(ex); } data = (data == null) ? "null".getBytes() : data; if (cl.hasOption("c")) { out.println(ConfigUtils.getClientConfigStr(new String(data))); } else { out.println(new String(data)); } if (cl.hasOption("s")) { new StatPrinter(out).print(stat); } return watch; } }
config = zk.getConfig(false, new Stat()); break; } catch (KeeperException.ConnectionLossException e) {
ReconfigTest.testServerHasConfig(zkHandles[leaderId], null, null); LOG.info("Initial Configuration:\n" + new String(zkHandles[leaderId].getConfig(this, new Stat()))); testReconfig(leaderId, true, reconfigServers); LOG.info("Configuration after adding 2 followers:\n" + new String(zkHandles[leaderId].getConfig(this, new Stat()))); testReconfig(follower2, false, reconfigServers); LOG.info("Configuration after removing leader and follower 1:\n" + new String(zkHandles[follower2].getConfig(this, new Stat()))); testReconfig(follower2, true, observerStrings); //change to observers LOG.info("Configuration after adding two observers:\n" + new String(zkHandles[follower2].getConfig(this, new Stat())));
@Override public byte[] call() throws Exception { if ( watching.isWatched() ) { return client.getZooKeeper().getConfig(true, stat); } byte[] config = client.getZooKeeper().getConfig(watching.getWatcher(ZooDefs.CONFIG_NODE), stat); watching.commitWatcher(KeeperException.NoNodeException.Code.OK.intValue(), false); return config; } }