use of org.apache.zookeeper.server.NIOServerCnxnFactory in project rest.li by linkedin.
the class ZKServer method restart.
public void restart() throws IOException, InterruptedException {
shutdown(false);
_zk = new ZooKeeperServer(_dataDir, _logDir, 5000);
_factory = new NIOServerCnxnFactory();
_factory.configure(new InetSocketAddress(_port), 60);
startup();
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project drill by apache.
the class MiniZooKeeperCluster method shutdown.
/**
* @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();
logger.info("Shutdown MiniZK cluster with all ZK servers");
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project hbase by apache.
the class MiniZooKeeperCluster method killCurrentActiveZooKeeperServer.
/**
* @return clientPort return clientPort if there is another ZK backup can run
* when killing the current active; return -1, if there is no backups.
* @throws IOException if waiting for the shutdown of a server fails
*/
public int killCurrentActiveZooKeeperServer() throws IOException, InterruptedException {
if (!started || activeZKServerIndex < 0) {
return -1;
}
// Shutdown the current active one
NIOServerCnxnFactory standaloneServerFactory = standaloneServerFactoryList.get(activeZKServerIndex);
int clientPort = clientPortList.get(activeZKServerIndex);
standaloneServerFactory.shutdown();
if (!waitForServerDown(clientPort, connectionTimeout)) {
throw new IOException("Waiting for shutdown of standalone server");
}
zooKeeperServers.get(activeZKServerIndex).getZKDatabase().close();
// remove the current active zk server
standaloneServerFactoryList.remove(activeZKServerIndex);
clientPortList.remove(activeZKServerIndex);
zooKeeperServers.remove(activeZKServerIndex);
LOG.info("Kill the current active ZK servers in the cluster on client port: {}", clientPort);
if (standaloneServerFactoryList.isEmpty()) {
// there is no backup servers;
return -1;
}
clientPort = clientPortList.get(activeZKServerIndex);
LOG.info("Activate a backup zk server in the cluster on client port: {}", clientPort);
// return the next back zk server's port
return clientPort;
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project hbase by apache.
the class MiniZooKeeperCluster method shutdown.
/**
* @throws IOException if waiting for the shutdown of a server fails
*/
public void shutdown() throws IOException {
// 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, connectionTimeout)) {
throw new IOException("Waiting for shutdown of standalone server at port=" + clientPort + ", timeout=" + this.connectionTimeout);
}
}
standaloneServerFactoryList.clear();
for (ZooKeeperServer zkServer : zooKeeperServers) {
// Explicitly close ZKDatabase since ZookeeperServer does not close them
zkServer.getZKDatabase().close();
}
zooKeeperServers.clear();
// clear everything
if (started) {
started = false;
activeZKServerIndex = 0;
clientPortList.clear();
LOG.info("Shutdown MiniZK cluster with all ZK servers");
}
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project hbase by apache.
the class MiniZooKeeperCluster method killOneBackupZooKeeperServer.
/**
* 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);
}
Aggregations