public boolean create(String path, boolean ephemeral) { try { if (exists(path)) return false; CreateMode createMode = ephemeral ? CreateMode.EPHEMERAL : CreateMode.PERSISTENT; m_curator.create().creatingParentsIfNeeded() .withMode(createMode).forPath(path); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } return true; }
/** * Utility to set the barrier node * * @throws Exception errors */ public synchronized void setBarrier() throws Exception { try { client.create().creatingParentsIfNeeded().forPath(barrierPath); } catch ( KeeperException.NodeExistsException ignore ) { // ignore } }
ourPath = client.create().creatingParentsIfNeeded().withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath(path, localLockNodeBytes); ourPath = client.create().creatingParentsIfNeeded().withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath(path);
PathAndBytesable<String> createBuilder = client.create().creatingParentsIfNeeded().withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL); 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);
public String call() throws Exception { return transport.getZKHandle().create() .creatingParentsIfNeeded() .withMode(CreateMode.EPHEMERAL) .forPath(memberpath); } });
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)); }
public String call() throws Exception { return transport.getZKHandle().create() .creatingParentsIfNeeded() .withMode(CreateMode.PERSISTENT) .forPath(subgroup); } });
/** * The shared value must be started before it can be used. Call {@link #close()} when you are * finished with the shared value * * @throws Exception ZK errors, interruptions, etc. */ public void start() throws Exception { Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Cannot be started more than once"); client.getConnectionStateListenable().addListener(connectionStateListener); try { client.create().creatingParentsIfNeeded().forPath(path, seedValue); } catch ( KeeperException.NodeExistsException ignore ) { // ignore } readValue(); }
public String call() throws Exception { return transport.getZKHandle() .create() .creatingParentsIfNeeded() .withMode(CreateMode.PERSISTENT) .forPath(subgrouppath); } });
public String call() throws Exception { return transport.getZKHandle().create() .creatingParentsIfNeeded() .withMode(CreateMode.EPHEMERAL) .forPath(memberpath); } });
/** * Enter the barrier and block until all members have entered or the timeout has * elapsed * * @param maxWait max time to block * @param unit time unit * @return true if the entry was successful, false if the timeout elapsed first * @throws Exception interruptions, errors, etc. */ public boolean enter(long maxWait, TimeUnit unit) throws Exception { long startMs = System.currentTimeMillis(); boolean hasMaxWait = (unit != null); long maxWaitMs = hasMaxWait ? TimeUnit.MILLISECONDS.convert(maxWait, unit) : Long.MAX_VALUE; boolean readyPathExists = (client.checkExists().usingWatcher(watcher).forPath(readyPath) != null); client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(ourPath); boolean result = (readyPathExists || internalEnter(startMs, hasMaxWait, maxWaitMs)); if ( connectionLost.get() ) { throw new KeeperException.ConnectionLossException(); } return result; }
public void writeBytes(String path, byte[] bytes) { try { if (_curator.checkExists().forPath(path) == null) { _curator.create() .creatingParentsIfNeeded() .withMode(CreateMode.PERSISTENT) .forPath(path, bytes); } else { _curator.setData().forPath(path, bytes); } } catch (Exception e) { throw new RuntimeException(e); } }
private void createOrSet(String path, byte[] data, CreateMode mode) { try { synchronized (this.curator) { if (this.curator.checkExists().forPath(path) != null) { this.curator.setData().forPath(path, data); } else { this.curator.create() .creatingParentsIfNeeded() .withMode(mode) .forPath(path, data); } } } catch (Exception e) { throw new ZooKeeperException(e); } }