Search in sources :

Example 1 with MappingChangedEvent

use of org.apache.dubbo.metadata.MappingChangedEvent in project dubbo by alibaba.

the class ZookeeperMetadataReport method addServiceMappingListener.

private List<String> addServiceMappingListener(String path, String serviceKey, MappingListener listener) {
    ChildListener zkListener = new ChildListener() {

        @Override
        public void childChanged(String path, List<String> children) {
            MappingChangedEvent event = new MappingChangedEvent();
            event.setServiceKey(serviceKey);
            event.setApps(null != children ? new HashSet<>(children) : null);
            listener.onEvent(event);
        }
    };
    List<String> childNodes = zkClient.addChildListener(path, zkListener);
    listenerMap.put(path, zkListener);
    return childNodes;
}
Also used : MappingChangedEvent(org.apache.dubbo.metadata.MappingChangedEvent) ChildListener(org.apache.dubbo.remoting.zookeeper.ChildListener) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 2 with MappingChangedEvent

use of org.apache.dubbo.metadata.MappingChangedEvent in project incubator-dubbo-ops by apache.

the class ZookeeperServiceMapping method notifyMappingChangedEvent.

private void notifyMappingChangedEvent(String service) {
    if (service.equals(Constants.CONFIGURATORS_CATEGORY) || service.equals(Constants.CONSUMERS_CATEGORY) || service.equals(Constants.PROVIDERS_CATEGORY) || service.equals(Constants.ROUTERS_CATEGORY)) {
        return;
    }
    String servicePath = MAPPING_PATH + Constants.PATH_SEPARATOR + service;
    String content = zkClient.getContent(servicePath);
    if (content != null) {
        Set<String> apps = getAppNames(content);
        MappingChangedEvent event = new MappingChangedEvent(service, apps);
        for (MappingListener listener : listeners) {
            listener.onEvent(event);
        }
    }
}
Also used : MappingChangedEvent(org.apache.dubbo.metadata.MappingChangedEvent) MappingListener(org.apache.dubbo.metadata.MappingListener)

Aggregations

MappingChangedEvent (org.apache.dubbo.metadata.MappingChangedEvent)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 MappingListener (org.apache.dubbo.metadata.MappingListener)1 ChildListener (org.apache.dubbo.remoting.zookeeper.ChildListener)1