Search in sources :

Example 1 with MappingListener

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

the class ConfigCenter method getServiceMapping.

@Bean
@DependsOn("metaDataCollector")
ServiceMapping getServiceMapping(ServiceDiscovery serviceDiscovery, InstanceRegistryCache instanceRegistryCache) {
    ServiceMapping serviceMapping = new NoOpServiceMapping();
    if (metadataUrl == null) {
        return serviceMapping;
    }
    MappingListener mappingListener = new AdminMappingListener(serviceDiscovery, instanceRegistryCache);
    serviceMapping = ExtensionLoader.getExtensionLoader(ServiceMapping.class).getExtension(metadataUrl.getProtocol());
    serviceMapping.addMappingListener(mappingListener);
    serviceMapping.init(metadataUrl);
    return serviceMapping;
}
Also used : NoOpServiceMapping(org.apache.dubbo.admin.registry.mapping.impl.NoOpServiceMapping) ServiceMapping(org.apache.dubbo.admin.registry.mapping.ServiceMapping) NoOpServiceMapping(org.apache.dubbo.admin.registry.mapping.impl.NoOpServiceMapping) AdminMappingListener(org.apache.dubbo.admin.registry.mapping.AdminMappingListener) AdminMappingListener(org.apache.dubbo.admin.registry.mapping.AdminMappingListener) MappingListener(org.apache.dubbo.metadata.MappingListener) DependsOn(org.springframework.context.annotation.DependsOn) Bean(org.springframework.context.annotation.Bean)

Example 2 with MappingListener

use of org.apache.dubbo.metadata.MappingListener 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

MappingListener (org.apache.dubbo.metadata.MappingListener)2 AdminMappingListener (org.apache.dubbo.admin.registry.mapping.AdminMappingListener)1 ServiceMapping (org.apache.dubbo.admin.registry.mapping.ServiceMapping)1 NoOpServiceMapping (org.apache.dubbo.admin.registry.mapping.impl.NoOpServiceMapping)1 MappingChangedEvent (org.apache.dubbo.metadata.MappingChangedEvent)1 Bean (org.springframework.context.annotation.Bean)1 DependsOn (org.springframework.context.annotation.DependsOn)1