ml.shifu.guagua.coordinator.zk
类 ZooKeeperUtils

java.lang.Object
  继承者 ml.shifu.guagua.coordinator.zk.ZooKeeperUtils

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.


字段摘要
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.
 
方法摘要
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 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.
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

RETRY_COUNT

public static final int RETRY_COUNT
Client connection retry count

另请参见:
常量字段值

TRY_PORT_COUNT

public static final int TRY_PORT_COUNT
How many ports will be used to launch embed zookeeper server.

另请参见:
常量字段值

INITAL_ZK_PORT

public static final int INITAL_ZK_PORT
Initial zookeeper port used for check valid zookeeper port.

另请参见:
常量字段值
方法详细信息

getValidZooKeeperPort

public 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.

返回:
valid zookeeper port

populateZooKeeperConfFile

public static void populateZooKeeperConfFile(String fileName,
                                             Map<String,String> props)
Create zoo.cfg file to launch a embed zookeeper server.

参数:
fileName - zookeeper conf file name
props - key-value pairs for zookeeper configurations

isServerAlive

public static boolean isServerAlive(InetAddress host,
                                    int port)
Check whether a server is alive.

参数:
host - the server host
port - the server port
返回:
true if a server is alive, false if a server is not alive.

isServerAlive

public static boolean isServerAlive(String host,
                                    int port)
Check whether a server is alive.

参数:
host - the server host
port - the server port
返回:
true if a server is alive, false if a server is not alive.

prepZooKeeperConf

public static void prepZooKeeperConf(String fileName,
                                     String clientPort)
                              throws IOException
Create zookeeper file with specified name and client port setting.

抛出:
IOException

checkIfEmbedZooKeeperStarted

public static void checkIfEmbedZooKeeperStarted(int embedZkClientPort)
Wait for a time period until zookeeper server is started.

参数:
embedZkClientPort - the valid zookeeper client port

startEmbedZooKeeper

public static int startEmbedZooKeeper()
                               throws IOException
Start embed zookeeper server in a daemon thread.

抛出:
IOException

startChildZooKeeperProcess

public static String startChildZooKeeperProcess(String zkJavaOpts)
                                         throws IOException
Start embed zookeeper server in a child process.

返回:
null if start child process failed, non empty string if valid zookeeper server in child.
抛出:
IOException

findContainingJar

public static String findContainingJar(Class my_class)
Find a jar that contains a class of the same name, if any. It will return a jar file, even if that is not the first thing on the class path that has a class with the same name.

参数:
my_class - the class to find
返回:
a jar file that contains the class, or null

checkServers

public static boolean checkServers(String servers)
Check zookeeper servers, if one of them is alive, return true;



Copyright © 2015. All Rights Reserved.