Example usage for org.apache.zookeeper.server.persistence FileTxnSnapLog close

List of usage examples for org.apache.zookeeper.server.persistence FileTxnSnapLog close

Introduction

In this page you can find the example usage for org.apache.zookeeper.server.persistence FileTxnSnapLog close.

Prototype

public void close() throws IOException 

Source Link

Document

close the transaction log files

Usage

From source file:co.paralleluniverse.galaxy.test.GalaxyTestingUtils.java

License:Open Source License

public static ServerCnxnFactory startZookeeper(final String configResource, final String dataDirName)
        throws IOException, QuorumPeerConfig.ConfigException {
    ServerConfig sc = new ServerConfig();
    sc.parse(pathToResource(configResource));
    deleteDir(dataDirName);//from  ww  w . jav  a  2s. c  o  m
    new File(dataDirName).mkdirs();
    FileTxnSnapLog txnLog = null;
    try {
        ZooKeeperServer zkServer = new ZooKeeperServer();

        txnLog = new FileTxnSnapLog(new File(sc.getDataDir()), new File(sc.getDataDir()));
        zkServer.setTxnLogFactory(txnLog);
        zkServer.setTickTime(sc.getTickTime());
        zkServer.setMinSessionTimeout(sc.getMinSessionTimeout());
        zkServer.setMaxSessionTimeout(sc.getMaxSessionTimeout());
        ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory();
        cnxnFactory.configure(sc.getClientPortAddress(), sc.getMaxClientCnxns());
        cnxnFactory.startup(zkServer);
        return cnxnFactory;
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    } finally {
        if (txnLog != null) {
            txnLog.close();
        }
    }
}

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;
    try {/*from  w  ww. j  av  a  2 s  .co  m*/
        // 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();
        }
    }
}