Java 类org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent 实例源码

项目:mycat-src-1.6.1-RELEASE    文件:BinDataPathChildrenCacheListener.java   
@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;
    }
}
项目:mycat-src-1.6.1-RELEASE    文件:RuleDataPathChildrenCacheListener.java   
@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;
    }
}
项目:GoPush    文件:ZkUtils.java   
/**
     * 设置子节点更改监听
     *
     * @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;
    }
项目:flow-platform    文件:ZoneServiceImpl.java   
@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;
    }
}
项目:dble    文件:DDLChildListener.java   
@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;
    }
}
项目:dble    文件:ViewChildListener.java   
@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;
    }
}
项目:dble    文件:BinDataPathChildrenCacheListener.java   
@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;
    }
}
项目:niubi-job    文件:StandbyNode.java   
@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);
}
项目:niubi-job    文件:StandbyJobSummaryListener.java   
@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);
}
项目:niubi-job    文件:MasterSlaveJobSummaryListener.java   
@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);
}
项目:jrpc    文件:ZookeeperServiceDiscovery.java   
@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;
    }
}
项目:vespa    文件:MockCurator.java   
/** 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;
}
项目:vespa    文件:ZKTenantApplications.java   
@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();
}
项目:drill    文件:TestEventDispatcher.java   
@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());
}
项目:nakadi    文件:EventTypeCache.java   
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);
        }
    }
}
项目:Decision    文件:ClusterPathChildrenCacheListener.java   
@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());
    }

}
项目:Decision    文件:ClusterSyncManager.java   
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();

    }
项目:spring-open    文件:ZookeeperRegistryTest.java   
/**
 * 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;
}
项目:curator-extensions    文件:NodeDiscovery.java   
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
    String nodePath = null;
    T nodeData = null;
    if (event.getData() != null) {
        nodePath = event.getData().getPath();
        nodeData = parseChildData(event.getData());
    }
    switch (event.getType()) {
        case CHILD_ADDED:
            addNode(nodePath, nodeData);
            break;

        case CHILD_REMOVED:
            removeNode(nodePath, nodeData);
            break;

        case CHILD_UPDATED:
            updateNode(nodePath, nodeData);
            break;
    }
}
项目:incubator-sentry    文件:MetastorePluginWithHA.java   
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event)
    throws Exception {
  switch ( event.getType() ) {
  case CHILD_ADDED:
    PathsUpdate newUpdate = new PathsUpdate();
    PluginCacheSyncUtil.setUpdateFromChildEvent(event, newUpdate);
    metastorePlugin.processCacheNotification(newUpdate);
    break;
  case INITIALIZED:
  case CHILD_UPDATED:
  case CHILD_REMOVED:
    break;
  case CONNECTION_RECONNECTED:
    MetastoreAuthzBinding.setSentryCacheOutOfSync(false);
    break;
  case CONNECTION_SUSPENDED:
  case CONNECTION_LOST:
    MetastoreAuthzBinding.setSentryCacheOutOfSync(true);
    break;
  default:
    break;
  }
}
项目:incubator-sentry    文件:UpdateForwarderWithHA.java   
@Override
public synchronized void childEvent(CuratorFramework client,
    PathChildrenCacheEvent event) throws Exception {
  switch ( event.getType() ) {
  case CHILD_ADDED:
    K newUpdate = (K) baseUpdate.getClass().newInstance();
    PluginCacheSyncUtil.setUpdateFromChildEvent(event, newUpdate);
    updateForwarder.postNotificationToLog(newUpdate);
    break;
  case INITIALIZED:
  case CHILD_UPDATED:
  case CHILD_REMOVED:
    break;
  case CONNECTION_RECONNECTED:
    // resume the node
    SentryPlugin.instance.setOutOfSync(false);
    break;
  case CONNECTION_SUSPENDED:
  case CONNECTION_LOST:
    // suspend the node
    SentryPlugin.instance.setOutOfSync(true);
    break;
  default:
    break;
  }
}
项目:fluo    文件:OracleClient.java   
/**
 * It's possible an Oracle has gone into a bad state. Upon the leader being changed, we want to
 * update our state
 */
@Override
public void childEvent(CuratorFramework curatorFramework, PathChildrenCacheEvent event)
    throws Exception {

  if (event.getType().equals(PathChildrenCacheEvent.Type.CHILD_REMOVED)
      || event.getType().equals(PathChildrenCacheEvent.Type.CHILD_ADDED)
      || event.getType().equals(PathChildrenCacheEvent.Type.CHILD_UPDATED)) {

    Participant participant = leaderSelector.getLeader();
    synchronized (this) {
      if (isLeader(participant)) {
        currentLeader = leaderSelector.getLeader();
      } else {
        currentLeader = null;
      }
    }
  }
}
项目:fluo    文件:OracleServer.java   
@Override
public void childEvent(CuratorFramework curatorFramework, PathChildrenCacheEvent event)
    throws Exception {

  try {
    if (isConnected() && (event.getType().equals(PathChildrenCacheEvent.Type.CHILD_ADDED)
        || event.getType().equals(PathChildrenCacheEvent.Type.CHILD_REMOVED)
        || event.getType().equals(PathChildrenCacheEvent.Type.CHILD_UPDATED))) {
      synchronized (this) {
        Participant participant = leaderSelector.getLeader();
        if (isLeader(participant) && !leaderSelector.hasLeadership()) {
          // in case current instance becomes leader, we want to know who came before it.
          currentLeader = participant;
        }
      }
    }
  } catch (InterruptedException e) {
    log.warn("Oracle leadership watcher has been interrupted unexpectedly");
  }
}
项目:bark    文件:ZkGroupMembershipTest.java   
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
    logger.debug("Listener parent path: {} currentData {}",
            new Object[]{event.getData().getPath(), StringSerializer.deserialize(event.getData().getData())});
    switch (event.getType()) {
        case CHILD_ADDED:
            synchronized (this) {
                testGroupMembers.add(event.getData().getPath().substring(
                        event.getData().getPath().lastIndexOf("/")+1));
            }
            barrier.await(10, TimeUnit.SECONDS);
            break;
        case CHILD_REMOVED:
            synchronized (this) {
                testGroupMembers.remove(event.getData().getPath().substring(
                        event.getData().getPath().lastIndexOf("/")+1));
            }
            barrier.await(10, TimeUnit.SECONDS);
            break;
    }

}
项目:redant    文件:DefaultServiceDiscovery.java   
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
    ChildData data = event.getData();
    if(data==null || data.getData()==null){
        return;
    }
    SlaveNode slaveNode = SlaveNode.parse(JSON.parseObject(data.getData(),JSONObject.class));
    if(slaveNode==null){
        LOGGER.error("get a null slaveNode with eventType={},path={},data={}",event.getType(),data.getPath(),data.getData());
    }else {
        switch (event.getType()) {
            case CHILD_ADDED:
                slaveNodeMap.put(slaveNode.getId(), slaveNode);
                LOGGER.info("CHILD_ADDED with path={},data={},current slaveNode size={}", data.getPath(), new String(data.getData(),CharsetUtil.UTF_8),slaveNodeMap.size());
                break;
            case CHILD_REMOVED:
                slaveNodeMap.remove(slaveNode.getId());
                LOGGER.info("CHILD_REMOVED with path={},data={},current slaveNode size={}", data.getPath(), new String(data.getData(),CharsetUtil.UTF_8),slaveNodeMap.size());
                break;
            case CHILD_UPDATED:
                slaveNodeMap.replace(slaveNode.getId(), slaveNode);
                LOGGER.info("CHILD_UPDATED with path={},data={},current slaveNode size={}", data.getPath(), new String(data.getData(),CharsetUtil.UTF_8),slaveNodeMap.size());
                break;
            default:
                break;
        }
    }
}
项目:jigsaw-payment    文件:RefreshableTransportPool.java   
@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()) + "}");
    }
}
项目:consistent_config    文件:ZkConfig.java   
private void _initWatch() throws Exception {
    PathChildrenCache watcher = new PathChildrenCache(
            client,
            STORE_PATH,
            true    // if cache data
    );
    watcher.getListenable().addListener((client1, event) -> {
        try {
            rwlock.writeLock().lock();
            ChildData data = event.getData();
            if (data == null) {
                System.out.println("No data in event[" + event + "]");
            } else {
                System.out.println("Receive event: "
                        + "type=[" + event.getType() + "]"
                        + ", path=[" + data.getPath() + "]"
                        + ", data=[" + new String(data.getData()) + "]"
                        + ", stat=[" + data.getStat() + "]");
                if (event.getType() == PathChildrenCacheEvent.Type.CHILD_ADDED
                        || event.getType() == PathChildrenCacheEvent.Type.CHILD_UPDATED) {
                    String path = data.getPath();
                    if (path.startsWith(STORE_PATH)) {
                        String key = path.replace(STORE_PATH + "/", "");
                        String dataStr = new String(data.getData(), "utf-8");
                        storeMap.put(key, dataStr);
                    }
                }

            }
        }finally {
            rwlock.writeLock().unlock();
        }
    });
    watcher.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);

}
项目:centraldogma    文件:ZooKeeperCommandExecutor.java   
@Override
public void childEvent(CuratorFramework unused, PathChildrenCacheEvent event) throws Exception {
    if (event.getType() != PathChildrenCacheEvent.Type.CHILD_ADDED) {
        return;
    }

    final long lastKnownRevision = revisionFromPath(event.getData().getPath());
    replayLogs(lastKnownRevision);
    oldLogRemover.touch();
}
项目:GoPush    文件:NodeServerDiscoveryService.java   
private void updateEvent(PathChildrenCacheEvent event) {
    String key = toKey(event);
    NodeServerInfo data = toNodeServerInfo(event);
    log.debug("node event update! key:{}, data:{}", key, data);
    //只需要更新缓存数据就可以了
    if (nodeServerPool.containsKey(key)) {
        nodeServerPool.put(key, data);
    }
}
项目:GoPush    文件:NodeServerDiscoveryService.java   
private void removeEvent(PathChildrenCacheEvent event) {
    String key = toKey(event);
    NodeServerInfo data = toNodeServerInfo(event);
    log.info("node event remove! key:{}, data:{}", key, data);
    if (nodeServerPool.containsKey(key)) {
        //检测Node是否还存在,存在的话移除该Node
        nodeManager.remove(key);
        nodeServerPool.remove(key);
    }

}
项目:GoPush    文件:NodeServerDiscoveryService.java   
private void addEvent(PathChildrenCacheEvent event) {
    String key = toKey(event);
    NodeServerInfo data = toNodeServerInfo(event);
    log.info("node event add! key:{}, data:{}", key, data);
    if (!nodeServerPool.containsKey(key)) {
        //开启node,加入到管理器
        nodeManager.put(key, data.getIntranetIp(), data.getNodePort(), data.getInternetIp(), data.getDevicePort());
        nodeServerPool.put(key, data);
    } else {
        log.error("node already! {},{}", key, data);
    }
}
项目:GoPush    文件:MonitorNodeServerService.java   
private void updateEvent(PathChildrenCacheEvent event) {
    String key = toKey(event);
    NodeServerInfo data = toNodeServerInfo(event);
    log.debug(" Monitor node event update! key:{}, data:{}", key, data);
    if (monitorNodeServerPool.containsKey(key)) {
        monitorNodeServerPool.put(key, data);
    }
}
项目:GoPush    文件:MonitorNodeServerService.java   
private void removeEvent(PathChildrenCacheEvent event) {
    String key = toKey(event);
    NodeServerInfo data = toNodeServerInfo(event);
    log.debug(" Monitor node event remove! key:{}, data:{}", key, data);
    if (monitorNodeServerPool.containsKey(key)) {
        monitorNodeServerPool.remove(key);
    }

}
项目:GoPush    文件:MonitorNodeServerService.java   
private void addEvent(PathChildrenCacheEvent event) {
    String key = toKey(event);
    NodeServerInfo data = toNodeServerInfo(event);
    log.debug(" Monitor node event add! key:{}, data:{}", key, data);
    if (!monitorNodeServerPool.containsKey(key)) {
        //开启node,加入到管理器
        monitorNodeServerPool.put(key, data);
    } else {
        log.error(" Monitor node already! {},{}", key, data);
    }
}
项目:GoPush    文件:MonitorDataCenterService.java   
private void updateEvent(PathChildrenCacheEvent event) {
    String key = toKey(event);
    DataCenterInfo data = toDataCenterInfo(event);
    log.debug(" Monitor data center event update! key:{}, data:{}", key, data);
    if (monitorDataCenterPool.containsKey(key)) {
        monitorDataCenterPool.put(key, data);
    }
}
项目:GoPush    文件:MonitorDataCenterService.java   
private void removeEvent(PathChildrenCacheEvent event) {
    String key = toKey(event);
    DataCenterInfo data = toDataCenterInfo(event);
    log.debug(" Monitor data center event remove! key:{}, data:{}", key, data);
    if (monitorDataCenterPool.containsKey(key)) {
        monitorDataCenterPool.remove(key);
    }

}
项目:GoPush    文件:MonitorDataCenterService.java   
private void addEvent(PathChildrenCacheEvent event) {
    String key = toKey(event);
    DataCenterInfo data = toDataCenterInfo(event);
    log.debug(" Monitor data center event add! key:{}, data:{}", key, data);
    if (!monitorDataCenterPool.containsKey(key)) {
        //开启node,加入到管理器
        monitorDataCenterPool.put(key, data);
    } else {
        log.error(" Monitor data center already! {},{}", key, data);
    }
}
项目:Equella    文件:ClusterMessagingServiceImpl.java   
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception
{
    Type type = event.getType();
    if( type.equals(Type.CHILD_ADDED) || type.equals(Type.CHILD_UPDATED) || type.equals(Type.CHILD_REMOVED) )
    {
        String remoteId = ZKPaths.getNodeFromPath(event.getData().getPath());
        String[] clientInfo = new String(event.getData().getData()).split(":");
        if( !isThisNode(remoteId) && !hasSameInfo(clientInfo) )
        {
            if( type.equals(Type.CHILD_ADDED) )
            {
                senders.get(remoteId);
                addReceiver(remoteId, clientInfo);
            }
            else if( type.equals(Type.CHILD_UPDATED) )
            {
                senders.get(remoteId);
                removeReceiver(remoteId);
                addReceiver(remoteId, clientInfo);
            }
            else
            {
                removeReceiver(remoteId);
            }
        }
    }
}
项目:storm-dynamic-spout    文件:ZookeeperWatchTrigger.java   
/**
 * Receives events for this node cache and handles them.
 * @param client curator for interacting with zookeeper.
 * @param event specific event from the node path being watched.
 * @throws Exception most likely something is wrong with the zookeeper connection.
 */
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
    logger.info("Received cache event {}", event);

    if (event == null) {
        logger.warn("Received a null event, this shouldn't happen!");
        return;
    }

    if (event.getType() == null) {
        logger.warn("Received an event, but there was no type, this shouldn't happen!");
        return;
    }

    switch (event.getType()) {
        case INITIALIZED:
            isInitialized = true;
            break;
        case CHILD_ADDED:
        case CHILD_UPDATED:
            if (isInitialized) {
                // Refresh the event from zookeeper, so we have the most current copy
                final TriggerEvent triggerEvent = getTriggerEvent(event.getData().getData());

                handleSidelining(event.getData().getPath(), triggerEvent);
            }
            break;
        case CHILD_REMOVED:
        case CONNECTION_SUSPENDED:
        case CONNECTION_RECONNECTED:
        case CONNECTION_LOST:
            break;
        default:
            logger.info("Unidentified event {}", event);
            break;
    }
}
项目:redirector    文件:CustomServiceCache.java   
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
    try {
        super.childEvent(client, event); // throws Exception
    } catch (Exception e) {
        log.error("Issue receiving ZkEventType={} for zkStackPath={}", event.getType(), stackPath, e);
    } finally {
        if (EVENTS_TO_LISTEN.contains(event.getType())) {
            switch (event.getType()) {
                case CHILD_REMOVED:
                    eventFromClient(event.getData().getPath(), getInstances(), Action.UNREGISTERED);
                    break;
                case INITIALIZED:
                    List<String> paths = new ArrayList<>();
                    List<ChildData> childData = getCache().getCurrentData();
                    if (CollectionUtils.isNotEmpty(childData)) {
                        for (ChildData data : childData) {
                            paths.add(data.getPath());
                        }
                    }
                    log.info("Dynamic Service Discovery cache for {} is initialized. Stacks.json will be written of FS", stackPath);
                    eventFromClient(paths, getInstances(), Action.INITIALIZED);
                    break;
                default:
                    eventFromClient(event.getData().getPath(), getInstances(), Action.REGISTERED);
            }
        }
    }
}