當前位置: 首頁>>代碼示例>>Java>>正文


Java NIOServerCnxnFactory類代碼示例

本文整理匯總了Java中org.apache.zookeeper.server.NIOServerCnxnFactory的典型用法代碼示例。如果您正苦於以下問題:Java NIOServerCnxnFactory類的具體用法?Java NIOServerCnxnFactory怎麽用?Java NIOServerCnxnFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NIOServerCnxnFactory類屬於org.apache.zookeeper.server包,在下文中一共展示了NIOServerCnxnFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: shutdown

import org.apache.zookeeper.server.NIOServerCnxnFactory; //導入依賴的package包/類
/**
 * @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");
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:29,代碼來源:MiniZooKeeperCluster.java

示例2: killOneBackupZooKeeperServer

import org.apache.zookeeper.server.NIOServerCnxnFactory; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:32,代碼來源:MiniZooKeeperCluster.java

示例3: commandRun

import org.apache.zookeeper.server.NIOServerCnxnFactory; //導入依賴的package包/類
@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);
        }
    }
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:17,代碼來源:DumpCommand.java

示例4: 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);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:TestCurrentInprogress.java

示例5: 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);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:21,代碼來源:TestBookKeeperConfiguration.java

示例6: 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();
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:24,代碼來源:ZooKeeperTestServer.java

示例7: 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();
  }
}
 
開發者ID:linkedin,項目名稱:li-apache-kafka-clients,代碼行數:23,代碼來源:EmbeddedZookeeper.java

示例8: 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);
}
 
開發者ID:apache,項目名稱:incubator-pulsar,代碼行數:27,代碼來源:ZooKeeperUtil.java

示例9: start

import org.apache.zookeeper.server.NIOServerCnxnFactory; //導入依賴的package包/類
/**
 * 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");
    }
}
 
開發者ID:pravega,項目名稱:pravega,代碼行數:24,代碼來源:ZooKeeperServiceRunner.java

示例10: commandRun

import org.apache.zookeeper.server.NIOServerCnxnFactory; //導入依賴的package包/類
@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);
        }
    }
}
 
開發者ID:sereca,項目名稱:SecureKeeper,代碼行數:17,代碼來源:DumpCommand.java

示例11: 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);
    }
}
 
開發者ID:vespa-engine,項目名稱:vespa,代碼行數:18,代碼來源:ZooKeeperTestServer.java

示例12: 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);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:17,代碼來源:ZooKeeperTestSupport.java

示例13: killOneBackupZooKeeperServer

import org.apache.zookeeper.server.NIOServerCnxnFactory; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:fengchen8086,項目名稱:LCIndex-HBase-0.94.16,代碼行數:31,代碼來源:MiniZooKeeperCluster.java

示例14: 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");
}
 
開發者ID:rhli,項目名稱:hadoop-EAR,代碼行數:22,代碼來源:MiniAvatarCluster.java

示例15: startZookeeper

import org.apache.zookeeper.server.NIOServerCnxnFactory; //導入依賴的package包/類
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());
  }
}
 
開發者ID:apache,項目名稱:apex-malhar,代碼行數:23,代碼來源:KafkaOperatorTestBase.java


注:本文中的org.apache.zookeeper.server.NIOServerCnxnFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。