@Override public String apply(String child) { return ZKPaths.makePath(path, child); } }
private String adjustPath(String path) throws Exception { if ( doProtected ) { ZKPaths.PathAndNode pathAndNode = ZKPaths.getPathAndNode(path); String name = getProtectedPrefix() + pathAndNode.getNode(); path = ZKPaths.makePath(pathAndNode.getPath(), name); } return path; } }
/** * Make sure all the nodes in the path are created. NOTE: Unlike File.mkdirs(), Zookeeper doesn't distinguish * between directories and files. So, every node in the path is created. The data for each node is an empty blob * * @param zookeeper the client * @param path path to ensure * @throws InterruptedException thread interruption * @throws org.apache.zookeeper.KeeperException * Zookeeper errors */ public static void mkdirs(ZooKeeper zookeeper, String path) throws InterruptedException, KeeperException { mkdirs(zookeeper, path, true); }
private void checkLeadership(List<String> children) throws Exception int ourIndex = (ourPath != null) ? sortedChildren.indexOf(ZKPaths.getNodeFromPath(ourPath)) : -1; if ( ourIndex < 0 ) client.checkExists().usingWatcher(watcher).inBackground(callback).forPath(ZKPaths.makePath(latchPath, watchPath));
sendBackgroundResponse(KeeperException.Code.OK.intValue(), createdPath, backgrounding.getContext(), ZKPaths.getNodeFromPath(createdPath), this);
/** * NOTE: this is a BLOCKING method. Rebuild the internal cache for the given node by querying * for all needed data WITHOUT generating any events to send to listeners. * * @param fullPath full path of the node to rebuild * @throws Exception errors */ public void rebuildNode(String fullPath) throws Exception { Preconditions.checkArgument(ZKPaths.getPathAndNode(fullPath).getPath().equals(path), "Node is not part of this cache: " + fullPath); Preconditions.checkState(!executorService.isShutdown(), "cache has been closed"); ensurePath.ensure(client.getZookeeperClient()); internalRebuildNode(fullPath); // this is necessary so that any updates that occurred while rebuilding are taken // have to rebuild entire tree in case this node got deleted in the interim offerOperation(new RefreshOperation(this, RefreshMode.FORCE_GET_DATA_AND_STAT)); }
String fixForNamespace(String path) { if ( ensurePath != null ) { try { ensurePath.ensure(client.getZookeeperClient()); } catch ( Exception e ) { client.logError("Ensure path threw exception", e); } } return ZKPaths.fixForNamespace(namespace, path); }
private boolean internalLeave(long startMs, boolean hasMaxWait, long maxWaitMs) throws Exception String ourPathName = ZKPaths.getNodeFromPath(ourPath); boolean ourNodeShouldExist = true; boolean result = true; if ( IsLowestNode ) String highestNodePath = ZKPaths.makePath(barrierPath, children.get(children.size() - 1)); stat = client.checkExists().usingWatcher(watcher).forPath(highestNodePath); String lowestNodePath = ZKPaths.makePath(barrierPath, children.get(0)); stat = client.checkExists().usingWatcher(watcher).forPath(lowestNodePath);
private void applyNewData(String fullPath, int resultCode, Stat stat, byte[] bytes) { if ( resultCode == KeeperException.Code.OK.intValue() ) // otherwise - node must have dropped or something - we should be getting another event { ChildData data = new ChildData(fullPath, stat, bytes); ChildData previousData = currentData.put(fullPath, data); if ( previousData == null ) // i.e. new { offerOperation(new EventOperation(this, new PathChildrenCacheEvent(PathChildrenCacheEvent.Type.CHILD_ADDED, data))); } else if ( previousData.getStat().getVersion() != stat.getVersion() ) { offerOperation(new EventOperation(this, new PathChildrenCacheEvent(PathChildrenCacheEvent.Type.CHILD_UPDATED, data))); } updateInitialSet(ZKPaths.getNodeFromPath(fullPath), data); } }
@Override public String apply(String name) { return ZKPaths.makePath(basePath, name); } }
String path = (nodeData != null) ? createBuilder.forPath(ZKPaths.makePath(leasesPath, LEASE_BASE_NAME), nodeData) : createBuilder.forPath(ZKPaths.makePath(leasesPath, LEASE_BASE_NAME)); String nodeName = ZKPaths.getNodeFromPath(path); builder.add(makeLease(path));
try final ZKPaths.PathAndNode pathAndNode = ZKPaths.getPathAndNode(path); List<String> children = client.getZooKeeper().getChildren(pathAndNode.getPath(), false); if ( foundNode != null ) foundNode = ZKPaths.makePath(pathAndNode.getPath(), foundNode);
@Override public Object call() throws Exception { ZKPaths.mkdirs(client.getZooKeeper(), path, makeLastNode); helper.set(doNothingHelper); isSet = true; return null; } }
String makeItemPath() { return ZKPaths.makePath(queuePath, QUEUE_ITEM_NAME); }
@Override public void performBackgroundOperation(OperationAndData<PathAndBytes> dummy) throws Exception { try { ZKPaths.mkdirs(client.getZooKeeper(), mainOperationAndData.getData().getPath(), false); } catch ( KeeperException e ) { // ignore } client.queueOperation(mainOperationAndData); } };
/** * Apply the namespace to the given path * * @param namespace namespace (can be null) * @param path path * @return adjusted path */ public static String fixForNamespace(String namespace, String path) { if ( namespace != null ) { return makePath(namespace, path); } return path; }
ZKPaths.mkdirs(client.getZooKeeper(), path, false); createdPath = client.getZooKeeper().create(path, data, acling.getAclList(path), createMode);
/** * Creates the barrier abstraction. <code>memberQty</code> is the number of members in the * barrier. When {@link #enter()} is called, it blocks until all members have entered. When * {@link #leave()} is called, it blocks until all members have left. * * @param client the client * @param barrierPath path to use * @param memberQty the number of members in the barrier. NOTE: more than <code>memberQty</code> * can enter the barrier. <code>memberQty</code> is a threshold, not a limit */ public DistributedDoubleBarrier(CuratorFramework client, String barrierPath, int memberQty) { Preconditions.checkState(memberQty > 0, "memberQty cannot be 0"); this.client = client; this.barrierPath = barrierPath; this.memberQty = memberQty; ourPath = ZKPaths.makePath(barrierPath, UUID.randomUUID().toString()); readyPath = ZKPaths.makePath(barrierPath, READY_NODE); }
String unfixForNamespace(String path) { if ( (namespace != null) && (path != null) ) { String namespacePath = ZKPaths.makePath(namespace, null); if ( path.startsWith(namespacePath) ) { path = (path.length() > namespacePath.length()) ? path.substring(namespacePath.length()) : "/"; } } return path; }
LockInternals(CuratorFramework client, LockInternalsDriver driver, String path, String lockName, int maxLeases) { this.driver = driver; this.lockName = lockName; this.maxLeases = maxLeases; PathUtils.validatePath(path); this.client = client; this.basePath = path; this.path = ZKPaths.makePath(path, lockName); }