本文整理汇总了Java中org.apache.zookeeper.server.NIOServerCnxnFactory.configure方法的典型用法代码示例。如果您正苦于以下问题:Java NIOServerCnxnFactory.configure方法的具体用法?Java NIOServerCnxnFactory.configure怎么用?Java NIOServerCnxnFactory.configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.zookeeper.server.NIOServerCnxnFactory
的用法示例。
在下文中一共展示了NIOServerCnxnFactory.configure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupZooKeeper
import org.apache.zookeeper.server.NIOServerCnxnFactory; //导入方法依赖的package包/类
@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);
}
示例2: setupZooKeeper
import org.apache.zookeeper.server.NIOServerCnxnFactory; //导入方法依赖的package包/类
@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);
}
示例3: startNetwork
import org.apache.zookeeper.server.NIOServerCnxnFactory; //导入方法依赖的package包/类
/**
* 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();
}
示例4: EmbeddedZookeeper
import org.apache.zookeeper.server.NIOServerCnxnFactory; //导入方法依赖的package包/类
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();
}
}
示例5: startServer
import org.apache.zookeeper.server.NIOServerCnxnFactory; //导入方法依赖的package包/类
public void startServer() throws Exception {
// create a ZooKeeper server(dataDir, dataLogDir, port)
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);
boolean b = ClientBase.waitForServerUp(getZooKeeperConnectString(), ClientBase.CONNECTION_TIMEOUT);
LOG.debug("Server up: " + b);
// create a zookeeper client
LOG.debug("Instantiate ZK Client");
ZooKeeperWatcherBase w = new ZooKeeperWatcherBase(10000);
zkc = ZkUtils.createConnectedZookeeperClient(getZooKeeperConnectString(), w);
// initialize the zk client with values
zkc.create("/ledgers", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zkc.create("/ledgers/available", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
示例6: ZooKeeperTestServer
import org.apache.zookeeper.server.NIOServerCnxnFactory; //导入方法依赖的package包/类
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, tickTime);
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);
}
}
示例7: TestZookeeperServer
import org.apache.zookeeper.server.NIOServerCnxnFactory; //导入方法依赖的package包/类
public TestZookeeperServer(int clientPort, boolean clearServerData) throws Exception {
// TODO This is necessary as zookeeper does not delete the log dir when it shuts down. Remove as soon as zookeeper shutdown works
zookeeperBaseDir = new File("./target/zookeeper" + count++);
if (clearServerData) {
cleanZookeeperDir();
}
zkServer = new ZooKeeperServer();
File dataDir = new File(zookeeperBaseDir, "log");
File snapDir = new File(zookeeperBaseDir, "data");
FileTxnSnapLog ftxn = new FileTxnSnapLog(dataDir, snapDir);
zkServer.setTxnLogFactory(ftxn);
zkServer.setTickTime(1000);
connectionFactory = new NIOServerCnxnFactory();
connectionFactory.configure(new InetSocketAddress("localhost", clientPort), 0);
connectionFactory.startup(zkServer);
}
示例8: createAndStartZooKeeper
import org.apache.zookeeper.server.NIOServerCnxnFactory; //导入方法依赖的package包/类
public static void createAndStartZooKeeper()
throws IOException, ConfigException, InterruptedException {
logStateChange("Creating zookeeper server");
AvatarShell.retrySleep = 1000;
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 NIOServerCnxnFactory();
cnxnFactory.configure(zkConf.getClientPortAddress(),
zkConf.getMaxClientCnxns());
cnxnFactory.startup(zooKeeper);
logStateChange("Creating zookeeper server - completed");
}
示例9: before
import org.apache.zookeeper.server.NIOServerCnxnFactory; //导入方法依赖的package包/类
@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();
}
}
示例10: afterPropertiesSet
import org.apache.zookeeper.server.NIOServerCnxnFactory; //导入方法依赖的package包/类
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);
}
示例11: EmbeddedZookeeper
import org.apache.zookeeper.server.NIOServerCnxnFactory; //导入方法依赖的package包/类
public EmbeddedZookeeper(int port, Path baseDir) throws Exception {
this.port = port;
zookeeperBaseDir = baseDir;
zkServer = new ZooKeeperServer();
File dataDir = zookeeperBaseDir.resolve("log").toFile();
File snapDir = zookeeperBaseDir.resolve("data").toFile();
FileTxnSnapLog ftxn = new FileTxnSnapLog(dataDir, snapDir);
zkServer.setTxnLogFactory(ftxn);
zkServer.setTickTime(1000);
connectionFactory = new NIOServerCnxnFactory() {
@Override
protected void configureSaslLogin() throws IOException {
// do nothing
}
};
connectionFactory.configure(new InetSocketAddress("localhost", port), 0);
}
示例12: testFileDescriptorLeak
import org.apache.zookeeper.server.NIOServerCnxnFactory; //导入方法依赖的package包/类
@Test
public void testFileDescriptorLeak() throws Exception {
OSMXBean osMbean = new OSMXBean();
if (osMbean.getUnix() != true) {
LOG.info("Unable to run test on non-unix system");
return;
}
long startFdCount = osMbean.getOpenFileDescriptorCount();
LOG.info("Start fdcount is: " + startFdCount);
for (int i = 0; i < 50; ++i) {
NIOServerCnxnFactory factory = new NIOServerCnxnFactory();
factory.configure(
new InetSocketAddress(
"127.0.0.1", PortAssignment.unique()), 10);
factory.start();
Thread.sleep(100);
factory.shutdown();
}
long endFdCount = osMbean.getOpenFileDescriptorCount();
LOG.info("End fdcount is: " + endFdCount);
// On my box, if selector.close() is not called fd diff is > 700.
Assert.assertTrue("Possible fd leakage",
((endFdCount - startFdCount) < 50));
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:30,代码来源:NIOConnectionFactoryFdLeakTest.java
示例13: start
import org.apache.zookeeper.server.NIOServerCnxnFactory; //导入方法依赖的package包/类
public void start() throws IOException {
try {
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);
}
LocalBookkeeperEnsemble.waitForServerUp(hostPort, 30000);
log.info("ZooKeeper started at {}", hostPort);
}
示例14: runZookeeper
import org.apache.zookeeper.server.NIOServerCnxnFactory; //导入方法依赖的package包/类
/**
* @param args
*/
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 {
zks = new ZooKeeperServer(zkDataDir, zkDataDir, ZooKeeperServer.DEFAULT_TICK_TIME);
serverFactory = new NIOServerCnxnFactory();
serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), maxCC);
serverFactory.startup(zks);
} catch (Exception e) {
// TODO Auto-generated catch block
LOG.error("Exception while instantiating ZooKeeper", e);
}
boolean b = waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT);
LOG.info("ZooKeeper server up: {}", b);
LOG.debug("Local ZK started (port: {}, data_directory: {})", ZooKeeperDefaultPort, zkDataDir.getAbsolutePath());
}
示例15: setUp
import org.apache.zookeeper.server.NIOServerCnxnFactory; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
zkDir = Files.createTempDir().getAbsoluteFile();
zkPort = Utils.getFreePorts(1)[0];
ZooKeeperServer zkServer = new ZooKeeperServer(zkDir, zkDir, 2000);
standaloneServerFactory = new NIOServerCnxnFactory();
standaloneServerFactory.configure(new InetSocketAddress(zkPort.value), 5000);
standaloneServerFactory.startup(zkServer);
}