@Override public String apply(String child) { return ZKPaths.makePath(path, child); } }
@Override public String apply(String name) { return ZKPaths.makePath(basePath, name); } }
String makeItemPath() { return ZKPaths.makePath(queuePath, QUEUE_ITEM_NAME); }
/** * 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; }
/** * 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); }
private void addNewQueueIfNeeded(String newQueuePath) throws Exception { if ( newQueuePath == null ) { newQueuePath = ZKPaths.makePath(queuePath, QUEUE_PREFIX + UUID.randomUUID().toString()); } if ( !queues.containsKey(newQueuePath) ) { T queue = queueAllocator.allocateQueue(client, newQueuePath); if ( queues.putIfAbsent(newQueuePath, queue) == null ) { queue.start(); preferredQueues.add(newQueuePath); } } }
/** * Return a list of all current nodes participating in the semaphore * * @return list of nodes * @throws Exception ZK errors, interruptions, etc. */ public Collection<String> getParticipantNodes() throws Exception { return client.getChildren().forPath(ZKPaths.makePath(leasesPath, LEASE_BASE_NAME)); }
NamespaceImpl(CuratorFrameworkImpl client, String namespace) { if ( namespace != null ) { try { PathUtils.validatePath("/" + namespace); } catch ( IllegalArgumentException e ) { throw new IllegalArgumentException("Invalid namespace: " + namespace); } } this.client = client; this.namespace = namespace; ensurePath = (namespace != null) ? new EnsurePath(ZKPaths.makePath("/", namespace)) : null; }
private InterProcessSemaphoreV2(CuratorFramework client, String path, int maxLeases, SharedCountReader count) { this.client = client; lock = new InterProcessMutex(client, ZKPaths.makePath(path, LOCK_PARENT)); this.maxLeases = (count != null) ? count.getCount() : maxLeases; leasesPath = ZKPaths.makePath(path, LEASE_PARENT); if ( count != null ) { count.addListener ( new SharedCountListener() { @Override public void countHasChanged(SharedCountReader sharedCount, int newCount) throws Exception { InterProcessSemaphoreV2.this.maxLeases = newCount; } @Override public void stateChanged(CuratorFramework client, ConnectionState newState) { // no need to handle this here - clients should set their own connection state listener } } ); } }
String fullPath = ZKPaths.makePath(path, name);
private void getInitialQueues() throws Exception { List<String> children = client.getChildren().forPath(queuePath); for ( String child : children ) { String queuePath = ZKPaths.makePath(this.queuePath, child); addNewQueueIfNeeded(queuePath); } if ( children.size() == 0 ) { addNewQueueIfNeeded(null); } }
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; } }
if ( foundNode != null ) foundNode = ZKPaths.makePath(pathAndNode.getPath(), foundNode);
/** * Inserts data into queue. * * @param data the data * @return true if data was successfully added * @throws Exception errors */ public boolean offer(byte[] data) throws Exception { ensurePath.ensure(client.getZookeeperClient()); String thisPath = ZKPaths.makePath(path, PREFIX); client.create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath(thisPath, data); return true; }
private void doWork() { try { List<String> children = client.getChildren().forPath(path); for ( String name : children ) { String thisPath = ZKPaths.makePath(path, name); Stat stat = client.checkExists().forPath(thisPath); if ( (stat != null) && (stat.getNumChildren() == 0) ) { reaper.addPath(thisPath, mode); } } } catch ( Exception e ) { log.error("Could not get children for path: " + path, e); } } }
/** * NOTE: this is a BLOCKING method. Completely rebuild the internal cache by querying * for all needed data WITHOUT generating any events to send to listeners. * * @throws Exception errors */ public void rebuild() throws Exception { Preconditions.checkState(!executorService.isShutdown(), "cache has been closed"); ensurePath.ensure(client.getZookeeperClient()); clear(); List<String> children = client.getChildren().forPath(path); for ( String child : children ) { String fullPath = ZKPaths.makePath(path, child); internalRebuildNode(fullPath); if ( rebuildTestExchanger != null ) { rebuildTestExchanger.exchange(new Object()); } } // this is necessary so that any updates that occurred while rebuilding are taken offerOperation(new RefreshOperation(this, RefreshMode.FORCE_GET_DATA_AND_STAT)); }
String itemPath = ZKPaths.makePath(queuePath, itemNode); Stat stat = new Stat();
private void reset() throws Exception { setLeadership(false); deleteNode(); BackgroundCallback callback = new BackgroundCallback() { @Override public void processResult(CuratorFramework client, CuratorEvent event) throws Exception { if ( event.getResultCode() == KeeperException.Code.OK.intValue() ) { ourPath = event.getName(); getChildren(); } else { log.error("getChildren() failed. rc = " + event.getResultCode()); } } }; client.create().creatingParentsIfNeeded().withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).inBackground(callback).forPath(ZKPaths.makePath(latchPath, LOCK_NAME), LeaderSelector.getIdBytes(id)); }