Java 类org.apache.zookeeper.server.NIOServerCnxnFactory 实例源码

项目:QDrill    文件:MiniZooKeeperCluster.java   
/**
 * @throws IOException
 */
public void shutdown() throws IOException {
  if (!started) {
    return;
  }
  // shut down all the zk servers
  for (int i = 0; i < standaloneServerFactoryList.size(); i++) {
    NIOServerCnxnFactory standaloneServerFactory =
      standaloneServerFactoryList.get(i);
    int clientPort = clientPortList.get(i);

    standaloneServerFactory.shutdown();
    if (!waitForServerDown(clientPort, CONNECTION_TIMEOUT)) {
      throw new IOException("Waiting for shutdown of standalone server");
    }
  }

  // clear everything
  started = false;
  activeZKServerIndex = 0;
  standaloneServerFactoryList.clear();
  clientPortList.clear();
  zooKeeperServers.clear();

  LOG.info("Shutdown MiniZK cluster with all ZK servers");
}
项目:QDrill    文件:MiniZooKeeperCluster.java   
/**
 * Kill one back up ZK servers
 *
 * @throws IOException
 * @throws InterruptedException
 */
public void killOneBackupZooKeeperServer() throws IOException,
  InterruptedException {
  if (!started || activeZKServerIndex < 0 ||
    standaloneServerFactoryList.size() <= 1) {
    return;
  }

  int backupZKServerIndex = activeZKServerIndex + 1;
  // Shutdown the current active one
  NIOServerCnxnFactory standaloneServerFactory =
    standaloneServerFactoryList.get(backupZKServerIndex);
  int clientPort = clientPortList.get(backupZKServerIndex);

  standaloneServerFactory.shutdown();
  if (!waitForServerDown(clientPort, CONNECTION_TIMEOUT)) {
    throw new IOException("Waiting for shutdown of standalone server");
  }

  // remove this backup zk server
  standaloneServerFactoryList.remove(backupZKServerIndex);
  clientPortList.remove(backupZKServerIndex);
  zooKeeperServers.remove(backupZKServerIndex);
  LOG.info("Kill one backup ZK servers in the cluster " +
    "on client port: " + clientPort);
}
项目:https-github.com-apache-zookeeper    文件:DumpCommand.java   
@Override
public void commandRun() {
    if (!isZKServerRunning()) {
        pw.println(ZK_NOT_SERVING);
    } else {
        pw.println("SessionTracker dump:");
        zkServer.getSessionTracker().dumpSessions(pw);
        pw.println("ephemeral nodes dump:");
        zkServer.dumpEphemerals(pw);
        pw.println("Connections dump:");
        //dumpConnections connection is implemented only in NIOServerCnxnFactory
        if (factory instanceof NIOServerCnxnFactory) {
            ((NIOServerCnxnFactory)factory).dumpConnections(pw);
        }
    }
}
项目:hadoop    文件:TestCurrentInprogress.java   
@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);
}
项目:hadoop    文件:TestBookKeeperConfiguration.java   
@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);
}
项目:dremio-oss    文件:MiniZooKeeperCluster.java   
/**
 * @throws IOException
 */
public void shutdown() throws IOException {
  if (!started) {
    return;
  }
  // shut down all the zk servers
  for (int i = 0; i < standaloneServerFactoryList.size(); i++) {
    NIOServerCnxnFactory standaloneServerFactory =
      standaloneServerFactoryList.get(i);
    int clientPort = clientPortList.get(i);

    standaloneServerFactory.shutdown();
    if (!waitForServerDown(clientPort, CONNECTION_TIMEOUT)) {
      throw new IOException("Waiting for shutdown of standalone server");
    }
  }

  // clear everything
  started = false;
  activeZKServerIndex = 0;
  standaloneServerFactoryList.clear();
  clientPortList.clear();
  zooKeeperServers.clear();

  LOG.info("Shutdown MiniZK cluster with all ZK servers");
}
项目:dremio-oss    文件:MiniZooKeeperCluster.java   
/**
 * Kill one back up ZK servers
 *
 * @throws IOException
 * @throws InterruptedException
 */
public void killOneBackupZooKeeperServer() throws IOException,
  InterruptedException {
  if (!started || activeZKServerIndex < 0 ||
    standaloneServerFactoryList.size() <= 1) {
    return;
  }

  int backupZKServerIndex = activeZKServerIndex + 1;
  // Shutdown the current active one
  NIOServerCnxnFactory standaloneServerFactory =
    standaloneServerFactoryList.get(backupZKServerIndex);
  int clientPort = clientPortList.get(backupZKServerIndex);

  standaloneServerFactory.shutdown();
  if (!waitForServerDown(clientPort, CONNECTION_TIMEOUT)) {
    throw new IOException("Waiting for shutdown of standalone server");
  }

  // remove this backup zk server
  standaloneServerFactoryList.remove(backupZKServerIndex);
  clientPortList.remove(backupZKServerIndex);
  zooKeeperServers.remove(backupZKServerIndex);
  LOG.info("Kill one backup ZK servers in the cluster " +
    "on client port: " + clientPort);
}
项目:aliyun-oss-hadoop-fs    文件:TestCurrentInprogress.java   
@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);
}
项目:aliyun-oss-hadoop-fs    文件:TestBookKeeperConfiguration.java   
@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);
}
项目:Mastering-Mesos    文件:ZooKeeperTestServer.java   
/**
 * 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();
}
项目:li-apache-kafka-clients    文件:EmbeddedZookeeper.java   
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();
  }
}
项目:big-c    文件:TestCurrentInprogress.java   
@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);
}
项目:big-c    文件:TestBookKeeperConfiguration.java   
@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);
}
项目:incubator-pulsar    文件:ZooKeeperUtil.java   
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);
}
项目:pravega    文件:ZooKeeperServiceRunner.java   
/**
 * Starts the ZooKeeper Service in process.
 *
 * @throws Exception If an exception occurred.
 */
public void start() throws Exception {
    Preconditions.checkState(this.tmpDir.get() != null, "Not Initialized.");
    val s = new ZooKeeperServer(this.tmpDir.get(), this.tmpDir.get(), ZooKeeperServer.DEFAULT_TICK_TIME);
    if (!this.server.compareAndSet(null, s)) {
        s.shutdown();
        throw new IllegalStateException("Already started.");
    }

    this.serverFactory.set(new NIOServerCnxnFactory());
    val address = LOOPBACK_ADDRESS.getHostAddress() + ":" + this.zkPort;
    log.info("Starting Zookeeper server at " + address + " ...");
    this.serverFactory.get().configure(new InetSocketAddress(LOOPBACK_ADDRESS, this.zkPort), 1000);
    this.serverFactory.get().startup(s);

    if (!waitForServerUp(this.zkPort)) {
        throw new IllegalStateException("ZooKeeper server failed to start");
    }
}
项目:SecureKeeper    文件:DumpCommand.java   
@Override
public void commandRun() {
    if (zkServer == null) {
        pw.println(ZK_NOT_SERVING);
    } else {
        pw.println("SessionTracker dump:");
        zkServer.getSessionTracker().dumpSessions(pw);
        pw.println("ephemeral nodes dump:");
        zkServer.dumpEphemerals(pw);
        pw.println("Connections dump:");
        //dumpConnections connection is implemented only in NIOServerCnxnFactory
        if (factory instanceof NIOServerCnxnFactory) {
            ((NIOServerCnxnFactory)factory).dumpConnections(pw);
        }
    }
}
项目:SecureKeeper    文件:DumpCommand.java   
@Override
public void commandRun() {
    if (zkServer == null) {
        pw.println(ZK_NOT_SERVING);
    } else {
        pw.println("SessionTracker dump:");
        zkServer.getSessionTracker().dumpSessions(pw);
        pw.println("ephemeral nodes dump:");
        zkServer.dumpEphemerals(pw);
        pw.println("Connections dump:");
        //dumpConnections connection is implemented only in NIOServerCnxnFactory
        if (factory instanceof NIOServerCnxnFactory) {
            ((NIOServerCnxnFactory)factory).dumpConnections(pw);
        }
    }
}
项目:vespa    文件:ZooKeeperTestServer.java   
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);
    }
}
项目:drill    文件:MiniZooKeeperCluster.java   
/**
 * @throws IOException
 */
public void shutdown() throws IOException {
  if (!started) {
    return;
  }
  // shut down all the zk servers
  for (int i = 0; i < standaloneServerFactoryList.size(); i++) {
    NIOServerCnxnFactory standaloneServerFactory =
      standaloneServerFactoryList.get(i);
    int clientPort = clientPortList.get(i);

    standaloneServerFactory.shutdown();
    if (!waitForServerDown(clientPort, CONNECTION_TIMEOUT)) {
      throw new IOException("Waiting for shutdown of standalone server");
    }
  }

  // clear everything
  started = false;
  activeZKServerIndex = 0;
  standaloneServerFactoryList.clear();
  clientPortList.clear();
  zooKeeperServers.clear();

  LOG.info("Shutdown MiniZK cluster with all ZK servers");
}
项目:drill    文件:MiniZooKeeperCluster.java   
/**
 * Kill one back up ZK servers
 *
 * @throws IOException
 * @throws InterruptedException
 */
public void killOneBackupZooKeeperServer() throws IOException,
  InterruptedException {
  if (!started || activeZKServerIndex < 0 ||
    standaloneServerFactoryList.size() <= 1) {
    return;
  }

  int backupZKServerIndex = activeZKServerIndex + 1;
  // Shutdown the current active one
  NIOServerCnxnFactory standaloneServerFactory =
    standaloneServerFactoryList.get(backupZKServerIndex);
  int clientPort = clientPortList.get(backupZKServerIndex);

  standaloneServerFactory.shutdown();
  if (!waitForServerDown(clientPort, CONNECTION_TIMEOUT)) {
    throw new IOException("Waiting for shutdown of standalone server");
  }

  // remove this backup zk server
  standaloneServerFactoryList.remove(backupZKServerIndex);
  clientPortList.remove(backupZKServerIndex);
  zooKeeperServers.remove(backupZKServerIndex);
  LOG.info("Kill one backup ZK servers in the cluster " +
    "on client port: " + clientPort);
}
项目:Camel    文件:ZooKeeperTestSupport.java   
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);
}
项目:LCIndex-HBase-0.94.16    文件:MiniZooKeeperCluster.java   
/**
 * Kill one back up ZK servers
 * @throws IOException
 * @throws InterruptedException
 */
public void killOneBackupZooKeeperServer() throws IOException,
                                      InterruptedException {
  if (!started || activeZKServerIndex < 0 ||
      standaloneServerFactoryList.size() <= 1) {
    return ;
  }

  int backupZKServerIndex = activeZKServerIndex+1;
  // Shutdown the current active one
  NIOServerCnxnFactory standaloneServerFactory =
    standaloneServerFactoryList.get(backupZKServerIndex);
  int clientPort = clientPortList.get(backupZKServerIndex);

  standaloneServerFactory.shutdown();
  if (!waitForServerDown(clientPort, CONNECTION_TIMEOUT)) {
    throw new IOException("Waiting for shutdown of standalone server");
  }

  // remove this backup zk server
  standaloneServerFactoryList.remove(backupZKServerIndex);
  clientPortList.remove(backupZKServerIndex);
  zooKeeperServers.remove(backupZKServerIndex);
  LOG.info("Kill one backup ZK servers in the cluster " +
      "on client port: " + clientPort);
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestCurrentInprogress.java   
@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);
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestBookKeeperConfiguration.java   
@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);
}
项目:hadoop-EAR    文件:MiniAvatarCluster.java   
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");
}
项目:apex-malhar    文件:KafkaOperatorTestBase.java   
public void startZookeeper(final int clusterId)
{

  try {
    //before start, clean the zookeeper files if it exists
    FileUtils.deleteQuietly(new File(baseDir, zkBaseDir));
    int clientPort = TEST_ZOOKEEPER_PORT[clusterId];
    int numConnections = 10;
    int tickTime = 2000;
    File dir = new File(baseDir, zkdir[clusterId]);

    TestZookeeperServer kserver = new TestZookeeperServer(dir, dir, tickTime);
    zkFactory[clusterId] = new NIOServerCnxnFactory();
    zkFactory[clusterId].configure(new InetSocketAddress(clientPort), numConnections);

    zkFactory[clusterId].startup(kserver); // start the zookeeper server.
    Thread.sleep(2000);
    kserver.startup();
  } catch (Exception ex) {
    logger.debug(ex.getLocalizedMessage());
  }
}
项目:apex-malhar    文件:KafkaOperatorTestBase.java   
public static void startZookeeper(final int clusterId)
{
  try {

    int numConnections = 100;
    int tickTime = 2000;
    File dir = new File(baseDir, zkdir[clusterId]);

    zkServer[clusterId] = new TestZookeeperServer(dir, dir, tickTime);
    zkFactory[clusterId] = new NIOServerCnxnFactory();
    zkFactory[clusterId].configure(new InetSocketAddress(TEST_ZOOKEEPER_PORT[clusterId]), numConnections);

    zkFactory[clusterId].startup(zkServer[clusterId]); // start the zookeeper server.
    Thread.sleep(2000);
    //kserver.startup();
  } catch (Exception ex) {
    logger.error(ex.getLocalizedMessage());
  }
}
项目:apex-malhar    文件:KafkaOperatorTestBase.java   
public static void startZookeeper(final int clusterId)
{
  try {

    int numConnections = 100;
    int tickTime = 2000;
    File dir = new File(baseDir, zkdir[clusterId]);

    zkServer[clusterId] = new TestZookeeperServer(dir, dir, tickTime);
    zkFactory[clusterId] = new NIOServerCnxnFactory();
    zkFactory[clusterId].configure(new InetSocketAddress(TEST_ZOOKEEPER_PORT[clusterId]), numConnections);

    zkFactory[clusterId].startup(zkServer[clusterId]); // start the zookeeper server.
    Thread.sleep(2000);
    //kserver.startup();
  } catch (Exception ex) {
    logger.error(ex.getLocalizedMessage());
  }
}
项目:hadoop-plus    文件:TestCurrentInprogress.java   
@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);
}
项目:hadoop-plus    文件:TestBookKeeperConfiguration.java   
@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);
}
项目:ameliant-tools    文件:EmbeddedZooKeeper.java   
@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();
    }
}
项目:search    文件:RevertDefaultThreadHandlerRule.java   
@Override
public Statement apply(Statement s, Description d) {
  return new StatementAdapter(s) {
    @Override
    protected void before() throws Throwable {
      if (!applied.getAndSet(true)) {
        UncaughtExceptionHandler p = Thread.getDefaultUncaughtExceptionHandler();
        try {
          // Try to initialize a zookeeper class that reinitializes default exception handler.
          Class<?> cl = NIOServerCnxnFactory.class;
          // Make sure static initializers have been called.
          Class.forName(cl.getName(), true, cl.getClassLoader());
        } finally {
          if (p == Thread.getDefaultUncaughtExceptionHandler()) {
          //  throw new RuntimeException("Zookeeper no longer resets default thread handler.");
          }
          Thread.setDefaultUncaughtExceptionHandler(p);
        }
      }
    }
  };
}
项目:FlexMap    文件:TestCurrentInprogress.java   
@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);
}
项目:FlexMap    文件:TestBookKeeperConfiguration.java   
@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);
}
项目:IRIndex    文件:MiniZooKeeperCluster.java   
/**
 * Kill one back up ZK servers
 * @throws IOException
 * @throws InterruptedException
 */
public void killOneBackupZooKeeperServer() throws IOException,
                                      InterruptedException {
  if (!started || activeZKServerIndex < 0 ||
      standaloneServerFactoryList.size() <= 1) {
    return ;
  }

  int backupZKServerIndex = activeZKServerIndex+1;
  // Shutdown the current active one
  NIOServerCnxnFactory standaloneServerFactory =
    standaloneServerFactoryList.get(backupZKServerIndex);
  int clientPort = clientPortList.get(backupZKServerIndex);

  standaloneServerFactory.shutdown();
  if (!waitForServerDown(clientPort, CONNECTION_TIMEOUT)) {
    throw new IOException("Waiting for shutdown of standalone server");
  }

  // remove this backup zk server
  standaloneServerFactoryList.remove(backupZKServerIndex);
  clientPortList.remove(backupZKServerIndex);
  zooKeeperServers.remove(backupZKServerIndex);
  LOG.info("Kill one backup ZK servers in the cluster " +
      "on client port: " + clientPort);
}
项目:hbase    文件:MiniZooKeeperCluster.java   
/**
 * Kill one back up ZK servers.
 *
 * @throws IOException if waiting for the shutdown of a server fails
 */
public void killOneBackupZooKeeperServer() throws IOException, InterruptedException {
  if (!started || activeZKServerIndex < 0 || standaloneServerFactoryList.size() <= 1) {
    return ;
  }

  int backupZKServerIndex = activeZKServerIndex+1;
  // Shutdown the current active one
  NIOServerCnxnFactory standaloneServerFactory =
    standaloneServerFactoryList.get(backupZKServerIndex);
  int clientPort = clientPortList.get(backupZKServerIndex);

  standaloneServerFactory.shutdown();
  if (!waitForServerDown(clientPort, connectionTimeout)) {
    throw new IOException("Waiting for shutdown of standalone server");
  }

  zooKeeperServers.get(backupZKServerIndex).getZKDatabase().close();

  // remove this backup zk server
  standaloneServerFactoryList.remove(backupZKServerIndex);
  clientPortList.remove(backupZKServerIndex);
  zooKeeperServers.remove(backupZKServerIndex);
  LOG.info("Kill one backup ZK servers in the cluster " +
      "on client port: " + clientPort);
}
项目:RStore    文件:MiniZooKeeperCluster.java   
/**
 * @throws IOException
 */
public void shutdown() throws IOException {
  if (!started) {
    return;
  }
  // shut down all the zk servers
  for (int i = 0; i < standaloneServerFactoryList.size(); i++) {
    NIOServerCnxnFactory standaloneServerFactory =
      standaloneServerFactoryList.get(i);      
    int clientPort = clientPortList.get(i);

    standaloneServerFactory.shutdown();
    if (!waitForServerDown(clientPort, CONNECTION_TIMEOUT)) {
      throw new IOException("Waiting for shutdown of standalone server");
    }
  }

  // clear everything
  started = false;
  activeZKServerIndex = 0;
  standaloneServerFactoryList.clear();
  clientPortList.clear();
  zooKeeperServers.clear();

  LOG.info("Shutdown MiniZK cluster with all ZK servers");
}
项目:RStore    文件:MiniZooKeeperCluster.java   
/**
 * Kill one back up ZK servers
 * @throws IOException
 * @throws InterruptedException 
 */
public void killOneBackupZooKeeperServer() throws IOException, 
                                      InterruptedException {
  if (!started || activeZKServerIndex < 0 || 
      standaloneServerFactoryList.size() <= 1) {
    return ;
  }

  int backupZKServerIndex = activeZKServerIndex+1;
  // Shutdown the current active one
  NIOServerCnxnFactory standaloneServerFactory =
    standaloneServerFactoryList.get(backupZKServerIndex);
  int clientPort = clientPortList.get(backupZKServerIndex);

  standaloneServerFactory.shutdown();
  if (!waitForServerDown(clientPort, CONNECTION_TIMEOUT)) {
    throw new IOException("Waiting for shutdown of standalone server");
  }

  // remove this backup zk server
  standaloneServerFactoryList.remove(backupZKServerIndex);
  clientPortList.remove(backupZKServerIndex);
  zooKeeperServers.remove(backupZKServerIndex);    
  LOG.info("Kill one backup ZK servers in the cluster " +
      "on client port: " + clientPort);
}
项目:hadoop-TCP    文件:TestCurrentInprogress.java   
@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);
}
项目:hadoop-TCP    文件:TestBookKeeperConfiguration.java   
@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);
}