本文整理汇总了Java中org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent.Type方法的典型用法代码示例。如果您正苦于以下问题:Java PathChildrenCacheEvent.Type方法的具体用法?Java PathChildrenCacheEvent.Type怎么用?Java PathChildrenCacheEvent.Type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent
的用法示例。
在下文中一共展示了PathChildrenCacheEvent.Type方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDispatcherPropagatesEvents
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入方法依赖的package包/类
@Test
public void testDispatcherPropagatesEvents() throws Exception {
final PathChildrenCacheEvent.Type[] types = new PathChildrenCacheEvent.Type[] {
PathChildrenCacheEvent.Type.CHILD_ADDED,
PathChildrenCacheEvent.Type.CHILD_REMOVED,
PathChildrenCacheEvent.Type.CHILD_UPDATED
};
for (final PathChildrenCacheEvent.Type type:types) {
dispatcher.childEvent(null, new PathChildrenCacheEvent(type, child));
final TransientStoreEvent event = TransientStoreEvent.of(EventDispatcher.MAPPINGS.get(type), key, value);
Mockito
.verify(store)
.fireListeners(event);
}
Assert.assertEquals("Number of event types that dispatcher can handle is different", types.length, EventDispatcher.MAPPINGS.size());
}
示例2: updateNodeStatus
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入方法依赖的package包/类
public String updateNodeStatus(String nodeId, PathChildrenCacheEvent.Type eventType) throws Exception {
String clusterStatus = null;
switch (eventType){
case CHILD_ADDED:
logger.info("ClusterSyncManager Leader: {}. STATUS - Group Initialized: {} ", groupId, nodeId);
clusterNodesStatus.get(NODE_STATUS.INITIALIZED).add(nodeId);
clusterNodesStatus.get(NODE_STATUS.STOPPED).remove(nodeId);
break;
case CHILD_REMOVED:
logger.error("*****ClusterSyncManager Leader: {}. STATUS - Group {} are notified as DOWN *****",
groupId, nodeId);
clusterNodesStatus.get(NODE_STATUS.INITIALIZED).remove(nodeId);
clusterNodesStatus.get(NODE_STATUS.STOPPED).add(nodeId);
break;
}
return updateNodeStatus();
}
示例3: createChildrenCacheEventMock
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入方法依赖的package包/类
/**
* Create mock {@link PathChildrenCacheEvent} object using given controller ID and DPID.
*
* @param controllerId Controller ID.
* @param path HexString of DPID.
* @param type Event type to be set to mock object.
* @return Mock PathChildrenCacheEvent object
*/
private PathChildrenCacheEvent createChildrenCacheEventMock(String controllerId, String path,
PathChildrenCacheEvent.Type type) {
PathChildrenCacheEvent event = createMock(PathChildrenCacheEvent.class);
ChildData data = createMock(ChildData.class);
expect(data.getPath()).andReturn(path).anyTimes();
expect(data.getData()).andReturn(controllerId.getBytes()).anyTimes();
replay(data);
expect(event.getType()).andReturn(type).anyTimes();
expect(event.getData()).andReturn(data).anyTimes();
replay(event);
return event;
}
示例4: childEvent
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入方法依赖的package包/类
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event)
throws Exception {
PathChildrenCacheEvent.Type eventType = event.getType();
switch (eventType) {
case INITIALIZED:
LOG.debug("initailize the service instance list from zookeeper.");
break;
case CHILD_ADDED:
LOG.debug("add new service instance from zookeeper.");
this.addChild(event.getData());
break;
case CHILD_UPDATED:
LOG.debug("update service instance from zookeeper.");
this.addChild(event.getData());
break;
case CONNECTION_RECONNECTED:
this.cache.rebuild();
break;
case CHILD_REMOVED:
case CONNECTION_SUSPENDED:
case CONNECTION_LOST:
LOG.debug("remove service instance from zookeeper.");
this.removeChild(event.getData());
break;
default:
LOG.debug("Ignore PathChildrenCache event : {path:"
+ event.getData().getPath() + " data:"
+ new String(event.getData().getData()) + "}");
}
}
示例5: expectGroupEvent
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入方法依赖的package包/类
final void expectGroupEvent(PathChildrenCacheEvent.Type eventType) {
while (true) {
try {
PathChildrenCacheEvent event = groupEvents.take();
if (event.getType() == eventType) {
break;
}
} catch (InterruptedException ex) {
throw new RuntimeException(ex);
}
}
}
示例6: childEvent
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入方法依赖的package包/类
@Override
public void childEvent(final CuratorFramework client, final PathChildrenCacheEvent event) throws Exception {
final PathChildrenCacheEvent.Type original = event.getType();
final TransientStoreEventType mapped = MAPPINGS.get(original);
if (mapped != null) { // dispatch the event to listeners only if it can be mapped
final String path = event.getData().getPath();
final byte[] bytes = event.getData().getData();
final V value = store.getConfig().getSerializer().deserialize(bytes);
store.fireListeners(TransientStoreEvent.of(mapped, path, value));
}
}
示例7: test_path_cache
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入方法依赖的package包/类
@Test
public void test_path_cache() throws Exception {
CuratorFramework zk = curator.usingNamespace("namespace-test");
String groupPath = "/group-1";
String s = zk.create().forPath(groupPath);
Assert.assertEquals(groupPath, s);
Stat stat = zk.checkExists().forPath("/group-1");
Assert.assertNotNull(stat);
stat = zk.checkExists().forPath("/namespace-test/group-1");
Assert.assertNull(stat);
final PathChildrenCacheEvent.Type[] saveEventType = new PathChildrenCacheEvent.Type[1];
final long[] saveTime = new long[1];
PathChildrenCache pcc = new PathChildrenCache(zk, groupPath, true);
pcc.start();
pcc.getListenable().addListener(new PathChildrenCacheListener() {
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
logger.info("event type={}", event.getType());
switch (event.getType()) {
case CHILD_ADDED:
saveEventType[0] = PathChildrenCacheEvent.Type.CHILD_ADDED;
saveTime[0] = System.currentTimeMillis();
logger.info("child[path={}, date={}] added", event.getData().getPath(), new String(event.getData().getData()));
break;
case CHILD_UPDATED:
saveEventType[0] = PathChildrenCacheEvent.Type.CHILD_UPDATED;
saveTime[0] = System.currentTimeMillis();
logger.info("child[path={}, date={}] updated", event.getData().getPath(), new String(event.getData().getData()));
break;
}
}
});
String hostPath = groupPath + "/localhost:8001";
zk.create().forPath(hostPath);
long wtStart = System.currentTimeMillis();
Thread.sleep(30);
// use 15 ms
// System.out.println("listener wait time="+(saveTime[0] - wtStart));
Assert.assertEquals(PathChildrenCacheEvent.Type.CHILD_ADDED, saveEventType[0]);
// System.out.println(new String(zk.getData().forPath(hostPath)));
// create three node
String threePath = groupPath + "/hosts/localhost:8001";
zk.create().creatingParentsIfNeeded().forPath(threePath);
zk.setData().forPath(threePath, "{tree}".getBytes());
// test update
zk.setData().forPath(hostPath, "{}".getBytes());
Thread.sleep(30);
Assert.assertEquals(PathChildrenCacheEvent.Type.CHILD_UPDATED, saveEventType[0]);
// test set parent node's data
zk.setData().forPath(groupPath, "{grou-data}".getBytes());
Thread.sleep(30);
Assert.assertEquals(PathChildrenCacheEvent.Type.CHILD_UPDATED, saveEventType[0]);
}
示例8: notify
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入方法依赖的package包/类
/** Translating method */
public final void notify(Path path, byte[] data, PathChildrenCacheEvent.Type type) {
String pathString = "/" + path.toString(); // this silly path class strips the leading "/" :-/
PathChildrenCacheEvent event = new PathChildrenCacheEvent(type, new ChildData(pathString, null, data));
notify(path, event);
}