public Stat setData(CuratorFramework zk, String path, byte[] data) throws Exception { String npath = PathUtils.normalize_path(path); return zk.setData().forPath(npath, data); }
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); } }
/** * Utility to mark a lock for revocation. Assuming that the lock has been registered with * a {@link RevocationListener}, it will get called and the lock should be released. Note, * however, that revocation is cooperative. * * @param client the client * @param path the path of the lock - usually from something like * {@link InterProcessMutex#getParticipantNodes()} * @throws Exception errors */ public static void attemptRevoke(CuratorFramework client, String path) throws Exception { try { client.setData().forPath(path, LockInternals.REVOKE_MESSAGE); } catch ( KeeperException.NoNodeException ignore ) { // ignore } }
/** * Change the shared value value irrespective of its previous state * * @param newValue new value * @throws Exception ZK errors, interruptions, etc. */ public void setValue(byte[] newValue) throws Exception { Preconditions.checkState(state.get() == State.STARTED, "not started"); client.setData().forPath(path, newValue); stat.setVersion(stat.getVersion() + 1); value = Arrays.copyOf(newValue, newValue.length); }
public Stat call() throws Exception { return transport.getZKHandle().setData().forPath(memberpath, data); } });
public Stat call() throws Exception { return transport.getZKHandle().setData().forPath(memberpath, data); } });
public Stat call() throws Exception { return transport.getZKHandle().setData().forPath(group, data); } });
public void writeBytes(String path, byte[] bytes) { try { if (!exists(path)) create(path, false); m_curator.setData().forPath(path, bytes); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
/** * 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); } } }
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); } }