use of org.apache.zookeeper.server.ZooKeeperServer in project fabric8 by jboss-fuse.
the class GroupTest method startZooKeeper.
private NIOServerCnxnFactory startZooKeeper(int port) throws Exception {
ServerConfig cfg = new ServerConfig();
cfg.parse(new String[] { Integer.toString(port), "target/zk/data" });
ZooKeeperServer zkServer = new ZooKeeperServer();
FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(cfg.getDataLogDir()), new File(cfg.getDataDir()));
zkServer.setTxnLogFactory(ftxn);
zkServer.setTickTime(cfg.getTickTime());
zkServer.setMinSessionTimeout(6000);
zkServer.setMaxSessionTimeout(9000);
NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory();
cnxnFactory.configure(cfg.getClientPortAddress(), cfg.getMaxClientCnxns());
cnxnFactory.startup(zkServer);
return cnxnFactory;
}
use of org.apache.zookeeper.server.ZooKeeperServer in project fabric8 by jboss-fuse.
the class ZookeeperPortServiceTest method startZooKeeper.
private NIOServerCnxnFactory startZooKeeper(int port) throws Exception {
String testDirectory = "target/zk-ports/data" + System.currentTimeMillis();
FileUtils.deleteDirectory(new File(testDirectory));
ServerConfig cfg = new ServerConfig();
cfg.parse(new String[] { Integer.toString(port), testDirectory });
ZooKeeperServer zkServer = new ZooKeeperServer();
FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(cfg.getDataLogDir()), new File(cfg.getDataDir()));
zkServer.setTxnLogFactory(ftxn);
zkServer.setTickTime(cfg.getTickTime());
zkServer.setMinSessionTimeout(cfg.getMinSessionTimeout());
zkServer.setMaxSessionTimeout(cfg.getMaxSessionTimeout());
NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory();
cnxnFactory.configure(cfg.getClientPortAddress(), cfg.getMaxClientCnxns());
cnxnFactory.startup(zkServer);
return cnxnFactory;
}
use of org.apache.zookeeper.server.ZooKeeperServer in project fabric8 by jboss-fuse.
the class ServiceFactoryTest method infraUp.
@Before
public void infraUp() throws Exception {
int tickTime = 500;
int numConnections = 5000;
File dir = new File("target", "zookeeper" + random.nextInt()).getAbsoluteFile();
server = new ZooKeeperServer(dir, dir, tickTime);
standaloneServerFactory = createFactory(0, numConnections);
zkPort = standaloneServerFactory.getLocalPort();
System.setProperty("zookeeper.url", "localhost:" + zkPort);
standaloneServerFactory.startup(server);
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + zkPort).sessionTimeoutMs(5000).retryPolicy(new RetryNTimes(5000, 1000));
curator = builder.build();
LOG.debug("Starting curator " + curator);
curator.start();
}
use of org.apache.zookeeper.server.ZooKeeperServer in project bookkeeper by apache.
the class ZooKeeperUtil method restartServer.
public void restartServer() throws Exception {
zks = new ZooKeeperServer(zkTmpDir, zkTmpDir, ZooKeeperServer.DEFAULT_TICK_TIME);
serverFactory = new NIOServerCnxnFactory();
serverFactory.configure(zkaddr, 100);
serverFactory.startup(zks);
if (0 == zooKeeperPort) {
zooKeeperPort = serverFactory.getLocalPort();
zkaddr = new InetSocketAddress(zkaddr.getHostName(), zooKeeperPort);
connectString = zkaddr.getHostName() + ":" + zooKeeperPort;
}
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()).sessionTimeoutMs(10000).build();
}
use of org.apache.zookeeper.server.ZooKeeperServer in project airavata by apache.
the class AiravataZKUtils method runZKFromConfig.
public static void runZKFromConfig(ServerConfig config, ServerCnxnFactory cnxnFactory) throws IOException {
AiravataZKUtils.logger.info("Starting Zookeeper server...");
FileTxnSnapLog txnLog = null;
try {
// Note that this thread isn't going to be doing anything else,
// so rather than spawning another thread, we will just call
// run() in this thread.
// create a file logger url from the command line args
ZooKeeperServer zkServer = new ZooKeeperServer();
txnLog = new FileTxnSnapLog(new File(config.getDataDir()), new File(config.getDataDir()));
zkServer.setTxnLogFactory(txnLog);
zkServer.setTickTime(config.getTickTime());
zkServer.setMinSessionTimeout(config.getMinSessionTimeout());
zkServer.setMaxSessionTimeout(config.getMaxSessionTimeout());
cnxnFactory = ServerCnxnFactory.createFactory();
cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns());
cnxnFactory.startup(zkServer);
cnxnFactory.join();
if (zkServer.isRunning()) {
zkServer.shutdown();
}
} catch (InterruptedException e) {
// warn, but generally this is ok
AiravataZKUtils.logger.warn("Server interrupted", e);
System.exit(1);
} finally {
if (txnLog != null) {
txnLog.close();
}
}
}
Aggregations