本文整理汇总了Java中org.apache.zookeeper.WatchedEvent.getState方法的典型用法代码示例。如果您正苦于以下问题:Java WatchedEvent.getState方法的具体用法?Java WatchedEvent.getState怎么用?Java WatchedEvent.getState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.zookeeper.WatchedEvent
的用法示例。
在下文中一共展示了WatchedEvent.getState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectZooKeeper
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
private static ZooKeeper connectZooKeeper(String ensemble)
throws IOException, KeeperException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
ZooKeeper zkc = new ZooKeeper(HOSTPORT, ZK_SESSION_TIMEOUT, new Watcher() {
public void process(WatchedEvent event) {
if (event.getState() == Watcher.Event.KeeperState.SyncConnected) {
latch.countDown();
}
}
});
if (!latch.await(ZK_SESSION_TIMEOUT, TimeUnit.MILLISECONDS)) {
throw new IOException("Zookeeper took too long to connect");
}
return zkc;
}
示例2: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
public void process(WatchedEvent event) {
if (event.getState() == KeeperState.SyncConnected) {
if (latch != null) {
latch.countDown();
}
}
if (event.getType() == EventType.None) {
return;
}
try {
events.put(event);
} catch (InterruptedException e) {
Assert.assertTrue("interruption unexpected", false);
}
}
示例3: connectZooKeeper
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
private static ZooKeeper connectZooKeeper(String ensemble)
throws IOException, KeeperException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
ZooKeeper zkc = new ZooKeeper(HOSTPORT, 3600, new Watcher() {
public void process(WatchedEvent event) {
if (event.getState() == Watcher.Event.KeeperState.SyncConnected) {
latch.countDown();
}
}
});
if (!latch.await(10, TimeUnit.SECONDS)) {
throw new IOException("Zookeeper took too long to connect");
}
return zkc;
}
示例4: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
/**
* It listen to Zookeeper session events. It is called automatically by Zookeeper when a zookeeper session issues an event.
*
* @param event issued by zookeeper session
* @throws IllegalStateException if {@link ZKClusterWatcher#start()} was not called.
*/
@Override
public void process(final WatchedEvent event) {
if (zkConnection == null || zkNodeWatchers == null) {
throw new IllegalStateException("Zookeeper monitoring has not been started.");
}
try {
if (event.getType() == Watcher.Event.EventType.None) {
switch (event.getState()) {
case SyncConnected:
zkClusterStatus.getAndSet(ZKClusterStatusName.QUORUM);
zkMonitorListener.onGetQuorum();
zkNodeWatchers.forEach(zkNodeWatcher -> zkNodeWatcher.updateStatus());
break;
case Disconnected:
zkClusterStatus.getAndSet(ZKClusterStatusName.NO_QUORUM);
zkMonitorListener.onLackOfQuorum();
zkNodeWatchers.forEach(zkNodeWatcher -> zkNodeWatcher.updateStatus());
break;
case Expired:
zkClusterStatus.set(ZKClusterStatusName.NO_QUORUM);
restartZKConnection();
break;
default:
break;
}
}
} catch (Exception e) {
throw new ZKMonitorException(e.getMessage(), e, this.getClass());
}
}
示例5: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
/**
* It listen to Zookeeper events.
* It is called automatically by Zookeeper when a Kafka broker znode has appeared/disappeared or
* session connect/disconnect
*
* @param event {@link WatchedEvent} instance sent by Zookeeper node
*/
@Override
public void process(final WatchedEvent event) {
if (zkClient == null) {
return;
}
if (event.getType() != Event.EventType.None) {
setupWatcherAsync(); // Must initialize the watcher because it is one-shot.
switch (event.getType()) {
case NodeChildrenChanged: // A kafka broker has appeared / disappeared
updateBrokerStatus(); // Force to update brokers' status
break;
default:
}
} else {
switch (event.getState()) {
case SyncConnected:
case Disconnected:
updateBrokerStatus(); // Force to update brokers' status
break;
case Expired:
restartZKConnection(); // ZK connection has expired, let's reconnect
break;
default:
}
}
}
示例6: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
@Override
public void process(WatchedEvent event) {
// TODO Auto-generated method stub
System.out.println("Receive Watcher Event:" + event);
if (KeeperState.SyncConnected == event.getState()) {
countDownLatch.countDown();
}
}
示例7: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
synchronized public void process(WatchedEvent event) {
if (event.getState() == KeeperState.SyncConnected ||
event.getState() == KeeperState.ConnectedReadOnly) {
connected = true;
notifyAll();
clientConnected.countDown();
} else {
connected = false;
notifyAll();
}
}
示例8: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
public void process(WatchedEvent event) {
LOG.info(name + " event:" + event.getState() + " "
+ event.getType() + " " + event.getPath());
if (event.getState() == KeeperState.SyncConnected
&& startSignal != null && startSignal.getCount() > 0)
{
startSignal.countDown();
}
}
示例9: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
@Override
public void process(WatchedEvent event) {
KeeperState state = event.getState();
if (state == KeeperState.SyncConnected) {
ZooKeeperConnectionDescriptor zooKeeperConnectionDescriptor = getDescriptor();
List<AuthInfo> authInfos = zooKeeperConnectionDescriptor.getAuthInfos();
if (authInfos != null && !authInfos.isEmpty()) {
for (AuthInfo authInfo : authInfos) {
String scheme = authInfo.getScheme();
byte[] auth;
try {
auth = authInfo.getAuth();
}
catch (IOException e) {
e.printStackTrace();
continue;
}
// TODO: Is the lack of thread saftey of this method a concern here?
addAuthInfo(scheme, auth);
}
}
}
fireConnectionStateChanged();
}
示例10: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
public void process(WatchedEvent event) {
LOG.info("Event:" + event.getState() + " " + event.getType() + " " + event.getPath());
if (event.getState() == KeeperState.SyncConnected
&& startSignal != null && startSignal.getCount() > 0)
{
startSignal.countDown();
}
}
示例11: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
public void process(WatchedEvent event) {
if (event.getType() == Watcher.Event.EventType.None) {
synchronized (this) {
connected = event.getState() == Watcher.Event.KeeperState.SyncConnected;
notifyAll();
}
}
}
示例12: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
@Override
public synchronized void process(WatchedEvent event) {
if (event.getState() == KeeperState.AuthFailed) {
authFailed.incrementAndGet();
}
else {
super.process(event);
}
}
示例13: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
public void process(WatchedEvent event) {
LOG.info("Event:" + event.getState() + " " + event.getType() + " "
+ event.getPath());
if (event.getState() == KeeperState.SyncConnected) {
if (startSignal != null && startSignal.getCount() > 0) {
LOG.info("startsignal.countDown()");
startSignal.countDown();
} else {
LOG.warn("startsignal " + startSignal);
}
}
}
示例14: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
@Override
public synchronized void process(WatchedEvent event) {
if (event.getState() == KeeperState.AuthFailed) {
authFailed.countDown();
}
else {
super.process(event);
}
}
示例15: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
@Override
public synchronized void process(WatchedEvent event) {
if (event.getState() == KeeperState.AuthFailed) {
synchronized(authFailed) {
authFailed.incrementAndGet();
authFailed.notify();
}
}
else {
super.process(event);
}
}