示例#1
0
 public static void shutDownZooKeeper() throws IOException, InterruptedException {
   cnxnFactory.shutdown();
   cnxnFactory.join();
   if (zooKeeper.isRunning()) {
     zooKeeper.shutdown();
   }
 }
示例#2
0
  @Test
  public void testMinMaxSessionTimeout() throws Exception {
    // override the defaults
    final int MINSESS = 20000;
    final int MAXSESS = 240000;
    ZooKeeperServer zs = serverFactory.getZooKeeperServer();
    zs.setMinSessionTimeout(MINSESS);
    zs.setMaxSessionTimeout(MAXSESS);

    // validate typical case - requested == negotiated
    int timeout = 120000;
    DisconnectableZooKeeper zk = createClient(timeout);
    Assert.assertEquals(timeout, zk.getSessionTimeout());
    // make sure tostring works in both cases
    LOG.info(zk.toString());
    zk.close();
    LOG.info(zk.toString());

    // validate lower limit
    zk = createClient(MINSESS / 2);
    Assert.assertEquals(MINSESS, zk.getSessionTimeout());
    LOG.info(zk.toString());
    zk.close();
    LOG.info(zk.toString());

    // validate upper limit
    zk = createClient(MAXSESS * 2);
    Assert.assertEquals(MAXSESS, zk.getSessionTimeout());
    LOG.info(zk.toString());
    zk.close();
    LOG.info(zk.toString());
  }
 @Override
 public void stop() throws Exception {
   cnxnFactory.shutdown();
   cnxnFactory.join();
   if (zkServer.isRunning()) {
     zkServer.shutdown();
   }
 }
 @Override
 public void run() {
   try {
     zooKeeperServer.startup();
     zooKeeperServer.getServerCnxnFactory().start();
     startContext.complete();
     log.info("Zookeeper started at " + binding.getValue().getSocketAddress());
   } catch (Throwable e) {
     startContext.failed(new StartException(e));
     log.error("Zookeeper failed to start at " + binding.getValue().getSocketAddress());
   }
 }
    @Override
    public void run() {
      try {
        zooKeeperServer.getServerCnxnFactory().closeSession(tickTime);
        zooKeeperServer.getServerCnxnFactory().closeAll();
        zooKeeperServer.getServerCnxnFactory().shutdown();
        zooKeeperServer.shutdown();
      } finally {
        stopContext.complete();
      }

      log.info("Zookeeper stopped");
    }
  @Override
  public void start() throws Exception {
    ServerConfig config = new ServerConfig();
    config.parse(new String[] {"2181", "zk"});

    zkServer = new ZooKeeperServer();
    zkServer.setTxnLogFactory(
        new FileTxnSnapLog(new File(config.getDataLogDir()), new File(config.getDataDir())));
    zkServer.setTickTime(config.getTickTime());
    zkServer.setMinSessionTimeout(config.getMinSessionTimeout());
    zkServer.setMaxSessionTimeout(config.getMaxSessionTimeout());
    cnxnFactory = ServerCnxnFactory.createFactory();
    cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns());
    cnxnFactory.startup(zkServer);
  }
示例#7
0
  public static void createAndStartZooKeeper()
      throws IOException, ConfigException, InterruptedException {
    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 NIOServerCnxn.Factory(zkConf.getClientPortAddress(), zkConf.getMaxClientCnxns());
    cnxnFactory.startup(zooKeeper);
  }
示例#8
0
  static void shutdownServerInstance(ServerCnxnFactory factory, String hostPort) {
    if (factory != null) {
      ZKDatabase zkDb = null;
      {
        ZooKeeperServer zs = getServer(factory);
        if (zs != null) {
          zkDb = zs.getZKDatabase();
        }
      }
      factory.shutdown();
      try {
        if (zkDb != null) {
          zkDb.close();
        }
      } catch (IOException ie) {
        LOG.warn("Error closing logs ", ie);
      }
      final int PORT = getPort(hostPort);

      Assert.assertTrue(
          "waiting for server down",
          ClientBase.waitForServerDown("127.0.0.1:" + PORT, CONNECTION_TIMEOUT));
    }
  }
  @Override
  public synchronized void start(final StartContext context) throws StartException {
    File dir = new File(dataDir).getAbsoluteFile();

    try {
      zooKeeperServer = new ZooKeeperServer(dir, dir, (int) tickTime);

      ServerCnxnFactory serverCnxnFactory =
          ServerCnxnFactory.createFactory(binding.getValue().getSocketAddress(), 5);
      zooKeeperServer.setServerCnxnFactory(serverCnxnFactory);

      context.asynchronous();
      executor.getValue().execute(new ZooKeeperServerRunner(zooKeeperServer, context));
    } catch (IOException e) {
      context.failed(new StartException(e));
    }
  }