public InetSocketAddress getClientPortAddress() { return config.getClientPortAddress(); }
private void startStandalone() throws IOException { logger.info("Starting Embedded ZooKeeper Server"); final ServerConfig config = new ServerConfig(); config.readFrom(quorumPeerConfig); try { transactionLog = new FileTxnSnapLog(new File(config.getDataLogDir()), new File(config.getDataDir())); embeddedZkServer = new ZooKeeperServer(); embeddedZkServer.setTxnLogFactory(transactionLog); embeddedZkServer.setTickTime(config.getTickTime()); embeddedZkServer.setMinSessionTimeout(config.getMinSessionTimeout()); embeddedZkServer.setMaxSessionTimeout(config.getMaxSessionTimeout()); connectionFactory = ServerCnxnFactory.createFactory(); connectionFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns()); connectionFactory.startup(embeddedZkServer); } catch (InterruptedException e) { Thread.currentThread().interrupt(); logger.warn("Embedded ZooKeeper Server interrupted", e); } catch (final IOException ioe) { throw new IOException("Failed to start embedded ZooKeeper Server", ioe); } catch (final Exception e) { throw new RuntimeException("Failed to start embedded ZooKeeper Server", e); } }
zkServer.setMaxSessionTimeout(config.maxSessionTimeout); cnxnFactory = ServerCnxnFactory.createFactory(); cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns()); cnxnFactory.startup(zkServer);
if (config.getClientPortAddress() != null) { cnxnFactory = ServerCnxnFactory.createFactory(); cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns(), false); cnxnFactory.startup(zkServer);
@Test public void testValidArguments() { String[] args = {"2181", "/data/dir", "60000", "10000"}; serverConfig.parse(args); assertEquals(2181, serverConfig.getClientPortAddress().getPort()); assertTrue(checkEquality("/data/dir", serverConfig.getDataDir())); assertEquals(60000, serverConfig.getTickTime()); assertEquals(10000, serverConfig.getMaxClientCnxns()); }
connectionFactory.configure(serverConfig.getClientPortAddress(), serverConfig.getMaxClientCnxns()); connectionFactory.startup(zkServer);
@Override public void run() { try { ZooKeeperServerMain zs = new ZooKeeperServerMain(); zs.runFromConfig(sc); _logger.info("[Distribution] distribution server started up.... host:" + sc.getClientPortAddress().getHostName() + ";address:" + sc.getClientPortAddress().getAddress().getHostAddress() + ";port:" + sc.getClientPortAddress().getPort()); } catch (Exception e) { _logger.error(e, e); cleanIfStartsError(); } _logger.info("[Distribution] distribution server shutdown...."); } };
initZkConnection(sc.getClientPortAddress().getHostName() + ":" + sc.getClientPortAddress().getPort());
this.connectionFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns()); try { this.connectionFactory.startup(zooKeeperServer);
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; } }
zkServer.setMinSessionTimeout(config.minSessionTimeout); zkServer.setMaxSessionTimeout(config.maxSessionTimeout); cnxnFactory = new NIOServerCnxn.Factory(config.getClientPortAddress(), config.getMaxClientCnxns()); cnxnFactory.startup(zkServer);
connectionFactory.configure(serverConfig.getClientPortAddress(), serverConfig.getMaxClientCnxns()); connectionFactory.startup(zkServer);
connectionFactory.configure(serverConfig.getClientPortAddress(), serverConfig.getMaxClientCnxns()); connectionFactory.startup(zkServer);
null /* this is not used */, new TestZKDatabase(ftxn, limiter)); cnxnFactory = new TestServerCnxnFactory(limiter); cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns()); cnxnFactory.startup(zooKeeperServer);
/** * This method is coming from <code>ZooKeeperServerMain</code> but tweaked to not block and to * have access to <code>_zkServer</code> and <code>_cnxnFactory</code>. */ private void runFromConfig(ServerConfig config) throws IOException { log.info("Starting server"); try { _zkServer = new ZooKeeperServer(); FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(config.getDataLogDir()), new File(config.getDataDir())); _zkServer.setTxnLogFactory(ftxn); _zkServer.setTickTime(config.getTickTime()); _zkServer.setMinSessionTimeout(config.getMinSessionTimeout()); _zkServer.setMaxSessionTimeout(config.getMaxSessionTimeout()); _cnxnFactory = new NIOServerCnxnFactory(); _cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns()); _cnxnFactory.startup(_zkServer); } catch(InterruptedException e) { // warn, but generally this is ok log.warn("Server interrupted", e); } }
public void start() { // See ZooKeeperServerMain.runFromConfig LOG.info("Starting server"); boolean needStartZKServer = true; LogCtl.disable("org.apache.zookeeper.server.ZooKeeperServer"); // ZooKeeperServer logs an error because ZooKeeperServerShutdownHandler not set but that is not an accessible class. try { if (config.getClientPortAddress() != null) { cnxnFactory = ServerCnxnFactory.createFactory(); cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns(), false); cnxnFactory.startup(zkServer); // zkServer has been started. So we don't need to start it again in secureCnxnFactory. needStartZKServer = false; } if (config.getSecureClientPortAddress() != null) { secureCnxnFactory = ServerCnxnFactory.createFactory(); secureCnxnFactory.configure(config.getSecureClientPortAddress(), config.getMaxClientCnxns(), true); secureCnxnFactory.startup(zkServer, needStartZKServer); } if ( needStartZKServer ) zkServer.startup(); } catch (IOException e) { throw new RuntimeIOException(e); } catch (InterruptedException e) { // Note from ZookeeperServerMain: "warn, but generally this is ok" LOG.warn("Server interrupted", e); } finally { LogCtl.setLevel("org.apache.zookeeper.server.ZooKeeperServer", "WARN"); } }
public static ServerCnxnFactory startZookeeper(final String configResource, final String dataDirName) throws IOException, QuorumPeerConfig.ConfigException { ServerConfig sc = new ServerConfig(); sc.parse(pathToResource(configResource)); deleteDir(dataDirName); new File(dataDirName).mkdirs(); FileTxnSnapLog txnLog = null; try { ZooKeeperServer zkServer = new ZooKeeperServer(); txnLog = new FileTxnSnapLog(new File(sc.getDataDir()), new File( sc.getDataDir())); zkServer.setTxnLogFactory(txnLog); zkServer.setTickTime(sc.getTickTime()); zkServer.setMinSessionTimeout(sc.getMinSessionTimeout()); zkServer.setMaxSessionTimeout(sc.getMaxSessionTimeout()); ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory(); cnxnFactory.configure(sc.getClientPortAddress(), sc.getMaxClientCnxns()); cnxnFactory.startup(zkServer); return cnxnFactory; } catch (InterruptedException e) { throw new RuntimeException(e); } finally { if (txnLog != null) { txnLog.close(); } } }
private void runFromConfig(ServerConfig config) throws IOException { zkServer = new ZooKeeperServer(); try { txnLog = new FileTxnSnapLog(new File(config.getDataLogDir()), 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); } catch (InterruptedException e) { if (zkServer.isRunning()) { zkServer.shutdown(); } } }
cnxnFactory.configure(serverConfig.getClientPortAddress(), serverConfig.getMaxClientCnxns());
zkServer.setMaxSessionTimeout(config.getMaxSessionTimeout()); cnxnFactory = ServerCnxnFactory.createFactory(); cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns()); cnxnFactory.startup(zkServer);