public final class ZooKeeperUtils extends Object
ZooKeeperUtils is a helper used to start embed zookeeper server in CLI host.
For big data guagua application, independent zookeeper instance is recommended, embed server is for user easy to use guagua if there is no zookeeper server in hand.
| Modifier and Type | Field and Description |
|---|---|
static int |
INITAL_ZK_PORT
Initial zookeeper port used for check valid zookeeper port.
|
static int |
RETRY_COUNT
Client connection retry count
|
static int |
TRY_PORT_COUNT
How many ports will be used to launch embed zookeeper server.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
checkIfEmbedZooKeeperStarted(int embedZkClientPort)
Wait for a time period until zookeeper server is started.
|
static boolean |
checkServers(String servers)
Check zookeeper servers, if one of them is alive, return true;
|
static String |
findContainingJar(Class my_class)
Find a jar that contains a class of the same name, if any.
|
static int |
getValidZooKeeperPort()
Check from DEFAULT_ZK_PORT to (DEFAULT_ZK_PORT + TRY_PORT_COUNT) to see if there is valid port to launch embed
zookeeper server.
|
static boolean |
isServerAlive(InetAddress host,
int port)
Check whether a server is alive.
|
static boolean |
isServerAlive(String host,
int port)
Check whether a server is alive.
|
static void |
populateZooKeeperConfFile(String fileName,
Map<String,String> props)
Create zoo.cfg file to launch a embed zookeeper server.
|
static void |
prepZooKeeperConf(String zkFolder,
String fileName,
String clientPort)
Create zookeeper file with specified name and client port setting.
|
static String |
startChildZooKeeperProcess(String zkJavaOpts)
Start embed zookeeper server in a child process.
|
static int |
startEmbedZooKeeper()
Start embed zookeeper server in a daemon thread.
|
public static final int RETRY_COUNT
public static final int TRY_PORT_COUNT
public static final int INITAL_ZK_PORT
public static int getValidZooKeeperPort()
public static void populateZooKeeperConfFile(String fileName, Map<String,String> props)
fileName - zookeeper conf file nameprops - key-value pairs for zookeeper configurationspublic static boolean isServerAlive(InetAddress host, int port)
host - the server hostport - the server portpublic static boolean isServerAlive(String host, int port)
host - the server hostport - the server portpublic static void prepZooKeeperConf(String zkFolder, String fileName, String clientPort) throws IOException
IOExceptionpublic static void checkIfEmbedZooKeeperStarted(int embedZkClientPort)
embedZkClientPort - the valid zookeeper client portpublic static int startEmbedZooKeeper()
throws IOException
IOExceptionpublic static String startChildZooKeeperProcess(String zkJavaOpts) throws IOException
IOExceptionpublic static String findContainingJar(Class my_class)
my_class - the class to findpublic static boolean checkServers(String servers)
Copyright © 2018. All Rights Reserved.