当前位置: 首页>>代码示例>>Java>>正文


Java PathChildrenCacheEvent类代码示例

本文整理汇总了Java中org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent的典型用法代码示例。如果您正苦于以下问题:Java PathChildrenCacheEvent类的具体用法?Java PathChildrenCacheEvent怎么用?Java PathChildrenCacheEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PathChildrenCacheEvent类属于org.apache.curator.framework.recipes.cache包,在下文中一共展示了PathChildrenCacheEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: childEvent

import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入依赖的package包/类
@Override public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
    ChildData data = event.getData();
    switch (event.getType()) {

        case CHILD_ADDED:

            add(data.getPath().substring(data.getPath().lastIndexOf("/")+1),event.getData().getData()) ;
            break;
        case CHILD_REMOVED:
            delete(data.getPath().substring(data.getPath().lastIndexOf("/")+1),event.getData().getData()); ;
            break;
        case CHILD_UPDATED:
            add(data.getPath().substring(data.getPath().lastIndexOf("/")+1),event.getData().getData()) ;
            break;
        default:
            break;
    }
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:19,代码来源:BinDataPathChildrenCacheListener.java

示例2: listenerPathChildrenCache

import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入依赖的package包/类
/**
     * 设置子节点更改监听
     *
     * @param path
     * @throws Exception
     */
    public boolean listenerPathChildrenCache(String path, BiConsumer<CuratorFramework, PathChildrenCacheEvent> biConsumer) {

        if (!ObjectUtils.allNotNull(zkClient, path, biConsumer)) {
            return Boolean.FALSE;
        }
        try {
            Stat stat = exists(path);
            if (stat != null) {
                PathChildrenCache watcher = new PathChildrenCache(zkClient, path, true);
                watcher.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
                //该模式下 watcher在重连的时候会自动 rebuild 否则需要重新rebuild
                watcher.getListenable().addListener(biConsumer::accept, pool);
                if (!pathChildrenCaches.contains(watcher)) {
                    pathChildrenCaches.add(watcher);
                }
//                else{
//                    watcher.rebuild();
//                }
                return Boolean.TRUE;
            }
        } catch (Exception e) {
            log.error("listen path children cache fail! path:{} , error:{}", path, e);
        }
        return Boolean.FALSE;
    }
 
开发者ID:lee123lee123,项目名称:GoPush,代码行数:32,代码来源:ZkUtils.java

示例3: childEvent

import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入依赖的package包/类
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
    final Type eventType = event.getType();
    final String path = event.getData().getPath();
    final String name = ZKHelper.getNameFromPath(path);
    LOGGER.debugMarker("ZoneEventListener", "Receive zookeeper event %s %s", eventType, path);

    if (eventType == Type.CHILD_ADDED || eventType == Type.CHILD_UPDATED) {
        agentService.report(new AgentPath(zone.getName(), name), AgentStatus.IDLE);
        return;
    }

    if (eventType == Type.CHILD_REMOVED) {
        agentService.report(new AgentPath(zone.getName(), name), AgentStatus.OFFLINE);
        return;
    }
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:18,代码来源:ZoneServiceImpl.java

示例4: childEvent

import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入依赖的package包/类
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
    ChildData childData = event.getData();
    switch (event.getType()) {
        case CHILD_ADDED:
            try {
                lockTableByNewNode(childData);
            } catch (Exception e) {
                LOGGER.info("CHILD_ADDED error", e);
            }
            break;
        case CHILD_UPDATED:
            updateMeta(childData);
            break;
        case CHILD_REMOVED:
            deleteNode(childData);
            break;
        default:
            break;
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:22,代码来源:DDLChildListener.java

示例5: childEvent

import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入依赖的package包/类
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
    ChildData childData = event.getData();
    switch (event.getType()) {
        case CHILD_ADDED:
            createOrUpdateViewMeta(childData, false);
            break;
        case CHILD_UPDATED:
            createOrUpdateViewMeta(childData, true);
            break;
        case CHILD_REMOVED:
            deleteNode(childData);
            break;
        default:
            break;
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:18,代码来源:ViewChildListener.java

示例6: childEvent

import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入依赖的package包/类
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
    ChildData data = event.getData();
    switch (event.getType()) {
        case CHILD_ADDED:
            add(data, false);
            break;
        case CHILD_UPDATED:
            add(data, true);
            break;
        case CHILD_REMOVED:
            delete(data);
            break;
        default:
            break;
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:18,代码来源:BinDataPathChildrenCacheListener.java

示例7: childEvent

import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入依赖的package包/类
@Override
public synchronized void childEvent(CuratorFramework curatorFramework, PathChildrenCacheEvent event) throws Exception {
    AssertHelper.isTrue(isJoined(), "illegal state .");
    boolean hasLeadership = leaderSelector != null && leaderSelector.hasLeadership();
    if (!hasLeadership) {
        return;
    }
    if (!EventHelper.isChildModifyEvent(event)) {
        return;
    }
    StandbyJobData standbyJobData = new StandbyJobData(event.getData());
    if (StringHelper.isEmpty(standbyJobData.getData().getJobOperation())) {
        return;
    }
    StandbyJobData.Data data = standbyJobData.getData();
    if (data.isUnknownOperation()) {
        return;
    }
    StandbyNodeData.Data nodeData = standbyApiFactory.nodeApi().getNode(nodePath).getData();
    executeOperation(nodeData, data);
}
 
开发者ID:xiaolongzuo,项目名称:niubi-job,代码行数:22,代码来源:StandbyNode.java

示例8: listen

import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入依赖的package包/类
@PostConstruct
public void listen() throws Exception {
    StandbyApiFactory standbyApiFactory = new StandbyApiFactoryImpl(client);
    PathChildrenCache pathChildrenCache = new PathChildrenCache(client, standbyApiFactory.pathApi().getJobPath(), true);
    pathChildrenCache.getListenable().addListener(new PathChildrenCacheListener() {
        @Override
        public synchronized void childEvent(CuratorFramework clientInner, PathChildrenCacheEvent event) throws Exception {
            if (!EventHelper.isChildUpdateEvent(event) && !EventHelper.isChildAddEvent(event)) {
                return;
            }
            StandbyJobData standbyJobData = new StandbyJobData(event.getData());
            if (!standbyJobData.getData().isOperated()) {
                return;
            }
            LoggerHelper.info("begin update standby job summary " + standbyJobData.getData());
            standbyJobSummaryService.updateJobSummary(standbyJobData.getData());
            standbyJobLogService.updateJobLog(standbyJobData.getData());
            LoggerHelper.info("update standby job summary successfully " + standbyJobData.getData());
        }
    });
    pathChildrenCache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
}
 
开发者ID:xiaolongzuo,项目名称:niubi-job,代码行数:23,代码来源:StandbyJobSummaryListener.java

示例9: listen

import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入依赖的package包/类
@PostConstruct
public void listen() throws Exception {
    MasterSlaveApiFactory masterSlaveApiFactory = new MasterSlaveApiFactoryImpl(client);
    PathChildrenCache pathChildrenCache = new PathChildrenCache(client, masterSlaveApiFactory.pathApi().getJobPath(), true);
    pathChildrenCache.getListenable().addListener(new PathChildrenCacheListener() {
        @Override
        public synchronized void childEvent(CuratorFramework clientInner, PathChildrenCacheEvent event) throws Exception {
            if (!EventHelper.isChildUpdateEvent(event) && !EventHelper.isChildAddEvent(event)) {
                return;
            }
            MasterSlaveJobData masterSlaveJobData = new MasterSlaveJobData(event.getData());
            if (!masterSlaveJobData.getData().isOperated()) {
                return;
            }
            LoggerHelper.info("begin update master-slave job summary " + masterSlaveJobData.getData());
            masterSlaveJobSummaryService.updateJobSummary(masterSlaveJobData.getData());
            masterSlaveJobLogService.updateJobLog(masterSlaveJobData.getData());
            LoggerHelper.info("update master-slave job summary successfully " + masterSlaveJobData.getData());
        }
    });
    pathChildrenCache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
}
 
开发者ID:xiaolongzuo,项目名称:niubi-job,代码行数:23,代码来源:MasterSlaveJobSummaryListener.java

示例10: childEvent

import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入依赖的package包/类
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
    switch (event.getType()) {
        case CHILD_ADDED:
        case CHILD_UPDATED: {
            addProvider(event.getData(), false);
            break;
        }

        case CHILD_REMOVED: {
            providers.remove(ZKPaths.getNodeFromPath(event.getData().getPath()));
            break;
        }
        default:
            break;
    }
}
 
开发者ID:dinstone,项目名称:jrpc,代码行数:18,代码来源:ZookeeperServiceDiscovery.java

示例11: createNode

import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入依赖的package包/类
/** Creates a node below the given directory root */
private String createNode(String pathString, byte[] content, boolean createParents, CreateMode createMode, Node root, Listeners listeners)
        throws KeeperException.NodeExistsException, KeeperException.NoNodeException {
    validatePath(pathString);
    Path path = Path.fromString(pathString);
    if (path.isRoot()) return "/"; // the root already exists
    Node parent = root.getNode(Paths.get(path.getParentPath().toString()), createParents);
    String name = nodeName(path.getName(), createMode);

    if (parent == null)
        throw new KeeperException.NoNodeException(path.getParentPath().toString());
    if (parent.children().containsKey(path.getName()))
        throw new KeeperException.NodeExistsException(path.toString());

    parent.add(name).setContent(content);
    String nodePath = "/" + path.getParentPath().toString() + "/" + name;
    listeners.notify(Path.fromString(nodePath), content, PathChildrenCacheEvent.Type.CHILD_ADDED);
    return nodePath;
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:20,代码来源:MockCurator.java

示例12: childEvent

import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入依赖的package包/类
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
    switch (event.getType()) {
        case CHILD_ADDED:
            applicationAdded(ApplicationId.fromSerializedForm(Path.fromString(event.getData().getPath()).getName()));
            break;
        // Event CHILD_REMOVED will be triggered on all config servers if deleteApplication() above is called on one of them
        case CHILD_REMOVED:
            applicationRemoved(ApplicationId.fromSerializedForm(Path.fromString(event.getData().getPath()).getName()));
            break;
        case CHILD_UPDATED:
            // do nothing, application just got redeployed
            break;
        default:
            break;
    }
    // We might have lost events and might need to remove applications (new applications are
    // not added by listening for events here, they are added when session is added, see RemoteSessionRepo)
    removeApplications();
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:21,代码来源:ZKTenantApplications.java

示例13: 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());
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:20,代码来源:TestEventDispatcher.java

示例14: onZkEvent

import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入依赖的package包/类
private void onZkEvent(final PathChildrenCacheEvent event) {
    // Lock is needed only to support massive load on startup. In all other cases it will be called for
    // event type creation/update, so it won't create any additional load.
    String invalidatedEventType = null;
    rwLock.readLock().lock();
    try {
        final boolean needInvalidate = event.getType() == PathChildrenCacheEvent.Type.CHILD_UPDATED ||
                event.getType() == PathChildrenCacheEvent.Type.CHILD_REMOVED ||
                event.getType() == PathChildrenCacheEvent.Type.CHILD_ADDED;
        if (needInvalidate) {
            final String[] path = event.getData().getPath().split("/");
            invalidatedEventType = path[path.length - 1];
            eventTypeCache.invalidate(invalidatedEventType);
        }
    } finally {
        rwLock.readLock().unlock();
    }
    if (null != invalidatedEventType) {
        for (final Consumer<String> listener : invalidationListeners) {
            listener.accept(invalidatedEventType);
        }
    }
}
 
开发者ID:zalando,项目名称:nakadi,代码行数:24,代码来源:EventTypeCache.java

示例15: childEvent

import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; //导入依赖的package包/类
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception
{
    String node;
    String nodeId;

    try {
        node = ZKPaths.getNodeFromPath(event.getData().getPath());
        nodeId = node.substring(node.indexOf("_") + 1);

        clusterSyncManagerInstance.updateNodeStatus(nodeId, event.getType());

    }catch (Exception e){
        logger.error("Exception receiving event {}: {}", event, e.getMessage());
    }

}
 
开发者ID:Stratio,项目名称:Decision,代码行数:18,代码来源:ClusterPathChildrenCacheListener.java


注:本文中的org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。