本文整理汇总了Java中org.apache.zookeeper.Watcher.Event.EventType类的典型用法代码示例。如果您正苦于以下问题:Java EventType类的具体用法?Java EventType怎么用?Java EventType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EventType类属于org.apache.zookeeper.Watcher.Event包,在下文中一共展示了EventType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processDataOrChildChange
import org.apache.zookeeper.Watcher.Event.EventType; //导入依赖的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);
}
}
}
示例2: setData
import org.apache.zookeeper.Watcher.Event.EventType; //导入依赖的package包/类
public Stat setData(String path, byte data[], int version, long zxid,
long time) throws KeeperException.NoNodeException {
Stat s = new Stat();
DataNode n = nodes.get(path);
if (n == null) {
throw new KeeperException.NoNodeException();
}
byte lastdata[] = null;
synchronized (n) {
lastdata = n.data;
n.data = data;
n.stat.setMtime(time);
n.stat.setMzxid(zxid);
n.stat.setVersion(version);
n.copyStat(s);
}
// now update if the path is in a quota subtree.
String lastPrefix;
if((lastPrefix = getMaxPrefixWithQuota(path)) != null) {
this.updateBytes(lastPrefix, (data == null ? 0 : data.length)
- (lastdata == null ? 0 : lastdata.length));
}
dataWatches.triggerWatch(path, EventType.NodeDataChanged);
return s;
}
示例3: process
import org.apache.zookeeper.Watcher.Event.EventType; //导入依赖的package包/类
@Override
public void process(WatchedEvent event) {
ZooKeeper zkClient = zookeeperConnManager.getZkClient();
try {
/* 重新注册节点 */
zkClient.exists(nodePath, this);
EventType eventType = event.getType();
switch (eventType) {
case NodeDeleted:
election();
break;
default:
break;
}
} catch (Exception e) {
log.error("error", e);
}
}
示例4: process
import org.apache.zookeeper.Watcher.Event.EventType; //导入依赖的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: testNodeCreated
import org.apache.zookeeper.Watcher.Event.EventType; //导入依赖的package包/类
@Test
public void testNodeCreated() throws Exception {
QuorumUtil qu = new QuorumUtil(1);
qu.startAll();
EventsWatcher watcher = new EventsWatcher();
ZooKeeper zk1 = createClient(qu, 1, watcher);
ZooKeeper zk2 = createClient(qu, 2);
String path = "/test1-created";
zk1.exists(path, watcher);
qu.shutdown(1);
zk2.create(path, new byte[2], ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
qu.start(1);
watcher.waitForConnected(TIMEOUT * 1000L);
watcher.assertEvent(TIMEOUT, EventType.NodeCreated);
qu.shutdownAll();
}
示例6: process
import org.apache.zookeeper.Watcher.Event.EventType; //导入依赖的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: testNodeChildrenChanged
import org.apache.zookeeper.Watcher.Event.EventType; //导入依赖的package包/类
@Test
public void testNodeChildrenChanged() throws Exception {
QuorumUtil qu = new QuorumUtil(1);
qu.startAll();
EventsWatcher watcher = new EventsWatcher();
ZooKeeper zk1 = createClient(qu, 1, watcher);
ZooKeeper zk2 = createClient(qu, 2);
String path = "/test-children-changed";
zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
zk1.getChildren(path, watcher);
qu.shutdown(1);
zk2.create(path + "/children-1", new byte[2],
ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
qu.start(1);
watcher.waitForConnected(TIMEOUT * 1000L);
watcher.assertEvent(TIMEOUT, EventType.NodeChildrenChanged);
qu.shutdownAll();
}
示例8: process
import org.apache.zookeeper.Watcher.Event.EventType; //导入依赖的package包/类
public void process(WatchedEvent event) {
if (!closed) {
try {
if (event.getType() != EventType.NodeDeleted) {
Stat s = zooKeeper.exists(nodePath, this);
if (s != null) {
zookeeper.getChildren(nodePath, this);
}
}
} catch (Exception e) {
LoggerFactory.getLogger().error(
"Error occured re-adding node watcherfor node "
+ nodePath, e);
}
nodeListener.processEvent(event.getPath(), event.getType()
.name(), null);
}
}
示例9: processDataOrChildChange
import org.apache.zookeeper.Watcher.Event.EventType; //导入依赖的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);
}
}
}
示例10: queueEvent
import org.apache.zookeeper.Watcher.Event.EventType; //导入依赖的package包/类
private void queueEvent(WatchedEvent event,
Set<Watcher> materializedWatchers) {
if (event.getType() == EventType.None
&& sessionState == event.getState()) {
return;
}
sessionState = event.getState();
final Set<Watcher> watchers;
if (materializedWatchers == null) {
// materialize the watchers based on the event
watchers = watcher.materialize(event.getState(),
event.getType(), event.getPath());
} else {
watchers = new HashSet<Watcher>();
watchers.addAll(materializedWatchers);
}
WatcherSetEventPair pair = new WatcherSetEventPair(watchers, event);
// queue the pair (watch set & event) for later processing
waitingEvents.add(pair);
}
示例11: process
import org.apache.zookeeper.Watcher.Event.EventType; //导入依赖的package包/类
public void process(WatchedEvent event) {
if (!closed) {
try {
if (event.getType() != EventType.NodeDeleted) {
Stat s = zooKeeper.exists(nodePath, this);
if (s != null) {
zookeeper.getChildren(nodePath, this);
}
}
} catch (Exception e) {
LoggerFactory.getLogger().error(
"Error occurred re-adding node watcherfor node "
+ nodePath, e);
}
nodeListener.processEvent(event.getPath(), event.getType()
.name(), null);
}
}
示例12: testRemoveNodeChildrenChangedWatches
import org.apache.zookeeper.Watcher.Event.EventType; //导入依赖的package包/类
/**
* Test verifies deletion of NodeChildrenChanged watches
*/
@Test(timeout = 30000)
public void testRemoveNodeChildrenChangedWatches() throws Exception {
List<EventType> expectedEvents = new ArrayList<Watcher.Event.EventType>();
expectedEvents.add(EventType.ChildWatchRemoved);
MyWatcher myWatcher = new MyWatcher("/testnode1", expectedEvents, 1);
zk.create("/testnode1", "data".getBytes(), Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
LOG.info("Adding child changed watcher");
zk.getChildren("/testnode1", myWatcher);
String cmdstring = "removewatches /testnode1 -c";
LOG.info("Remove watchers using shell command : {}", cmdstring);
zkMain.cl.parseCommand(cmdstring);
Assert.assertTrue("Removewatches cmd fails to remove child watches",
zkMain.processZKCmd(zkMain.cl));
myWatcher.matches();
Assert.assertEquals(
"Failed to remove child watches : " + zk.getChildWatches(), 0,
zk.getChildWatches().size());
}
示例13: processDataOrChildChange
import org.apache.zookeeper.Watcher.Event.EventType; //导入依赖的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);
}
}
}
示例14: setData
import org.apache.zookeeper.Watcher.Event.EventType; //导入依赖的package包/类
public Stat setData(String path, byte data[], int version, long zxid,
long time) throws KeeperException.NoNodeException {
Stat s = new Stat();
DataNodeV1 n = nodes.get(path);
if (n == null) {
throw new KeeperException.NoNodeException();
}
synchronized (n) {
n.data = data;
n.stat.setMtime(time);
n.stat.setMzxid(zxid);
n.stat.setVersion(version);
n.copyStat(s);
}
dataWatches.triggerWatch(path, EventType.NodeDataChanged);
return s;
}
示例15: process
import org.apache.zookeeper.Watcher.Event.EventType; //导入依赖的package包/类
@Override
public void process(WatchedEvent event) {
if (event.getType() == EventType.NodeDataChanged) {
synchronized(this) {
changed = true;
notifyAll();
}
}
}