public ZooKeeperServerFactory(QuorumPeerConfig config) throws IOException, InterruptedException {
LOGGER.info("Creating zookeeper server with: {}", config);
ServerConfig serverConfig = getServerConfig(config);
ZooKeeperServer zkServer = new ZooKeeperServer();
FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(serverConfig.getDataLogDir()), new File(serverConfig.getDataDir()));
zkServer.setTxnLogFactory(ftxn);
zkServer.setTickTime(serverConfig.getTickTime());
zkServer.setMinSessionTimeout(serverConfig.getMinSessionTimeout());
zkServer.setMaxSessionTimeout(serverConfig.getMaxSessionTimeout());
NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory() {
protected void configureSaslLogin() throws IOException {
}
};
InetSocketAddress clientPortAddress = serverConfig.getClientPortAddress();
cnxnFactory.configure(clientPortAddress, serverConfig.getMaxClientCnxns());
updateZooKeeperURL(cnxnFactory.getLocalAddress(), cnxnFactory.getLocalPort());
try {
LOGGER.debug("Starting ZooKeeper server on address %s", serverConfig.getClientPortAddress());
cnxnFactory.startup(zkServer);
LOGGER.debug("Started ZooKeeper server");
} catch (Exception e) {
LOGGER.warn(String.format("Failed to start ZooKeeper server, reason : %s", e));
cnxnFactory.shutdown();
throw e;
}
}