use of org.apache.zookeeper.server.NIOServerCnxnFactory in project wildfly-camel by wildfly-extras.
the class ZKServerFactoryBean method afterPropertiesSet.
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);
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project incubator-pulsar by apache.
the class ZooKeeperUtil method startServer.
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");
zkc = ZooKeeperClient.newBuilder().connectString(getZooKeeperConnectString()).build();
// 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);
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project drill by axbaretto.
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();
LOG.info("Shutdown MiniZK cluster with all ZK servers");
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project drill by axbaretto.
the class MiniZooKeeperCluster method startup.
/**
* @param baseDir
* @param numZooKeeperServers
* @return ClientPort server bound to.
* @throws IOException
* @throws InterruptedException
*/
public int startup(File baseDir, int numZooKeeperServers) throws IOException, InterruptedException {
if (numZooKeeperServers <= 0) {
return -1;
}
setupTestEnv();
shutdown();
int tentativePort = selectClientPort();
// running all the ZK servers
for (int i = 0; i < numZooKeeperServers; i++) {
File dir = new File(baseDir, "zookeeper_" + i).getAbsoluteFile();
recreateDir(dir);
int tickTimeToUse;
if (this.tickTime > 0) {
tickTimeToUse = this.tickTime;
} else {
tickTimeToUse = TICK_TIME;
}
ZooKeeperServer server = new ZooKeeperServer(dir, dir, tickTimeToUse);
NIOServerCnxnFactory standaloneServerFactory;
while (true) {
try {
standaloneServerFactory = new NIOServerCnxnFactory();
standaloneServerFactory.configure(new InetSocketAddress(tentativePort), 1000);
} catch (BindException e) {
LOG.debug("Failed binding ZK Server to client port: " + tentativePort);
// This port is already in use, try to use another.
tentativePort++;
continue;
}
try {
standaloneServerFactory.startup(server);
} catch (IOException e) {
LOG.error("Zookeeper startup error", e);
tentativePort++;
continue;
}
if (!waitForServerUp(server, CONNECTION_TIMEOUT)) {
server.shutdown();
server = new ZooKeeperServer(dir, dir, tickTimeToUse);
tentativePort++;
continue;
}
break;
}
// We have selected this port as a client port.
clientPortList.add(tentativePort);
standaloneServerFactoryList.add(standaloneServerFactory);
zooKeeperServers.add(server);
}
// set the first one to be active ZK; Others are backups
activeZKServerIndex = 0;
started = true;
clientPort = clientPortList.get(activeZKServerIndex);
LOG.info("Started MiniZK Cluster and connect 1 ZK server " + "on client port: " + clientPort);
return clientPort;
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project drill by axbaretto.
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
* @throws InterruptedException
*/
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, CONNECTION_TIMEOUT)) {
throw new IOException("Waiting for shutdown of standalone server");
}
// 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.size() == 0) {
// 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;
}
Aggregations