Java Code Examples for org.apache.zookeeper.server.ZooKeeperServer#setMaxSessionTimeout()

The following examples show how to use org.apache.zookeeper.server.ZooKeeperServer#setMaxSessionTimeout() . 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: 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 2
Source File: MiniAvatarCluster.java    From RDFS with Apache License 2.0 6 votes vote down vote up
public static void createAndStartZooKeeper() 
  throws IOException, ConfigException, InterruptedException {
  ServerConfig zkConf = createZooKeeperConf();

  zooKeeper = new ZooKeeperServer();
  FileTxnSnapLog ftxn = new 
    FileTxnSnapLog(new File(zkConf.getDataLogDir()),
                   new File(zkConf.getDataDir()));
  zooKeeper.setTxnLogFactory(ftxn);
  zooKeeper.setTickTime(zkConf.getTickTime());
  zooKeeper.setMinSessionTimeout(zkConf.getMinSessionTimeout());
  zooKeeper.setMaxSessionTimeout(zkConf.getMaxSessionTimeout());

  cnxnFactory =
    new NIOServerCnxn.Factory(zkConf.getClientPortAddress(),
                              zkConf.getMaxClientCnxns());
  cnxnFactory.startup(zooKeeper);

}
 
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: LocalZKServer.java    From oryx with Apache License 2.0 4 votes vote down vote up
/**
 * Starts Zookeeper.
 *
 * @throws IOException if an error occurs during initialization
 * @throws InterruptedException if an error occurs during initialization
 */
public synchronized void start() throws IOException, InterruptedException {
  log.info("Starting Zookeeper on port {}", port);

  dataDir = Files.createTempDirectory(LocalZKServer.class.getSimpleName());
  dataDir.toFile().deleteOnExit();

  QuorumPeerConfig quorumConfig = new QuorumPeerConfig();
  try {
    quorumConfig.parseProperties(ConfigUtils.keyValueToProperties(
        "dataDir", dataDir.toAbsolutePath(),
        "clientPort", port
    ));
  } catch (QuorumPeerConfig.ConfigException e) {
    throw new IllegalArgumentException(e);
  }

  purgeManager =
      new DatadirCleanupManager(quorumConfig.getDataDir(),
                                quorumConfig.getDataLogDir(),
                                quorumConfig.getSnapRetainCount(),
                                quorumConfig.getPurgeInterval());
  purgeManager.start();

  ServerConfig serverConfig = new ServerConfig();
  serverConfig.readFrom(quorumConfig);

  zkServer = new ZooKeeperServer();
  zkServer.setTickTime(serverConfig.getTickTime());
  zkServer.setMinSessionTimeout(serverConfig.getMinSessionTimeout());
  zkServer.setMaxSessionTimeout(serverConfig.getMaxSessionTimeout());

  // These two ServerConfig methods returned String in 3.4.x and File in 3.5.x
  transactionLog = new FileTxnSnapLog(new File(serverConfig.getDataLogDir().toString()),
                                      new File(serverConfig.getDataDir().toString()));
  zkServer.setTxnLogFactory(transactionLog);

  connectionFactory = ServerCnxnFactory.createFactory();
  connectionFactory.configure(serverConfig.getClientPortAddress(), serverConfig.getMaxClientCnxns());
  connectionFactory.startup(zkServer);
}