Refine search
@Override public Node getNode(final String path) throws KeeperException { assertClusterIdFlagTrue(); final Stat stat = new Stat(); try { final byte[] bytes = client.getData().storingStatIn(stat).forPath(path); return new Node(path, bytes, stat); } catch (Exception e) { throwIfInstanceOf(e, KeeperException.class); throw new RuntimeException(e); } }
private List<String> getChildren() throws Exception { final Stat childrenStat = new Stat(); while (true) { final List<String> possibleChildren = curator.getChildren() .storingStatIn(childrenStat) .usingWatcher(childrenWatcher) .forPath(path); if (clusterId == null) { // Do not do any checks if the clusterId is not specified on the command line. return possibleChildren; } try { curator.inTransaction() .check().forPath(Paths.configId(clusterId)).and() .check().withVersion(childrenStat.getVersion()).forPath(path).and() .commit(); } catch (KeeperException.BadVersionException e) { // Jobs have somehow changed while we were creating the transaction, retry. continue; } return possibleChildren; } }
@Override public byte[] readData(String path, Stat stat, boolean watch) throws KeeperException, InterruptedException { try { if ( stat != null ) { return watch ? curator.getData().storingStatIn(stat).watched().forPath(path) : curator.getData().storingStatIn(stat).forPath(path); } else { return watch ? curator.getData().watched().forPath(path) : curator.getData().forPath(path); } } catch ( Exception e ) { adjustException(e); } return null; // will never execute }
try Stat stat = context.getExhibitor().getLocalConnection().checkExists().forPath(key); byte[] bytes = context.getExhibitor().getLocalConnection().getData().storingStatIn(stat).forPath(key);
void getDataAndStat(final String fullPath) throws Exception { if (client.checkExists().forPath(fullPath) == null) { return; } final List<String> children = client.getChildren().usingWatcher(watcher).forPath(fullPath); if ( cacheData ) { Stat stat = new Stat(); byte[] data = null; if ( dataIsCompressed ) { data = client.getData().decompressed().storingStatIn(stat).usingWatcher(watcher).forPath(fullPath); } else { data = client.getData().storingStatIn(stat).usingWatcher(watcher).forPath(fullPath); } applyNewData(fullPath, KeeperException.Code.OK.intValue(), stat, data, children); } else { Stat stat = client.checkExists().usingWatcher(watcher).forPath(fullPath); applyNewData(fullPath, KeeperException.Code.OK.intValue(), stat, null, children); } }
private void readValue() throws Exception { Stat localStat = new Stat(); byte[] bytes = client.getData().storingStatIn(localStat).usingWatcher(watcher).forPath(path); updateValue(localStat.getVersion(), bytes); }
void refresh(final String path, final RefreshMode mode) throws Exception { ensurePath.ensure(client.getZookeeperClient()); Stat stat = new Stat(); try { List<String> children = client.getChildren().storingStatIn(stat).usingWatcher(watcher).forPath(path); processChildren(path, children, mode); updateIfNeeded(path, stat, children); } catch (KeeperException.NoNodeException e) { // node no longer exists - ignore log.debug("Node {} is no longer available.", path); } }
/** * Get the data in a ZNode. * @param path Path of the ZNode. * @param stat * @return The data in the ZNode. * @throws Exception If it cannot contact Zookeeper. */ public byte[] getData(final String path, Stat stat) throws Exception { return curator.getData().storingStatIn(stat).forPath(path); }
@Override public T forPath(String path) throws Exception { return inner.forPath(path); }
@Override public Pathable<T> usingWatcher(Watcher watcher) { return new PathableDecorator<>(inner.usingWatcher(wrap(watcher))); }
@Override public Pathable<T> watched() { return new PathableDecorator<>(inner.watched()); }
public static long getDeliveryTag(String experimentID, CuratorFramework curatorClient, String experimentNode, String pickedChild) throws Exception { String deliveryTagPath = experimentNode + File.separator + pickedChild + File.separator + experimentID + DELIVERY_TAG_POSTFIX; Stat exists = curatorClient.checkExists().forPath(deliveryTagPath); if(exists==null) { logger.error("Cannot find delivery Tag in path:" + deliveryTagPath + " for this experiment"); return -1; } return bytesToLong(curatorClient.getData().storingStatIn(exists).forPath(deliveryTagPath)); } public static byte[] longToBytes(long x) {
void getDataAndStat(final String fullPath) throws Exception { if (client.checkExists().forPath(fullPath) == null) { return; } final List<String> children = client.getChildren().usingWatcher(watcher).forPath(fullPath); if ( cacheData ) { Stat stat = new Stat(); byte[] data = null; if ( dataIsCompressed ) { data = client.getData().decompressed().storingStatIn(stat).usingWatcher(watcher).forPath(fullPath); } else { data = client.getData().storingStatIn(stat).usingWatcher(watcher).forPath(fullPath); } applyNewData(fullPath, KeeperException.Code.OK.intValue(), stat, data, children); } else { Stat stat = client.checkExists().usingWatcher(watcher).forPath(fullPath); applyNewData(fullPath, KeeperException.Code.OK.intValue(), stat, null, children); } }
void getDataAndStat(final String fullPath) throws Exception { Stat stat = new Stat(); byte[] data = client.getData().storingStatIn(stat).usingWatcher(dataWatcher).forPath(fullPath); applyNewData(fullPath, KeeperException.Code.OK.intValue(), stat, data); }
void refresh(final String path, final RefreshMode mode) throws Exception { ensurePath.ensure(client.getZookeeperClient()); Stat stat = new Stat(); List<String> children = client.getChildren().storingStatIn(stat).usingWatcher(watcher).forPath(path); processChildren(path, children, mode); updateIfNeeded(path, stat, children); }
private boolean getCurrentValue(MutableAtomicValue<byte[]> result, Stat stat) throws Exception { boolean createIt = false; try { result.preValue = client.getData().storingStatIn(stat).forPath(path); } catch ( KeeperException.NoNodeException e ) { result.preValue = null; createIt = true; } return createIt; }
@Override public Pathable<T> usingWatcher(CuratorWatcher watcher) { return new PathableDecorator<>(inner.usingWatcher(wrap(watcher))); } }
@Override public boolean replace(String key, String oldValue, String newValue) { Assert.notNull(key, "'key' must not be null."); Assert.notNull(oldValue, "'oldValue' must not be null."); Assert.notNull(newValue, "'newValue' must not be null."); synchronized (this.updateMap) { Stat currentStat = new Stat(); try { byte[] bytes = this.client.getData().storingStatIn(currentStat).forPath(getPath(key)); if (oldValue.equals(IntegrationUtils.bytesToString(bytes, this.encoding))) { updateNode(key, newValue, currentStat.getVersion()); } return true; } catch (KeeperException.NoNodeException e) { // ignore, the node doesn't exist there's nothing to replace return false; } catch (KeeperException.BadVersionException e) { // ignore return false; } catch (Exception e) { throw new ZookeeperMetadataStoreException("Cannot replace value"); } } }
public static long getCancelDeliveryTagIfExist(String experimentId, CuratorFramework curatorClient, String experimentNode, String pickedChild) throws Exception { String cancelDeliveryTagPath = experimentNode + File.separator + pickedChild + File.separator + experimentId + AiravataZKUtils.CANCEL_DELIVERY_TAG_POSTFIX; Stat exists = curatorClient.checkExists().forPath(cancelDeliveryTagPath); if (exists == null) { return -1; // no cancel deliverytag found } else { return bytesToLong(curatorClient.getData().storingStatIn(exists).forPath(cancelDeliveryTagPath)); } } }
void getDataAndStat(final String fullPath) throws Exception { Stat stat = new Stat(); byte[] data = client.getData().storingStatIn(stat).usingWatcher(dataWatcher).forPath(fullPath); applyNewData(fullPath, KeeperException.Code.OK.intValue(), stat, data); }