Java Code Examples for org.apache.zookeeper.server.ZooKeeperServer#DEFAULT_TICK_TIME

The following examples show how to use org.apache.zookeeper.server.ZooKeeperServer#DEFAULT_TICK_TIME . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZooKeeperServiceRunner.java    From pravega with Apache License 2.0 6 votes vote down vote up
/**
 * Starts the ZooKeeper Service in process.
 *
 * @throws Exception If an exception occurred.
 */
public void start() throws Exception {
    Preconditions.checkState(this.tmpDir.get() != null, "Not Initialized.");
    val s = new ZooKeeperServer(this.tmpDir.get(), this.tmpDir.get(), ZooKeeperServer.DEFAULT_TICK_TIME);
    if (!this.server.compareAndSet(null, s)) {
        s.shutdown();
        throw new IllegalStateException("Already started.");
    }
    this.serverFactory.set(NettyServerCnxnFactory.createFactory());
    val address = LOOPBACK_ADDRESS + ":" + this.zkPort;
    log.info("Starting Zookeeper server at " + address + " ...");
    this.serverFactory.get().configure(new InetSocketAddress(LOOPBACK_ADDRESS, this.zkPort), 1000, secureZK);
    this.serverFactory.get().startup(s);

    if (!waitForServerUp(this.zkPort, this.secureZK, this.keyStore, this.keyStorePasswordPath, this.trustStore,
            this.keyStorePasswordPath)) {
        throw new IllegalStateException("ZooKeeper server failed to start");
    }
}
 
Example 2
Source File: ZookeeperServerTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
public void start() throws IOException {
    try {
        // Allow all commands on ZK control port
        System.setProperty("zookeeper.4lw.commands.whitelist", "*");
        // disable the admin server as to not have any port conflicts
        System.setProperty("zookeeper.admin.enableServer", "false");
        zks = new ZooKeeperServer(zkTmpDir, zkTmpDir, ZooKeeperServer.DEFAULT_TICK_TIME);
        zks.setMaxSessionTimeout(20000);
        serverFactory = new NIOServerCnxnFactory();
        serverFactory.configure(new InetSocketAddress(zkPort), 1000);
        serverFactory.startup(zks);
    } catch (Exception e) {
        log.error("Exception while instantiating ZooKeeper", e);
    }

    this.zkPort = serverFactory.getLocalPort();
    this.hostPort = "127.0.0.1:" + zkPort;

    LocalBookkeeperEnsemble.waitForServerUp(hostPort, 30000);
    log.info("ZooKeeper started at {}", hostPort);
}
 
Example 3
Source File: ZooKeeperClientAspectJTest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
public void start() throws IOException {
    try {
        zks = new ZooKeeperServer(zkTmpDir, zkTmpDir, ZooKeeperServer.DEFAULT_TICK_TIME);
        zks.setMaxSessionTimeout(20000);
        serverFactory = new NIOServerCnxnFactory();
        serverFactory.configure(new InetSocketAddress(zkPort), 1000);
        serverFactory.startup(zks);
    } catch (Exception e) {
        log.error("Exception while instantiating ZooKeeper", e);
    }

    LocalBookkeeperEnsemble.waitForServerUp(hostPort, 30000);
    log.info("ZooKeeper started at {}", hostPort);
}
 
Example 4
Source File: LocalBookkeeperEnsemble.java    From pulsar with Apache License 2.0 5 votes vote down vote up
private void runZookeeper(int maxCC) throws IOException {
    // create a ZooKeeper server(dataDir, dataLogDir, port)
    LOG.info("Starting ZK server");
    // ServerStats.registerAsConcrete();
    // ClientBase.setupTestEnv();

    File zkDataDir = isNotBlank(zkDataDirName) ? Files.createDirectories(Paths.get(zkDataDirName)).toFile()
            : Files.createTempDirectory("zktest").toFile();

    if (this.clearOldData) {
        cleanDirectory(zkDataDir);
    }

    try {
        // Allow all commands on ZK control port
        System.setProperty("zookeeper.4lw.commands.whitelist", "*");
        zks = new ZooKeeperServer(zkDataDir, zkDataDir, ZooKeeperServer.DEFAULT_TICK_TIME);

        serverFactory = new NIOServerCnxnFactory();
        serverFactory.configure(new InetSocketAddress(zkPort), maxCC);
        serverFactory.startup(zks);
    } catch (Exception e) {
        LOG.error("Exception while instantiating ZooKeeper", e);

        if (serverFactory != null) {
            serverFactory.shutdown();
        }
        throw new IOException(e);
    }

    this.zkPort = serverFactory.getLocalPort();
    this.HOSTPORT = "127.0.0.1:" + zkPort;

    boolean b = waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT);

    LOG.info("ZooKeeper server up: {}", b);
    LOG.debug("Local ZK started (port: {}, data_directory: {})", zkPort, zkDataDir.getAbsolutePath());
}
 
Example 5
Source File: ZooKeeperUtil.java    From pulsar with Apache License 2.0 5 votes vote down vote up
public void startServer(String path) throws Exception {
    LOG.debug("Running ZK server");
    // ServerStats.registerAsConcrete();
    ClientBase.setupTestEnv();
    ZkTmpDir = File.createTempFile("zookeeper", "test");
    ZkTmpDir.delete();
    ZkTmpDir.mkdir();

    zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperServer.DEFAULT_TICK_TIME);
    serverFactory = new NIOServerCnxnFactory();
    serverFactory.configure(zkaddr, 100);
    serverFactory.startup(zks);

    zooKeeperPort = serverFactory.getLocalPort();
    connectString = "localhost:" + zooKeeperPort;
    boolean b = ClientBase.waitForServerUp(getZooKeeperConnectString(), ClientBase.CONNECTION_TIMEOUT);
    LOG.debug("Server up: " + b);

    // create a zookeeper client
    LOG.debug("Instantiate ZK Client");
    zkc = ZooKeeperClient.newBuilder().connectString(getZooKeeperConnectString()).build();
    if (path != "") {
        zkc.create(path, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    }
    // initialize the zk client with values
    zkc.create(path + "/ledgers", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zkc.create(path +"/ledgers/available", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}