@Override
  public void start() throws Exception {
    ServerConfig config = new ServerConfig();
    config.parse(new String[] {"2181", "zk"});

    zkServer = new ZooKeeperServer();
    zkServer.setTxnLogFactory(
        new FileTxnSnapLog(new File(config.getDataLogDir()), new File(config.getDataDir())));
    zkServer.setTickTime(config.getTickTime());
    zkServer.setMinSessionTimeout(config.getMinSessionTimeout());
    zkServer.setMaxSessionTimeout(config.getMaxSessionTimeout());
    cnxnFactory = ServerCnxnFactory.createFactory();
    cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns());
    cnxnFactory.startup(zkServer);
  }
示例#2
0
  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);
  }