Java Code Examples for org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent#Type

The following examples show how to use org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent#Type . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CuratorClientService.java    From knox with Apache License 2.0 6 votes vote down vote up
private ChildEntryListener.Type adaptType(PathChildrenCacheEvent.Type type) {
    ChildEntryListener.Type adapted = null;

    switch(type) {
        case CHILD_ADDED:
            adapted = ChildEntryListener.Type.ADDED;
            break;
        case CHILD_REMOVED:
            adapted = ChildEntryListener.Type.REMOVED;
            break;
        case CHILD_UPDATED:
            adapted = ChildEntryListener.Type.UPDATED;
            break;
    }

    return adapted;
}
 
Example 2
Source File: ClusterSyncManager.java    From Decision with Apache License 2.0 6 votes vote down vote up
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();

    }
 
Example 3
Source File: EventDispatcher.java    From Bats with Apache License 2.0 5 votes vote down vote up
@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));
  }
}
 
Example 4
Source File: ServiceListener.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Override
protected void dataChanged(String path, PathChildrenCacheEvent.Type eventType, String data) {
    if (eventType == PathChildrenCacheEvent.Type.CHILD_ADDED || eventType == PathChildrenCacheEvent.Type.CHILD_REMOVED || eventType == PathChildrenCacheEvent.Type.CHILD_UPDATED) {
        try {
            PathUtil.rebalance(registryCenter, registryConfig, changeListener, servicePath);
        } catch (Exception e) {
            logger.error("Zookeeper service listener failed ", e);
        }
    }
}
 
Example 5
Source File: RefListener.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Override
protected void dataChanged(String path, PathChildrenCacheEvent.Type eventType, String data) {
    if (eventType == PathChildrenCacheEvent.Type.CHILD_UPDATED) {
        try {
            String host = PathUtil.getHostByPath(path);
            if (Strings.isNullOrEmpty(host) || !host.equals(refHost) || Strings.isNullOrEmpty(data)) {
                return;
            }
            this.changeListener.refChange(registryConfig, MergeConfig.decode(data));
        } catch (Exception e) {
            logger.error("Zookeeper service listener failed ", e);
        }
    }
}
 
Example 6
Source File: RefreshableTransportPool.java    From jigsaw-payment with Apache License 2.0 5 votes vote down vote up
@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()) + "}");
    }
}
 
Example 7
Source File: ZookeeperPathChildrenCacheListener.java    From Thunder with Apache License 2.0 5 votes vote down vote up
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
    PathChildrenCacheEvent.Type type = event.getType();
    switch (type) {
        case INITIALIZED:
            initialized(event);
            break;
        case CHILD_ADDED:
            childAdded(event);
            break;
        case CHILD_UPDATED:
            childUpdated(event);
            break;
        case CHILD_REMOVED:
            childRemoved(event);
            break;
        case CONNECTION_SUSPENDED:
            connectionSuspended(event);
            break;
        case CONNECTION_RECONNECTED:
            connectionReconnected(event);
            break;
        case CONNECTION_LOST:
            connectionLost(event);
            break;
    }
}
 
Example 8
Source File: BaseCuratorDiscoveryTest.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
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);
    }
  }
}
 
Example 9
Source File: MockCurator.java    From vespa with Apache License 2.0 4 votes vote down vote up
/** 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);
}
 
Example 10
Source File: AbstractChildrenDataListener.java    From eagle with Apache License 2.0 votes vote down vote up
protected abstract void dataChanged(final String path, final PathChildrenCacheEvent.Type eventType, final String data);