Java Code Examples for org.apache.zookeeper.server.NIOServerCnxnFactory#createFactory()
The following examples show how to use
org.apache.zookeeper.server.NIOServerCnxnFactory#createFactory() .
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: EmbeddedZookeeper.java From logback-kafka-appender with Apache License 2.0 | 6 votes |
public void startup() throws IOException{ if (this.port == -1) { this.port = TestUtils.getAvailablePort(); } this.factory = NIOServerCnxnFactory.createFactory(new InetSocketAddress("localhost", port), 1024); this.snapshotDir = TestUtils.constructTempDir("embeeded-zk/snapshot"); this.logDir = TestUtils.constructTempDir("embeeded-zk/log"); final ZooKeeperServer zooKeeperServer = new ZooKeeperServer(snapshotDir, logDir, tickTime); try { factory.startup(zooKeeperServer); } catch (InterruptedException e) { throw new IOException(e); } assertEquals("standalone", zooKeeperServer.getState()); assertEquals(this.port, zooKeeperServer.getClientPort()); }
Example 2
Source File: EmbeddedZk.java From mercury with Apache License 2.0 | 5 votes |
@Override public void run() { Utility util = Utility.getInstance(); AppConfigReader reader = AppConfigReader.getInstance(); String zkDir = reader.getProperty("zk.dir", "/tmp/zk"); int tickTime = util.str2int(reader.getProperty("zk.tick", "2000")); if (tickTime < 1000) { log.info("zk.tick is too small. Reset to 1000 ms"); tickTime = 1000; } File baseDir = new File(zkDir); if (baseDir.exists()) { // this guarantees that a standalone zookeeper will start with a clean state util.cleanupDir(baseDir); log.info("Clean up transient Zookeeper working directory at {}", baseDir); } File snapshotDir = new File(baseDir, "snapshots"); File logDir = new File(baseDir, "log"); try { this.factory = NIOServerCnxnFactory.createFactory(2181, 512); factory.startup(new ZooKeeperServer(snapshotDir, logDir, tickTime)); } catch (IOException | InterruptedException e) { log.error("Unable to start Zookeeper - {}", e.getMessage()); System.exit(-1); } }
Example 3
Source File: EmbeddedKafkaCluster.java From beam with Apache License 2.0 | 5 votes |
public void startup() throws IOException { if (this.port == -1) { this.port = TestUtils.getAvailablePort(); } this.factory = NIOServerCnxnFactory.createFactory(new InetSocketAddress("127.0.0.1", port), 1024); this.snapshotDir = TestUtils.constructTempDir("embedded-zk/snapshot"); this.logDir = TestUtils.constructTempDir("embedded-zk/log"); try { factory.startup(new ZooKeeperServer(snapshotDir, logDir, tickTime)); } catch (InterruptedException e) { throw new IOException(e); } }
Example 4
Source File: KafkaNotification.java From incubator-atlas with Apache License 2.0 | 5 votes |
private String startZk() throws IOException, InterruptedException, URISyntaxException { String zkValue = properties.getProperty("zookeeper.connect"); LOG.debug("Starting zookeeper at {}", zkValue); URL zkAddress = getURL(zkValue); this.factory = NIOServerCnxnFactory.createFactory( new InetSocketAddress(zkAddress.getHost(), zkAddress.getPort()), 1024); File snapshotDir = constructDir("zk/txn"); File logDir = constructDir("zk/snap"); factory.startup(new ZooKeeperServer(snapshotDir, logDir, 500)); return factory.getLocalAddress().getAddress().toString(); }
Example 5
Source File: EmbeddedKafkaServer.java From atlas with Apache License 2.0 | 4 votes |
private String startZk() throws IOException, InterruptedException, URISyntaxException { String zkValue = properties.getProperty("zookeeper.connect"); LOG.info("Starting zookeeper at {}", zkValue); URL zkAddress = getURL(zkValue); File snapshotDir = constructDir("zk/txn"); File logDir = constructDir("zk/snap"); factory = NIOServerCnxnFactory.createFactory(new InetSocketAddress(zkAddress.getHost(), zkAddress.getPort()), 1024); factory.startup(new ZooKeeperServer(snapshotDir, logDir, 500)); String ret = factory.getLocalAddress().getAddress().toString(); LOG.info("Embedded zookeeper for Kafka started at {}", ret); return ret; }
Example 6
Source File: EmbeddedZookeeper.java From brooklin with BSD 2-Clause "Simplified" License | 4 votes |
/** * Construct an EmbeddedZookeeper * @param port the port to bind to * @param tickTime ZooKeeper tick time, used to regulate heartbeats and timeouts */ public EmbeddedZookeeper(int port, int tickTime) throws IOException { this._factory = NIOServerCnxnFactory.createFactory(port, 1024); this._port = _factory.getLocalPort(); this._tickTime = tickTime; }