本文整理匯總了Java中org.apache.zookeeper.WatchedEvent.getType方法的典型用法代碼示例。如果您正苦於以下問題:Java WatchedEvent.getType方法的具體用法?Java WatchedEvent.getType怎麽用?Java WatchedEvent.getType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.zookeeper.WatchedEvent
的用法示例。
在下文中一共展示了WatchedEvent.getType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: process
import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
@Override
public void process(WatchedEvent event) throws Exception {
String topicParentPath = zkConf.getZKBasePath() + "/topics";
LOG.info("get zookeeper notification for path={}", topicParentPath);
if (event.getType() == Watcher.Event.EventType.NodeChildrenChanged) {
List<String> newTopics = zkClient.getChildren().forPath(topicParentPath);
List<String> oldTopics = metadata.getAllTopics();
Collection<String> addedTopics = CollectionUtils.subtract(newTopics, oldTopics);
Collection<String> deletedTopics = CollectionUtils.subtract(oldTopics, newTopics);
for (String topic : addedTopics) {
String topicPath = topicParentPath + "/" + topic;
zkClient.getChildren()
.usingWatcher(new TopicWatcher(topic))
.forPath(topicPath);
Map<Integer, Integer> queueMap = readTopicInfo(topic);
metadata.updateTopicMap(topic, queueMap);
}
metadata.removeTopics(deletedTopics);
}
zkClient.getChildren()
.usingWatcher(new TopicsWather())
.forPath(topicParentPath);
}
示例2: processDataOrChildChange
import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
private void processDataOrChildChange(WatchedEvent event) {
final String path = event.getPath();
if (event.getType() == EventType.NodeChildrenChanged || event.getType() == EventType.NodeCreated || event.getType() == EventType.NodeDeleted) {
Set<IZkChildListener> childListeners = _childListener.get(path);
if (childListeners != null && !childListeners.isEmpty()) {
fireChildChangedEvents(path, childListeners);
}
}
if (event.getType() == EventType.NodeDataChanged || event.getType() == EventType.NodeDeleted || event.getType() == EventType.NodeCreated) {
Set<IZkDataListener> listeners = _dataListener.get(path);
if (listeners != null && !listeners.isEmpty()) {
fireDataChangedEvents(event.getPath(), listeners);
}
}
}
示例3: process
import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
public void process(WatchedEvent event) {
switch (event.getType()) {
case None:
switch (event.getState()) {
case SyncConnected:
connected = true;
break;
case Disconnected:
connected = false;
break;
default:
break;
}
break;
default:
break;
}
}
示例4: process
import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
@Override
public void process(WatchedEvent event) {
ZooKeeper zkClient = zookeeperConnManager.getZkClient();
try {
/* 重新注冊節點 */
List<String> childrens = zkClient.getChildren(nodePath, this);
EventType eventType = event.getType();
switch (eventType) {
case NodeChildrenChanged:
log.info("當前注冊中心內的成功注冊的agent數量-->"
+ childrens.stream().filter(children -> children.startsWith("agent")).count());
break;
default:
break;
}
} catch (Exception e) {
log.error("error", e);
}
}
示例5: process
import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
@Override
public void process(WatchedEvent event) {
if (isDestroyed()) {
return;
}
if (!getZooKeeperConnection().isConnected()) {
return;
}
String eventPath = event.getPath();
EventType eventType = event.getType();
Znode znode = getData();
String path = znode.getPath();
if (path.equals(eventPath) && eventType.equals(EventType.NodeDeleted)) {
destroy();
return;
}
processUpdate(event);
fireDataModelDataChanged();
}
示例6: 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);
}
}
示例7: processDataOrChildChange
import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
private void processDataOrChildChange(WatchedEvent event) {
final String path = event.getPath();
if (event.getType() == EventType.NodeChildrenChanged || event.getType() == EventType.NodeCreated
|| event.getType() == EventType.NodeDeleted) {
Set<IZkChildListener> childListeners = _childListener.get(path);
if (childListeners != null && !childListeners.isEmpty()) {
fireChildChangedEvents(path, childListeners);
}
}
if (event.getType() == EventType.NodeDataChanged || event.getType() == EventType.NodeDeleted
|| event.getType() == EventType.NodeCreated) {
Set<IZkDataListener> listeners = _dataListener.get(path);
if (listeners != null && !listeners.isEmpty()) {
fireDataChangedEvents(event.getPath(), listeners);
}
}
}
示例8: 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());
}
}
示例9: process
import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
@Override
public void process(WatchedEvent event) {
if (event.getType() == EventType.NodeDataChanged) {
synchronized(this) {
changed = true;
notifyAll();
}
}
}
示例10: process
import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
public void process(WatchedEvent event) {
super.process(event);
if (event.getType() != Event.EventType.None) {
try {
events.put(event);
} catch (InterruptedException e) {
LOG.warn("ignoring interrupt during event.put");
}
}
}
示例11: process
import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
@Override
public void process(WatchedEvent event) {
super.process(event);
try {
if (event.getType() != Event.EventType.None) {
dataEvents.put(event);
}
} catch (InterruptedException e) {
LOG.warn("ignoring interrupt during EventsWatcher process");
}
}
示例12: process
import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
public void process(WatchedEvent event) {
System.err.println(event);
synchronized (this) {
if (event.getType() == EventType.None) {
connected = (event.getState() == KeeperState.SyncConnected);
notifyAll();
}
}
}
示例13: 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();
}
}
}
示例14: processWatchEvent
import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
/**
* interface implementation of Zookeeper watch events (connection and node),
* proxied by {@link WatcherWithClientRef}.
*/
synchronized void processWatchEvent(ZooKeeper zk, WatchedEvent event) {
Event.EventType eventType = event.getType();
if (isStaleClient(zk)) return;
LOG.debug("Watcher event type: " + eventType + " with state:"
+ event.getState() + " for path:" + event.getPath()
+ " connectionState: " + zkConnectionState
+ " for " + this);
if (eventType == Event.EventType.None) {
// the connection state has changed
switch (event.getState()) {
case SyncConnected:
LOG.info("Session connected.");
// if the listener was asked to move to safe state then it needs to
// be undone
ConnectionState prevConnectionState = zkConnectionState;
zkConnectionState = ConnectionState.CONNECTED;
if (prevConnectionState == ConnectionState.DISCONNECTED &&
wantToBeInElection) {
monitorActiveStatus();
}
break;
case Disconnected:
LOG.info("Session disconnected. Entering neutral mode...");
// ask the app to move to safe state because zookeeper connection
// is not active and we dont know our state
zkConnectionState = ConnectionState.DISCONNECTED;
enterNeutralMode();
break;
case Expired:
// the connection got terminated because of session timeout
// call listener to reconnect
LOG.info("Session expired. Entering neutral mode and rejoining...");
enterNeutralMode();
reJoinElection(0);
break;
case SaslAuthenticated:
LOG.info("Successfully authenticated to ZooKeeper using SASL.");
break;
default:
fatalError("Unexpected Zookeeper watch event state: "
+ event.getState());
break;
}
return;
}
// a watch on lock path in zookeeper has fired. so something has changed on
// the lock. ideally we should check that the path is the same as the lock
// path but trusting zookeeper for now
String path = event.getPath();
if (path != null) {
switch (eventType) {
case NodeDeleted:
if (state == State.ACTIVE) {
enterNeutralMode();
}
joinElectionInternal();
break;
case NodeDataChanged:
monitorActiveStatus();
break;
default:
LOG.debug("Unexpected node event: " + eventType + " for path: " + path);
monitorActiveStatus();
}
return;
}
// some unexpected error has occurred
fatalError("Unexpected watch error from Zookeeper");
}
示例15: process
import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
public void process(WatchedEvent event) {
super.process(event);
if (event.getType() == EventType.None) {
states.add(event);
}
}