Java Code Examples for org.apache.zookeeper.server.NIOServerCnxnFactory#startup()
The following examples show how to use
org.apache.zookeeper.server.NIOServerCnxnFactory#startup() .
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: CCEmbeddedZookeeper.java From cruise-control with BSD 2-Clause "Simplified" License | 6 votes |
public CCEmbeddedZookeeper() { int tickTime = 500; try { File snapshotDir = CCKafkaTestUtils.newTempDir(); File logDir = CCKafkaTestUtils.newTempDir(); _zk = new ZooKeeperServer(snapshotDir, logDir, tickTime); _cnxnFactory = new NIOServerCnxnFactory(); InetAddress localHost = InetAddress.getLocalHost(); _hostAddress = localHost.getHostAddress(); InetSocketAddress bindAddress = new InetSocketAddress(localHost, 0); _cnxnFactory.configure(bindAddress, 0); _cnxnFactory.startup(_zk); _port = _zk.getClientPort(); } catch (Exception e) { throw new IllegalStateException(e); } //sanity check if (_zk.getClientPort() != _port) { throw new IllegalStateException(); } }
Example 2
Source File: ZooKeeperTestServer.java From attic-aurora with Apache License 2.0 | 6 votes |
/** * Starts zookeeper up on an ephemeral port. */ public void startNetwork() throws IOException, InterruptedException { zooKeeperServer = new ZooKeeperServer( new FileTxnSnapLog(dataDir, snapDir), new BasicDataTreeBuilder()) { // TODO(John Sirois): Introduce a builder to configure the in-process server if and when // some folks need JMX for in-process tests. @Override protected void registerJMX() { // noop } }; connectionFactory = new NIOServerCnxnFactory(); connectionFactory.configure( new InetSocketAddress(port), 60 /* Semi-arbitrary, max 60 connections is the default used by NIOServerCnxnFactory */); connectionFactory.startup(zooKeeperServer); port = zooKeeperServer.getClientPort(); }
Example 3
Source File: ZKServerFactoryBean.java From wildfly-camel with Apache License 2.0 | 6 votes |
public void afterPropertiesSet() throws Exception { if (purge) { deleteFilesInDir(getDataLogDir()); deleteFilesInDir(getDataDir()); } FileTxnSnapLog ftxn = new FileTxnSnapLog(getDataLogDir(), getDataDir()); zooKeeperServer.setTxnLogFactory(ftxn); zooKeeperServer.setTickTime(getTickTime()); zooKeeperServer.setMinSessionTimeout(getMinSessionTimeout()); zooKeeperServer.setMaxSessionTimeout(getMaxSessionTimeout()); connectionFactory = new NIOServerCnxnFactory() { @Override protected void configureSaslLogin() throws IOException { // do nothing } }; connectionFactory.configure(getClientPortAddress(), getMaxClientConnections()); connectionFactory.startup(zooKeeperServer); }
Example 4
Source File: EmbeddedZooKeeper.java From ameliant-tools with Apache License 2.0 | 6 votes |
@Override protected void before() throws Throwable { snapshotDir = tempDir(perTest("zk-snapshot")); logDir = tempDir(perTest("zk-log")); log.info("Setting up ZK Server with snapshotDir:{}, logDir:{}", snapshotDir, logDir); int tickTime = 500; try { zooKeeperServer = new ZooKeeperServer(snapshotDir, logDir, tickTime); cnxnFactory = new NIOServerCnxnFactory(); cnxnFactory.configure(new InetSocketAddress("127.0.0.1", port), 0); cnxnFactory.startup(zooKeeperServer); } catch (IOException e) { e.printStackTrace(); } }
Example 5
Source File: ZookeeperServerTest.java From pulsar with Apache License 2.0 | 6 votes |
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 6
Source File: ZooKeeperTestServer.java From vespa with Apache License 2.0 | 6 votes |
private ZooKeeperTestServer(int port) throws IOException { zooKeeperDir = getTempDir(); delete(zooKeeperDir); if (!zooKeeperDir.mkdir()) { throw new IllegalStateException("Failed to create directory " + zooKeeperDir); } zooKeeperDir.deleteOnExit(); server = new ZooKeeperServer(zooKeeperDir, zooKeeperDir, (int)tickTime.toMillis()); final int maxcc = 10000; // max number of connections from the same client factory = new NIOServerCnxnFactory(); factory.configure(new InetSocketAddress(port), maxcc); // Use any port try{ factory.startup(server); } catch (InterruptedException e) { throw (RuntimeException) new IllegalStateException("Interrupted during test startup: ").initCause(e); } }
Example 7
Source File: TestBookKeeperConfiguration.java From big-c with Apache License 2.0 | 6 votes |
@BeforeClass public static void setupZooKeeper() throws Exception { // create a ZooKeeper server(dataDir, dataLogDir, port) LOG.info("Starting ZK server"); ZkTmpDir = File.createTempFile("zookeeper", "test"); ZkTmpDir.delete(); ZkTmpDir.mkdir(); try { zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperDefaultPort); serverFactory = new NIOServerCnxnFactory(); serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), 10); serverFactory.startup(zks); } catch (Exception e) { LOG.error("Exception while instantiating ZooKeeper", e); } boolean b = LocalBookKeeper.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT); LOG.debug("ZooKeeper server up: " + b); }
Example 8
Source File: TestCurrentInprogress.java From big-c with Apache License 2.0 | 6 votes |
@BeforeClass public static void setupZooKeeper() throws Exception { LOG.info("Starting ZK server"); zkTmpDir = File.createTempFile("zookeeper", "test"); zkTmpDir.delete(); zkTmpDir.mkdir(); try { zks = new ZooKeeperServer(zkTmpDir, zkTmpDir, ZooKeeperDefaultPort); serverFactory = new NIOServerCnxnFactory(); serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), 10); serverFactory.startup(zks); } catch (Exception e) { LOG.error("Exception while instantiating ZooKeeper", e); } boolean b = LocalBookKeeper.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT); LOG.debug("ZooKeeper server up: " + b); }
Example 9
Source File: EmbeddedZookeeper.java From li-apache-kafka-clients with BSD 2-Clause "Simplified" License | 6 votes |
public EmbeddedZookeeper() { try { snapshotDir = KafkaTestUtils.newTempDir(); logDir = KafkaTestUtils.newTempDir(); tickTime = 500; zk = new ZooKeeperServer(snapshotDir, logDir, tickTime); registerShutdownHandler(zk); cnxnFactory = new NIOServerCnxnFactory(); InetAddress localHost = InetAddress.getLocalHost(); hostAddress = localHost.getHostAddress(); InetSocketAddress bindAddress = new InetSocketAddress(localHost, port); cnxnFactory.configure(bindAddress, 0); cnxnFactory.startup(zk); port = zk.getClientPort(); } catch (Exception e) { throw new IllegalStateException(e); } //sanity check if (zk.getClientPort() != port) { throw new IllegalStateException(); } }
Example 10
Source File: TestCurrentInprogress.java From hadoop with Apache License 2.0 | 6 votes |
@BeforeClass public static void setupZooKeeper() throws Exception { LOG.info("Starting ZK server"); zkTmpDir = File.createTempFile("zookeeper", "test"); zkTmpDir.delete(); zkTmpDir.mkdir(); try { zks = new ZooKeeperServer(zkTmpDir, zkTmpDir, ZooKeeperDefaultPort); serverFactory = new NIOServerCnxnFactory(); serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), 10); serverFactory.startup(zks); } catch (Exception e) { LOG.error("Exception while instantiating ZooKeeper", e); } boolean b = LocalBookKeeper.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT); LOG.debug("ZooKeeper server up: " + b); }
Example 11
Source File: ZookeeperTestService.java From hudi with Apache License 2.0 | 5 votes |
public ZooKeeperServer start() throws IOException, InterruptedException { Objects.requireNonNull(workDir, "The localBaseFsLocation must be set before starting cluster."); setupTestEnv(); stop(); File dir = new File(workDir, "zookeeper").getAbsoluteFile(); recreateDir(dir, clean); int tickTimeToUse; if (this.tickTime > 0) { tickTimeToUse = this.tickTime; } else { tickTimeToUse = TICK_TIME; } this.zooKeeperServer = new ZooKeeperServer(dir, dir, tickTimeToUse); standaloneServerFactory = new NIOServerCnxnFactory(); // NOTE: Changed from the original, where InetSocketAddress was // originally created to bind to the wildcard IP, we now configure it. LOG.info("Zookeeper force binding to: " + this.bindIP); standaloneServerFactory.configure(new InetSocketAddress(bindIP, clientPort), 1000); // Start up this ZK server standaloneServerFactory.startup(zooKeeperServer); String serverHostname; if (bindIP.equals("0.0.0.0")) { serverHostname = "localhost"; } else { serverHostname = bindIP; } if (!waitForServerUp(serverHostname, clientPort, CONNECTION_TIMEOUT)) { throw new IOException("Waiting for startup of standalone server"); } started = true; LOG.info("Zookeeper Minicluster service started on client port: " + clientPort); return zooKeeperServer; }
Example 12
Source File: ZookeeperTestServer.java From blueflood with Apache License 2.0 | 5 votes |
public void connect() throws IOException, InterruptedException { zkServer = new ZooKeeperServer(new FileTxnSnapLog(dataDir, logDir), new ZooKeeperServer.BasicDataTreeBuilder()); connectionFactory = new NIOServerCnxnFactory(); connectionFactory.configure(new InetSocketAddress(port), 10); connectionFactory.startup(zkServer); port = zkServer.getClientPort(); }
Example 13
Source File: LocalBookkeeperEnsemble.java From pulsar with Apache License 2.0 | 5 votes |
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 14
Source File: ZooKeeperUtil.java From pulsar with Apache License 2.0 | 5 votes |
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); }
Example 15
Source File: KafkaEmbeddedRule.java From devicehive-java-server with Apache License 2.0 | 5 votes |
public EmbeddedZookeeperInternal(int port) throws IOException, InterruptedException { this.port = port; logDir = TestUtils.tempDir(); snapshotDir = TestUtils.tempDir(); zooKeeperServer = new ZooKeeperServer(snapshotDir, logDir, 500); nioServerCnxnFactory = new NIOServerCnxnFactory(); InetSocketAddress inetSocketAddress = new InetSocketAddress("127.0.0.1", port); nioServerCnxnFactory.configure(inetSocketAddress, 0); nioServerCnxnFactory.startup(zooKeeperServer); }
Example 16
Source File: ZookeeperServer.java From ingestion with Apache License 2.0 | 5 votes |
/** * Set embedded zookeeper up and spawn it in a new thread. * * @throws TTransportException * @throws IOException * @throws InterruptedException */ public void start() throws Exception { File dir = Files.createTempDir(); String dirPath = dir.getAbsolutePath(); System.out.println("Storing ZooKeeper files in " + dirPath); ZooKeeperServer server = new ZooKeeperServer(dir, dir, TICK_TIME); standaloneServerFactory = new NIOServerCnxnFactory(); standaloneServerFactory.configure(new InetSocketAddress(CLIENT_PORT), NUM_CONNECTIONS); standaloneServerFactory.startup(server); // start the server. TimeUnit.SECONDS.sleep(WAIT_SECONDS); }
Example 17
Source File: EmbeddedZkServer.java From incubator-sentry with Apache License 2.0 | 5 votes |
public EmbeddedZkServer(int port) throws Exception { snapshotDir = Files.createTempDirectory("zookeeper-snapshot-"); logDir = Files.createTempDirectory("zookeeper-log-"); int tickTime = 500; zookeeper = new ZooKeeperServer(snapshotDir.toFile(), logDir.toFile(), tickTime); factory = new NIOServerCnxnFactory(); InetSocketAddress addr = new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(), port); LOGGER.info("Starting Zookeeper at " + addr); factory.configure(addr, 0); factory.startup(zookeeper); }
Example 18
Source File: ZookeeperServer.java From camel-spring-boot with Apache License 2.0 | 5 votes |
public ZookeeperServer(File root) throws IOException, InterruptedException { zkServer = new ZooKeeperServer(); File dataDir = new File(root, "log"); File snapDir = new File(root, "data"); FileTxnSnapLog ftxn = new FileTxnSnapLog(dataDir, snapDir); zkServer.setTxnLogFactory(ftxn); zkServer.setTickTime(1000); connectionFactory = new NIOServerCnxnFactory(); connectionFactory.configure(new InetSocketAddress("localhost", SocketUtils.findAvailableTcpPort()), 0); connectionFactory.startup(zkServer); }
Example 19
Source File: EmbeddedZooKeeper.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
private void start(InetSocketAddress addr) throws IOException, InterruptedException { factory = new NIOServerCnxnFactory(); factory.configure(addr, 20); factory.startup(zk); }
Example 20
Source File: ZookeeperService.java From kite with Apache License 2.0 | 4 votes |
@Override public void start() throws IOException, InterruptedException { Preconditions.checkState(workDir != null, "The localBaseFsLocation must be set before starting cluster."); setupTestEnv(); stop(); File dir = new File(workDir, "zookeeper").getAbsoluteFile(); recreateDir(dir, clean); int tickTimeToUse; if (this.tickTime > 0) { tickTimeToUse = this.tickTime; } else { tickTimeToUse = TICK_TIME; } this.zooKeeperServer = new ZooKeeperServer(dir, dir, tickTimeToUse); standaloneServerFactory = new NIOServerCnxnFactory(); // NOTE: Changed from the original, where InetSocketAddress was // originally created to bind to the wildcard IP, we now configure it. logger.info("Zookeeper force binding to: " + this.bindIP); standaloneServerFactory.configure( new InetSocketAddress(bindIP, clientPort), 1000); // Start up this ZK server standaloneServerFactory.startup(zooKeeperServer); String serverHostname; if (bindIP.equals("0.0.0.0")) { serverHostname = "localhost"; } else { serverHostname = bindIP; } if (!waitForServerUp(serverHostname, clientPort, CONNECTION_TIMEOUT)) { throw new IOException("Waiting for startup of standalone server"); } started = true; logger.info("Zookeeper Minicluster service started on client port: " + clientPort); }