Example usage for org.apache.zookeeper.server ZooKeeperServer shutdown

List of usage examples for org.apache.zookeeper.server ZooKeeperServer shutdown

Introduction

In this page you can find the example usage for org.apache.zookeeper.server ZooKeeperServer shutdown.

Prototype

public void shutdown() 

Source Link

Usage

From source file:com.github.zkclient.ZkServer.java

License:Apache License

@PreDestroy
public void shutdown() {
    ZooKeeperServer zk = _zk;
    if (zk == null) {
        LOG.warn("shutdown duplication");
        return;/*from w w  w .j  a  va2s.  co m*/
    } else {
        _zk = null;
    }
    LOG.info("Shutting down ZkServer...");
    try {
        _zkClient.close();
    } catch (ZkException e) {
        LOG.warn("Error on closing zkclient: " + e.getClass().getName());
    }
    if (_nioFactory != null) {
        _nioFactory.shutdown();
        try {
            _nioFactory.join();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        _nioFactory = null;
    }
    zk.shutdown();
    if (zk.getZKDatabase() != null) {
        try {
            // release file description
            zk.getZKDatabase().close();
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
        }
    }
    LOG.info("Shutting down ZkServer...done");
}

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 w  w. j  ava 2s  .  c om*/
    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();
        }
    }
}

From source file:org.apache.apex.malhar.kafka.KafkaOperatorTestBase.java

License:Apache License

public static void stopZookeeper() {
    for (ZooKeeperServer zs : zkServer) {
        if (zs != null) {
            zs.shutdown();
        }/*w ww  .  j av a  2  s. c o  m*/
    }

    for (ServerCnxnFactory zkf : zkFactory) {
        if (zkf != null) {
            zkf.closeAll();
            zkf.shutdown();
        }
    }
    zkServer = new ZooKeeperServer[2];
    zkFactory = new ServerCnxnFactory[2];
}

From source file:org.apache.hedwig.server.TestPubSubServerStartup.java

License:Apache License

private void instantiateAndDestroyPubSubServer()
        throws IOException, InterruptedException, ConfigurationException, MalformedURLException, Exception {
    int zkPort = PortManager.nextFreePort();
    int hwPort = PortManager.nextFreePort();
    int hwSSLPort = PortManager.nextFreePort();
    String hedwigParams = "default_server_host=localhost:" + hwPort + "\n" + "zk_host=localhost:" + zkPort
            + "\n" + "server_port=" + hwPort + "\n" + "ssl_server_port=" + hwSSLPort + "\n"
            + "zk_timeout=2000\n";

    File hedwigConfigFile = new File(System.getProperty("java.io.tmpdir") + "/hedwig.cfg");
    writeStringToFile(hedwigParams, hedwigConfigFile);

    ClientBase.setupTestEnv();/*from  ww w  .  ja  v a2s  .  com*/
    File zkTmpDir = FileUtils.createTempDirectory("zookeeper", "test");

    ZooKeeperServer zks = new ZooKeeperServer(zkTmpDir, zkTmpDir, zkPort);

    NIOServerCnxnFactory serverFactory = new NIOServerCnxnFactory();
    serverFactory.configure(new InetSocketAddress(zkPort), 100);
    serverFactory.startup(zks);

    boolean b = ClientBase.waitForServerUp("127.0.0.1:" + zkPort, 5000);
    ServerConfiguration serverConf = new ServerConfiguration();
    serverConf.loadConf(hedwigConfigFile.toURI().toURL());

    logger.info("Zookeeper server up and running!");

    ZooKeeper zkc = new ZooKeeper("127.0.0.1:" + zkPort, 5000, null);

    // initialize the zk client with (fake) values
    zkc.create("/ledgers", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zkc.create("/ledgers/available", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

    zkc.close();
    PubSubServer hedwigServer = null;
    try {
        logger.info("starting hedwig broker!");
        hedwigServer = new PubSubServer(serverConf, new ClientConfiguration(), new LoggingExceptionHandler());
        hedwigServer.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
    Assert.assertNotNull("failed to instantiate hedwig pub sub server", hedwigServer);

    hedwigServer.shutdown();
    serverFactory.shutdown();

    zks.shutdown();

    zkTmpDir.delete();

    ClientBase.waitForServerDown("localhost:" + zkPort, 10000);

}