本文整理汇总了Java中org.apache.zookeeper.server.ZooKeeperServer类的典型用法代码示例。如果您正苦于以下问题:Java ZooKeeperServer类的具体用法?Java ZooKeeperServer怎么用?Java ZooKeeperServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZooKeeperServer类属于org.apache.zookeeper.server包,在下文中一共展示了ZooKeeperServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shutdownServerInstance
import org.apache.zookeeper.server.ZooKeeperServer; //导入依赖的package包/类
static void shutdownServerInstance(ServerCnxnFactory factory,
String hostPort)
{
if (factory != null) {
ZKDatabase zkDb;
{
ZooKeeperServer zs = getServer(factory);
zkDb = zs.getZKDatabase();
}
factory.shutdown();
try {
zkDb.close();
} catch (IOException ie) {
LOG.warn("Error closing logs ", ie);
}
final int PORT = getPort(hostPort);
Assert.assertTrue("waiting for server down",
ClientBaseWithFixes.waitForServerDown("127.0.0.1:" + PORT,
CONNECTION_TIMEOUT));
}
}
示例2: MiniZKFCCluster
import org.apache.zookeeper.server.ZooKeeperServer; //导入依赖的package包/类
public MiniZKFCCluster(Configuration conf, ZooKeeperServer zks) {
this.conf = conf;
// Fast check interval so tests run faster
conf.setInt(CommonConfigurationKeys.HA_HM_CHECK_INTERVAL_KEY, 50);
conf.setInt(CommonConfigurationKeys.HA_HM_CONNECT_RETRY_INTERVAL_KEY, 50);
conf.setInt(CommonConfigurationKeys.HA_HM_SLEEP_AFTER_DISCONNECT_KEY, 50);
svcs = new ArrayList<DummyHAService>(2);
// remove any existing instances we are keeping track of
DummyHAService.instances.clear();
for (int i = 0; i < 2; i++) {
addSvcs(svcs, i);
}
this.ctx = new TestContext();
this.zks = zks;
}
示例3: startServerInstance
import org.apache.zookeeper.server.ZooKeeperServer; //导入依赖的package包/类
/**
* Starting the given server instance
*/
public static void startServerInstance(File dataDir,
ServerCnxnFactory factory, String hostPort) throws IOException,
InterruptedException {
final int port = getPort(hostPort);
LOG.info("STARTING server instance 127.0.0.1:{}", port);
ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000);
factory.startup(zks);
Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp(
"127.0.0.1:" + port, CONNECTION_TIMEOUT));
}
示例4: shutdownServerInstance
import org.apache.zookeeper.server.ZooKeeperServer; //导入依赖的package包/类
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));
}
}
示例5: run
import org.apache.zookeeper.server.ZooKeeperServer; //导入依赖的package包/类
@Override
public CommandResponse run(ZooKeeperServer zkServer, Map<String, String> kwargs) {
CommandResponse response = initializeResponse();
long traceMask;
if (!kwargs.containsKey("traceMask")) {
response.put("error", "setTraceMask requires long traceMask argument");
return response;
}
try {
traceMask = Long.parseLong(kwargs.get("traceMask"));
} catch (NumberFormatException e) {
response.put("error", "setTraceMask requires long traceMask argument, got "
+ kwargs.get("traceMask"));
return response;
}
ZooTrace.setTextTraceLevel(traceMask);
response.put("tracemask", traceMask);
return response;
}
示例6: setupZooKeeper
import org.apache.zookeeper.server.ZooKeeperServer; //导入依赖的package包/类
@BeforeClass
public static void setupZooKeeper() throws Exception {
LOG.info("Starting ZK server");
zkTmpDir = File.createTempFile("zookeeper", "test");
zkTmpDir.delete();
zkTmpDir.mkdir();
try {
zks = new ZooKeeperServer(zkTmpDir, zkTmpDir, ZooKeeperDefaultPort);
serverFactory = new NIOServerCnxnFactory();
serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), 10);
serverFactory.startup(zks);
} catch (Exception e) {
LOG.error("Exception while instantiating ZooKeeper", e);
}
boolean b = LocalBookKeeper.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT);
LOG.debug("ZooKeeper server up: " + b);
}
示例7: setupZooKeeper
import org.apache.zookeeper.server.ZooKeeperServer; //导入依赖的package包/类
@BeforeClass
public static void setupZooKeeper() throws Exception {
// create a ZooKeeper server(dataDir, dataLogDir, port)
LOG.info("Starting ZK server");
ZkTmpDir = File.createTempFile("zookeeper", "test");
ZkTmpDir.delete();
ZkTmpDir.mkdir();
try {
zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperDefaultPort);
serverFactory = new NIOServerCnxnFactory();
serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), 10);
serverFactory.startup(zks);
} catch (Exception e) {
LOG.error("Exception while instantiating ZooKeeper", e);
}
boolean b = LocalBookKeeper.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT);
LOG.debug("ZooKeeper server up: " + b);
}
示例8: MiniZooKeeperCluster
import org.apache.zookeeper.server.ZooKeeperServer; //导入依赖的package包/类
public MiniZooKeeperCluster(Configuration configuration) {
this.started = false;
this.configuration = configuration;
activeZKServerIndex = -1;
zooKeeperServers = new ArrayList<ZooKeeperServer>();
clientPortList = new ArrayList<Integer>();
standaloneServerFactoryList = new ArrayList<NIOServerCnxnFactory>();
}
示例9: waitForActiveLockData
import org.apache.zookeeper.server.ZooKeeperServer; //导入依赖的package包/类
public static void waitForActiveLockData(TestContext ctx,
ZooKeeperServer zks, String parentDir, byte[] activeData)
throws Exception {
long st = Time.now();
long lastPrint = st;
while (true) {
if (ctx != null) {
ctx.checkException();
}
try {
Stat stat = new Stat();
byte[] data = zks.getZKDatabase().getData(
parentDir + "/" +
ActiveStandbyElector.LOCK_FILENAME, stat, null);
if (activeData != null &&
Arrays.equals(activeData, data)) {
return;
}
if (Time.now() > lastPrint + LOG_INTERVAL_MS) {
LOG.info("Cur data: " + StringUtils.byteToHexString(data));
lastPrint = Time.now();
}
} catch (NoNodeException nne) {
if (activeData == null) {
return;
}
if (Time.now() > lastPrint + LOG_INTERVAL_MS) {
LOG.info("Cur data: no node");
lastPrint = Time.now();
}
}
Thread.sleep(50);
}
}
示例10: EmbeddedZooKeeper
import org.apache.zookeeper.server.ZooKeeperServer; //导入依赖的package包/类
EmbeddedZooKeeper() throws IOException, InterruptedException {
this.tmpDir = Files.createTempDirectory(null).toFile();
this.factory = new NIOServerCnxnFactory();
this.zookeeper = new ZooKeeperServer(new File(tmpDir, "data"), new File(tmpDir, "log"), TICK_TIME);
InetSocketAddress addr = new InetSocketAddress("127.0.0.1", 0);
factory.configure(addr, 0);
factory.startup(zookeeper);
this.port = zookeeper.getClientPort();
}
示例11: ReadOnlyRequestProcessor
import org.apache.zookeeper.server.ZooKeeperServer; //导入依赖的package包/类
public ReadOnlyRequestProcessor(ZooKeeperServer zks,
RequestProcessor nextProcessor) {
super("ReadOnlyRequestProcessor:" + zks.getServerId(), zks
.getZooKeeperServerListener());
this.zks = zks;
this.nextProcessor = nextProcessor;
}
示例12: getActiveServer
import org.apache.zookeeper.server.ZooKeeperServer; //导入依赖的package包/类
synchronized public ZooKeeperServer getActiveServer(){
if(leader!=null)
return leader.zk;
else if(follower!=null)
return follower.zk;
else if (observer != null)
return observer.zk;
return null;
}
示例13: unregisterJMX
import org.apache.zookeeper.server.ZooKeeperServer; //导入依赖的package包/类
protected void unregisterJMX(ZooKeeperServer zks) {
// unregister from JMX
try {
if (jmxServerBean != null) {
MBeanRegistry.getInstance().unregister(jmxServerBean);
}
} catch (Exception e) {
LOG.warn("Failed to unregister with JMX", e);
}
jmxServerBean = null;
}
示例14: initialize
import org.apache.zookeeper.server.ZooKeeperServer; //导入依赖的package包/类
public static void initialize() {
synchronized (ProviderRegistry.class) {
if (initialized)
return;
IPAuthenticationProvider ipp = new IPAuthenticationProvider();
DigestAuthenticationProvider digp = new DigestAuthenticationProvider();
authenticationProviders.put(ipp.getScheme(), ipp);
authenticationProviders.put(digp.getScheme(), digp);
Enumeration<Object> en = System.getProperties().keys();
while (en.hasMoreElements()) {
String k = (String) en.nextElement();
if (k.startsWith("zookeeper.authProvider.")) {
String className = System.getProperty(k);
try {
Class<?> c = ZooKeeperServer.class.getClassLoader()
.loadClass(className);
AuthenticationProvider ap = (AuthenticationProvider) c
.newInstance();
authenticationProviders.put(ap.getScheme(), ap);
} catch (Exception e) {
LOG.warn("Problems loading " + className,e);
}
}
}
initialized = true;
}
}
示例15: createFollower
import org.apache.zookeeper.server.ZooKeeperServer; //导入依赖的package包/类
private ConversableFollower createFollower(File tmpDir, QuorumPeer peer)
throws IOException {
FileTxnSnapLog logFactory = new FileTxnSnapLog(tmpDir, tmpDir);
peer.setTxnFactory(logFactory);
ZKDatabase zkDb = new ZKDatabase(logFactory);
FollowerZooKeeperServer zk = new FollowerZooKeeperServer(logFactory, peer, new ZooKeeperServer.BasicDataTreeBuilder(), zkDb);
peer.setZKDatabase(zkDb);
return new ConversableFollower(peer, zk);
}