本文整理匯總了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);
}
}