protected TransactionalState(Map conf, String id, Map componentConf, String subroot) { try { conf = new HashMap(conf); // ensure that the serialization registrations are consistent with the declarations in this spout if(componentConf!=null) { conf.put(Config.TOPOLOGY_KRYO_REGISTER, componentConf .get(Config.TOPOLOGY_KRYO_REGISTER)); } String rootDir = conf.get(Config.TRANSACTIONAL_ZOOKEEPER_ROOT) + "/" + id + "/" + subroot; List<String> servers = (List<String>) getWithBackup(conf, Config.TRANSACTIONAL_ZOOKEEPER_SERVERS, Config.STORM_ZOOKEEPER_SERVERS); Object port = getWithBackup(conf, Config.TRANSACTIONAL_ZOOKEEPER_PORT, Config.STORM_ZOOKEEPER_PORT); CuratorFramework initter = Utils.newCuratorStarted(conf, servers, port); try { initter.create().creatingParentsIfNeeded().forPath(rootDir); } catch(KeeperException.NodeExistsException e) { } initter.close(); _curator = Utils.newCuratorStarted(conf, servers, port, rootDir); _ser = new KryoValuesSerializer(conf); _des = new KryoValuesDeserializer(conf); } catch (Exception e) { throw new RuntimeException(e); } }
public String createNode(CuratorFramework zk, String path, byte[] data, org.apache.zookeeper.CreateMode mode) throws Exception { String npath = PathUtils.normalize_path(path); return zk.create().withMode(mode).withACL(ZooDefs.Ids.OPEN_ACL_UNSAFE) .forPath(npath, data); }
client.create().creatingParentsIfNeeded().forPath(pref); client.create().withMode(EPHEMERAL).inBackground(new BackgroundCallback() {
client.create().forPath(readyPath);
if ( createIt ) client.create().forPath(path, newValue);
public void setData(String path, Object obj) { path = "/" + path; byte[] ser = _ser.serializeObject(obj); try { if(_curator.checkExists().forPath(path)!=null) { _curator.setData().forPath(path, ser); } else { _curator.create() .creatingParentsIfNeeded() .withMode(CreateMode.PERSISTENT) .forPath(path, ser); } } catch(Exception e) { throw new RuntimeException(e); } }
@VisibleForTesting void internalCreateNode(String path, byte[] bytes, BackgroundCallback callback) throws Exception { client.create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).inBackground(callback).forPath(path, bytes); }
/** * Forcibly sets the value any guarantees of atomicity. * * @param newValue the new value * @throws Exception ZooKeeper errors */ public void forceSet(byte[] newValue) throws Exception { try { ensurePath.ensure(client.getZookeeperClient()); client.setData().forPath(path, newValue); } catch ( KeeperException.NoNodeException dummy ) { try { client.create().forPath(path, newValue); } catch ( KeeperException.NodeExistsException dummy2 ) { client.setData().forPath(path, newValue); } } }
/** * 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 } }
public String call() throws Exception { return transport.getZKHandle().create() .withMode(CreateMode.PERSISTENT) .forPath(groupname); } });
client.create().creatingParentsIfNeeded().forPath(queuePath); client.create().creatingParentsIfNeeded().forPath(lockPath);
private void doPutInForeground(final T item, String path, final MultiItem<T> givenMultiItem, byte[] bytes) throws Exception { client.create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath(path, bytes); synchronized(putCount) { putCount.decrementAndGet(); putCount.notifyAll(); } putListenerContainer.forEach ( new Function<QueuePutListener<T>, Void>() { @Override public Void apply(QueuePutListener<T> listener) { if ( item != null ) { listener.putCompleted(item); } else { listener.putMultiCompleted(givenMultiItem); } return null; } } ); }
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; }
/** * 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; }
public String call() throws Exception { return transport.getZKHandle().create() .creatingParentsIfNeeded() .withMode(CreateMode.EPHEMERAL) .forPath(memberpath); } });
try client.create().withMode(CreateMode.EPHEMERAL).forPath(lockNodePath); lockCreated = true;
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); } });
/** * 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(); }