public class ZKUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
SERVICE_MASTER_NODE |
static int |
TIMEOUT |
static int |
TIMEOUT_SERVER |
static int |
ZK_RETRIALS |
| Constructor and Description |
|---|
ZKUtils() |
| Modifier and Type | Method and Description |
|---|---|
static org.apache.zookeeper.data.Stat |
checkZKNodeForExistence(org.apache.zookeeper.ZooKeeper s_zk,
java.lang.String nodeName,
org.apache.zookeeper.Watcher watcher,
int retrials)
Helper method to check for node existence in ZK with retrial logic in case of connection loss
|
static byte[] |
getData(org.apache.zookeeper.ZooKeeper s_zk,
java.lang.String nodeName,
org.apache.zookeeper.Watcher watcher,
org.apache.zookeeper.data.Stat stat,
int retrials)
Helper method to get data from ZK with retrial logic in case of connection loss
|
static java.util.List<java.lang.String> |
getZkNodeChildren(org.apache.zookeeper.ZooKeeper s_zk,
java.lang.String nodeName,
org.apache.zookeeper.Watcher watcher,
int retrials)
Helper method to get znode children from ZK with retrial logic in case of connection loss
|
static void |
resetZookeeper(java.lang.String zkAddresses,
org.apache.zookeeper.ZooKeeper s_zk,
org.apache.zookeeper.Watcher watcher)
Method to reset ZK - in case of KeeperException.SessionExpiredException
that exception should actually remove znode from ZK - at least for nodes, as they are going to be
EPHEMERAL_SEQUENTIAL, so we need to make sure that even new "master" is in place because of this
(worst case master got SessionExpiredException)
we do not restart service on any other node if it is running on "this one"
Using writelock to prevent "reading" threads to get data that is in inconsistent state - during reset
|
public static final int ZK_RETRIALS
public static final int TIMEOUT
public static final int TIMEOUT_SERVER
public static final java.lang.String SERVICE_MASTER_NODE
public static byte[] getData(org.apache.zookeeper.ZooKeeper s_zk,
java.lang.String nodeName,
org.apache.zookeeper.Watcher watcher,
org.apache.zookeeper.data.Stat stat,
int retrials)
throws org.apache.zookeeper.KeeperException,
java.lang.InterruptedException,
ZKClosedException
s_zk - nodeName - watcher - stat - retrials - org.apache.zookeeper.KeeperExceptionjava.lang.InterruptedExceptionZKClosedExceptionpublic static org.apache.zookeeper.data.Stat checkZKNodeForExistence(org.apache.zookeeper.ZooKeeper s_zk,
java.lang.String nodeName,
org.apache.zookeeper.Watcher watcher,
int retrials)
throws org.apache.zookeeper.KeeperException,
java.lang.InterruptedException,
ZKClosedException
s_zk - nodeName - watcher - retrials - org.apache.zookeeper.KeeperExceptionjava.lang.InterruptedExceptionZKClosedExceptionpublic static java.util.List<java.lang.String> getZkNodeChildren(org.apache.zookeeper.ZooKeeper s_zk,
java.lang.String nodeName,
org.apache.zookeeper.Watcher watcher,
int retrials)
throws org.apache.zookeeper.KeeperException,
java.lang.InterruptedException,
ZKClosedException
s_zk - nodeName - watcher - retrials - org.apache.zookeeper.KeeperExceptionjava.lang.InterruptedExceptionZKClosedExceptionpublic static void resetZookeeper(java.lang.String zkAddresses,
org.apache.zookeeper.ZooKeeper s_zk,
org.apache.zookeeper.Watcher watcher)
throws java.io.IOException
s_zk - watcher - java.io.IOException