/** * Sets the data of the existing znode to be the specified data. The node must * exist but no checks are done on the existing data or version. * * <p> * If the node does not exist, a {@link org.apache.zookeeper.KeeperException.NoNodeException} will be thrown. * * <p> * No watches are set but setting data will trigger other watchers of this * node. * * <p> * If there is another problem, a KeeperException will be thrown. * * @param zkw * zk reference * @param znode * path of node * @param data * data to set for node * @throws org.apache.zookeeper.KeeperException * if unexpected zookeeper exception */ public static void setData(ZooKeeperWatcher zkw, String znode, byte[] data) throws KeeperException, KeeperException.NoNodeException { setData(zkw, znode, data, -1); }
/** * Sets the cluster as up. * * @throws org.apache.zookeeper.KeeperException * unexpected zk exception */ public void setClusterUp() throws KeeperException { byte[] upData = toByteArray(); try { ZKUtil.createAndWatch(watcher, watcher.clusterStateZNode, upData); } catch (KeeperException.NodeExistsException nee) { ZKUtil.setData(watcher, watcher.clusterStateZNode, upData); } }
/** * Set data into node creating node if it doesn't yet exist. Does not set * watch. * * @param zkw * zk reference * @param znode * path of node * @param data * data to set for node * @throws org.apache.zookeeper.KeeperException */ public static void createSetData(final ZooKeeperWatcher zkw, final String znode, final byte[] data) throws KeeperException { if (checkExists(zkw, znode) == -1) { ZKUtil.createWithParents(zkw, znode); } ZKUtil.setData(zkw, znode, data); }
/** * Set the balancer on/off * * @param balancerOn * @throws org.apache.zookeeper.KeeperException */ public void setBalancerOn(boolean balancerOn) throws KeeperException { byte[] upData = toByteArray(balancerOn); try { ZKUtil.createAndWatch(watcher, watcher.balancerZNode, upData); } catch (KeeperException.NodeExistsException nee) { ZKUtil.setData(watcher, watcher.balancerZNode, upData); } super.nodeDataChanged(watcher.balancerZNode); }
private void setTableState(final String tableName, final ZooKeeperProtos.Table.State state) throws KeeperException { String znode = ZKUtil.joinZNode(this.watcher.tableZNode, tableName); if (ZKUtil.checkExists(this.watcher, znode) == -1) { ZKUtil.createAndFailSilent(this.watcher, znode); } synchronized (this.cache) { ZooKeeperProtos.Table.Builder builder = ZooKeeperProtos.Table .newBuilder(); builder.setState(state); byte[] data = builder.build().toByteArray(); ZKUtil.setData(this.watcher, znode, data); this.cache.put(tableName, state); } }
rt = EntityGroupTransaction.createEntityGroupTransition(endState, entityGroup.getEntityGroupName(), serverName, payload); if (!ZKUtil.setData(zkw, node, rt.toByteArray(), stat.getVersion())) { LOG.warn(zkw.prefix("Attempt to transition the " + "unassigned node for " + encoded + " from " + beginState + " to "
boolean setData = false; try { setData = ZKUtil.setData(zkw, node, data, version);