Example usage for org.apache.zookeeper.server ServerCnxnFactory join

List of usage examples for org.apache.zookeeper.server ServerCnxnFactory join

Introduction

In this page you can find the example usage for org.apache.zookeeper.server ServerCnxnFactory join.

Prototype

public abstract void join() throws InterruptedException;

Source Link

Usage

From source file:org.apache.airavata.common.utils.AiravataZKUtils.java

License:Apache License

public static void runZKFromConfig(ServerConfig config, ServerCnxnFactory cnxnFactory) throws IOException {
    AiravataZKUtils.logger.info("Starting Zookeeper server...");
    FileTxnSnapLog txnLog = null;//from  w  ww .j  a v  a 2  s .  c o m
    try {
        // Note that this thread isn't going to be doing anything else,
        // so rather than spawning another thread, we will just call
        // run() in this thread.
        // create a file logger url from the command line args
        ZooKeeperServer zkServer = new ZooKeeperServer();

        txnLog = new FileTxnSnapLog(new File(config.getDataDir()), new File(config.getDataDir()));
        zkServer.setTxnLogFactory(txnLog);
        zkServer.setTickTime(config.getTickTime());
        zkServer.setMinSessionTimeout(config.getMinSessionTimeout());
        zkServer.setMaxSessionTimeout(config.getMaxSessionTimeout());
        cnxnFactory = ServerCnxnFactory.createFactory();
        cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns());
        cnxnFactory.startup(zkServer);
        cnxnFactory.join();
        if (zkServer.isRunning()) {
            zkServer.shutdown();
        }
    } catch (InterruptedException e) {
        // warn, but generally this is ok
        AiravataZKUtils.logger.warn("Server interrupted", e);
        System.exit(1);
    } finally {
        if (txnLog != null) {
            txnLog.close();
        }
    }
}