本文整理了Java中org.apache.hadoop.hbase.zookeeper.ZKUtil.createNodeIfNotExistsAndWatch()
方法的一些代码示例,展示了ZKUtil.createNodeIfNotExistsAndWatch()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZKUtil.createNodeIfNotExistsAndWatch()
方法的具体详情如下:
包路径:org.apache.hadoop.hbase.zookeeper.ZKUtil
类名称:ZKUtil
方法名:createNodeIfNotExistsAndWatch
[英]Creates the specified znode to be a persistent node carrying the specified data. Returns true if the node was successfully created, false if the node already existed. If the node is created successfully, a watcher is also set on the node. If the node is not created successfully because it already exists, this method will also set a watcher on the node but return false. If there is another problem, a KeeperException will be thrown.
[中]将指定的znode创建为承载指定数据的持久节点。如果节点已成功创建,则返回true;如果节点已存在,则返回false。如果节点创建成功,也会在节点上设置观察者。如果由于节点已存在而未能成功创建该节点,此方法还将在该节点上设置一个监视程序,但返回false。如果还有其他问题,将抛出KeeperException。
代码示例来源:origin: harbby/presto-connectors
/**
* Utility method to ensure an ENABLED znode is in place; if not present, we create it.
* @param zookeeper
* @param path Path to znode to check
* @return True if we created the znode.
* @throws NodeExistsException
* @throws KeeperException
*/
private static boolean ensurePeerEnabled(final ZooKeeperWatcher zookeeper, final String path)
throws NodeExistsException, KeeperException {
if (ZKUtil.checkExists(zookeeper, path) == -1) {
// There is a race b/w PeerWatcher and ReplicationZookeeper#add method to create the
// peer-state znode. This happens while adding a peer.
// The peer state data is set as "ENABLED" by default.
ZKUtil.createNodeIfNotExistsAndWatch(zookeeper, path,
ReplicationStateZKBase.ENABLED_ZNODE_BYTES);
return true;
}
return false;
}
代码示例来源:origin: co.cask.hbase/hbase
/**
* Add a new peer to this cluster
* @param id peer's identifier
* @param clusterKey ZK ensemble's addresses, client port and root znode
* @throws IllegalArgumentException Thrown when the peer doesn't exist
* @throws IllegalStateException Thrown when a peer already exists, since
* multi-slave isn't supported yet.
*/
public void addPeer(String id, String clusterKey) throws IOException {
try {
if (peerExists(id)) {
throw new IllegalArgumentException("Cannot add existing peer");
}
ZKUtil.createWithParents(this.zookeeper, this.peersZNode);
ZKUtil.createAndWatch(this.zookeeper, ZKUtil.joinZNode(this.peersZNode, id),
Bytes.toBytes(clusterKey));
// There is a race b/w PeerWatcher and ReplicationZookeeper#add method to create the
// peer-state znode. This happens while adding a peer.
// The peer state data is set as "ENABLED" by default.
ZKUtil.createNodeIfNotExistsAndWatch(this.zookeeper, getPeerStateNode(id),
Bytes.toBytes(PeerState.ENABLED.name()));
} catch (KeeperException e) {
throw new IOException("Unable to add peer", e);
}
}
代码示例来源:origin: co.cask.hbase/hbase
/**
* start a state tracker to check whether this peer is enabled or not
*
* @param zookeeper zk watcher for the local cluster
* @param peerStateNode path to zk node which stores peer state
* @throws KeeperException
*/
public void startStateTracker(ZooKeeperWatcher zookeeper, String peerStateNode)
throws KeeperException {
if (ZKUtil.checkExists(zookeeper, peerStateNode) == -1) {
// There is a race b/w PeerWatcher and ReplicationZookeeper#add method to create the
// peer-state znode. This happens while adding a peer.
// The peer state data is set as "ENABLED" by default.
ZKUtil.createNodeIfNotExistsAndWatch(zookeeper, peerStateNode,
Bytes.toBytes(PeerState.ENABLED.name()));
}
this.peerStateTracker = new PeerStateTracker(peerStateNode, zookeeper,
this);
this.peerStateTracker.start();
this.readPeerStateZnode();
}
代码示例来源:origin: co.cask.hbase/hbase
continue;
ZKUtil.createNodeIfNotExistsAndWatch(this.zookeeper, newClusterZnode,
HConstants.EMPTY_BYTE_ARRAY);
SortedSet<String> logQueue = new TreeSet<String>();
代码示例来源:origin: harbby/presto-connectors
continue;
ZKUtil.createNodeIfNotExistsAndWatch(this.zookeeper, newClusterZnode,
HConstants.EMPTY_BYTE_ARRAY);
SortedSet<String> logQueue = new TreeSet<String>();
内容来源于网络,如有侵权,请联系作者删除!