use of org.apache.zookeeper.Watcher.Event.EventType in project pinpoint by naver.
the class ZookeeperUtils method isConnectedEvent.
public static boolean isConnectedEvent(WatchedEvent event) {
KeeperState state = event.getState();
EventType eventType = event.getType();
return isConnectedEvent(state, eventType);
}
use of org.apache.zookeeper.Watcher.Event.EventType in project pinpoint by naver.
the class ZookeeperUtils method isDisconnectedEvent.
public static boolean isDisconnectedEvent(WatchedEvent event) {
KeeperState state = event.getState();
EventType eventType = event.getType();
return isDisconnectedEvent(state, eventType);
}
use of org.apache.zookeeper.Watcher.Event.EventType in project pinpoint by naver.
the class ZookeeperClusterDataManager method process.
@SuppressWarnings("deprecation")
@Override
public void process(WatchedEvent event) {
logger.info("Handle Zookeeper Event({}) started.", event);
KeeperState state = event.getState();
EventType eventType = event.getType();
String path = event.getPath();
// when this happens, ephemeral node disappears
// reconnects automatically, and process gets notified for all events
boolean result = false;
if (state == KeeperState.SyncConnected || state == KeeperState.NoSyncConnected) {
if (eventType == EventType.NodeChildrenChanged) {
result = handleNodeChildrenChanged(path);
} else if (eventType == EventType.NodeDeleted) {
result = handleNodeDeleted(path);
} else if (eventType == EventType.NodeDataChanged) {
result = handleNodeDataChanged(path);
}
}
if (result) {
logger.info("Handle Zookeeper Event({}) completed.", event);
} else {
logger.info("Handle Zookeeper Event({}) failed.", event);
}
}
use of org.apache.zookeeper.Watcher.Event.EventType in project zookeeper by apache.
the class WatchedEventTest method testCreatingWatchedEvent.
@Test
public void testCreatingWatchedEvent() {
// EventWatch is a simple, immutable type, so all we need to do
// is make sure we can create all possible combinations of values.
EnumSet<EventType> allTypes = EnumSet.allOf(EventType.class);
EnumSet<KeeperState> allStates = EnumSet.allOf(KeeperState.class);
WatchedEvent we;
for (EventType et : allTypes) {
for (KeeperState ks : allStates) {
we = new WatchedEvent(et, ks, "blah");
assertEquals(et, we.getType());
assertEquals(ks, we.getState());
assertEquals("blah", we.getPath());
}
}
}
use of org.apache.zookeeper.Watcher.Event.EventType in project zookeeper by apache.
the class RemoveWatchesCmdTest method verifyRemoveAnyWatches.
private void verifyRemoveAnyWatches(boolean local) throws Exception {
final Map<String, List<EventType>> pathVsEvent = new HashMap<>();
LOG.info("Adding NodeChildrenChanged, NodeDataChanged watchers");
final CountDownLatch watcherLatch = new CountDownLatch(2);
Watcher watcher = new Watcher() {
@Override
public void process(WatchedEvent event) {
switch(event.getType()) {
case ChildWatchRemoved:
case DataWatchRemoved:
addWatchNotifications(pathVsEvent, event);
watcherLatch.countDown();
break;
case NodeChildrenChanged:
case NodeDataChanged:
addWatchNotifications(pathVsEvent, event);
break;
}
}
private void addWatchNotifications(Map<String, List<EventType>> pathVsEvent, WatchedEvent event) {
pathVsEvent.computeIfAbsent(event.getPath(), k -> new ArrayList<>()).add(event.getType());
}
};
zk.create("/testnode1", "data".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.getChildren("/testnode1", watcher);
zk.getData("/testnode1", watcher, null);
String cmdstring = "removewatches /testnode1 -a";
if (local) {
LOG.info("Stopping ZK server to verify deletion of watches locally");
stopServer();
cmdstring = "removewatches /testnode1 -a -l";
}
LOG.info("Remove watchers using shell command : {}", cmdstring);
zkMain.cl.parseCommand(cmdstring);
assertTrue(zkMain.processZKCmd(zkMain.cl), "Removewatches cmd fails to remove child/data watches");
LOG.info("Waiting for the WatchRemoved events");
watcherLatch.await(10, TimeUnit.SECONDS);
assertEquals(1, pathVsEvent.size(), "Didn't receives WatchRemoved events!");
assertTrue(pathVsEvent.get("/testnode1").contains(EventType.DataWatchRemoved), "Didn't receives DataWatchRemoved!");
assertTrue(pathVsEvent.get("/testnode1").contains(EventType.ChildWatchRemoved), "Didn't receives ChildWatchRemoved!");
}
Aggregations