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; }
public String call() throws Exception { return transport.getZKHandle().create() .creatingParentsIfNeeded() .withMode(CreateMode.EPHEMERAL) .forPath(memberpath); } });
public String call() throws Exception { return transport.getZKHandle().create() .creatingParentsIfNeeded() .withMode(CreateMode.PERSISTENT) .forPath(subgroup); } });
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); } }