use of org.apache.zookeeper.server.ZooKeeperServer in project xian by happyyangyuan.
the class TestingZooKeeperMain method getZooKeeperServer.
private ZooKeeperServer getZooKeeperServer(ServerCnxnFactory cnxnFactory) throws Exception {
Field zkServerField = ServerCnxnFactory.class.getDeclaredField("zkServer");
zkServerField.setAccessible(true);
ZooKeeperServer zkServer;
// Wait until the zkServer field is non-null or up to 1s, whichever comes first.
long startTime = System.currentTimeMillis();
do {
zkServer = (ZooKeeperServer) zkServerField.get(cnxnFactory);
} while ((zkServer == null) && ((System.currentTimeMillis() - startTime) < MAX_WAIT_MS));
return zkServer;
}
use of org.apache.zookeeper.server.ZooKeeperServer in project xian by happyyangyuan.
the class TestingZooKeeperMain method blockUntilStarted.
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
@Override
public void blockUntilStarted() throws Exception {
latch.await();
ServerCnxnFactory cnxnFactory = getServerConnectionFactory();
if (cnxnFactory != null) {
final ZooKeeperServer zkServer = getZooKeeperServer(cnxnFactory);
if (zkServer != null) {
synchronized (zkServer) {
if (!zkServer.isRunning()) {
zkServer.wait();
}
}
}
}
Thread.sleep(1000);
Exception exception = startingException.get();
if (exception != null) {
throw exception;
}
}
use of org.apache.zookeeper.server.ZooKeeperServer 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.ZooKeeperServer in project incubator-pulsar by apache.
the class ZooKeeperServerAspect method zkServerConstructor.
@After("zkServerConstructorPointCut()")
public void zkServerConstructor(JoinPoint joinPoint) throws Throwable {
// ZooKeeperServer instance was created
ZooKeeperServer zkServer = (ZooKeeperServer) joinPoint.getThis();
synchronized (ZooKeeperServerAspect.class) {
if (metricsRegistered) {
// We can only register the metrics a single time for the process
return;
}
metricsRegistered = true;
}
Gauge.build().name("zookeeper_server_znode_count").help("Number of z-nodes stored").create().setChild(new Gauge.Child() {
@Override
public double get() {
return zkServer.getZKDatabase().getNodeCount();
}
}).register();
Gauge.build().name("zookeeper_server_data_size_bytes").help("Size of all of z-nodes stored (bytes)").create().setChild(new Gauge.Child() {
@Override
public double get() {
return zkServer.getZKDatabase().getDataTree().approximateDataSize();
}
}).register();
Gauge.build().name("zookeeper_server_connections").help("Number of currently opened connections").create().setChild(new Gauge.Child() {
@Override
public double get() {
return zkServer.serverStats().getNumAliveClientConnections();
}
}).register();
Gauge.build().name("zookeeper_server_watches_count").help("Number of watches").create().setChild(new Gauge.Child() {
@Override
public double get() {
return zkServer.getZKDatabase().getDataTree().getWatchCount();
}
}).register();
Gauge.build().name("zookeeper_server_ephemerals_count").help("Number of ephemerals z-nodes").create().setChild(new Gauge.Child() {
@Override
public double get() {
return zkServer.getZKDatabase().getDataTree().getEphemeralsCount();
}
}).register();
}
use of org.apache.zookeeper.server.ZooKeeperServer in project ecf by eclipse.
the class ZooDiscoveryContainer method startStandAlone.
/**
* Start a ZooKeeer server locally to write nodes to. Implied by
* {@link IDiscoveryConfig#ZOODISCOVERY_FLAVOR_STANDALONE} configuration.
*
* @param conf
*/
void startStandAlone(final Configuration conf) {
if (ZooDiscoveryContainer.zooKeeperServer != null && ZooDiscoveryContainer.zooKeeperServer.isRunning())
return;
else if (ZooDiscoveryContainer.zooKeeperServer != null && !ZooDiscoveryContainer.zooKeeperServer.isRunning())
try {
ZooDiscoveryContainer.zooKeeperServer.startup();
return;
} catch (Exception e) {
// $NON-NLS-1$
Logger.log(LogService.LOG_DEBUG, "Zookeeper server cannot be started! ", e);
}
try {
ZooDiscoveryContainer.zooKeeperServer = new ZooKeeperServer();
FileTxnSnapLog fileTxnSnapLog = new FileTxnSnapLog(conf.getZookeeperDataFile(), conf.getZookeeperDataFile());
ZooDiscoveryContainer.zooKeeperServer.setTxnLogFactory(fileTxnSnapLog);
ZooDiscoveryContainer.zooKeeperServer.setTickTime(conf.getTickTime());
Factory cnxnFactory = new NIOServerCnxn.Factory(new InetSocketAddress(conf.getClientPort()));
cnxnFactory.startup(ZooDiscoveryContainer.zooKeeperServer);
} catch (Exception e) {
Logger.log(LogService.LOG_ERROR, "Zookeeper server cannot be started! Possibly another instance is already running on the same port. ", e);
}
}
Aggregations