use of com.alibaba.nacos.api.naming.listener.EventListener in project dubbo by alibaba.
the class NacosRegistry method unsubscribeEventListener.
private void unsubscribeEventListener(String serviceName, final URL url, final NotifyListener listener) throws NacosException {
ConcurrentMap<NotifyListener, EventListener> notifyListenerEventListenerConcurrentMap = nacosListeners.get(url);
if (notifyListenerEventListenerConcurrentMap == null) {
return;
}
EventListener nacosListener = notifyListenerEventListenerConcurrentMap.get(listener);
if (nacosListener == null) {
return;
}
namingService.unsubscribe(serviceName, getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP), nacosListener);
}
use of com.alibaba.nacos.api.naming.listener.EventListener in project dubbo by alibaba.
the class NacosRegistry method subscribeEventListener.
private void subscribeEventListener(String serviceName, final URL url, final NotifyListener listener) throws NacosException {
ConcurrentMap<NotifyListener, EventListener> listeners = nacosListeners.computeIfAbsent(url, k -> new ConcurrentHashMap<>());
EventListener nacosListener = listeners.computeIfAbsent(listener, k -> {
EventListener eventListener = event -> {
if (event instanceof NamingEvent) {
NamingEvent e = (NamingEvent) event;
List<Instance> instances = e.getInstances();
if (isServiceNamesWithCompatibleMode(url)) {
// Get all instances with corresponding serviceNames to avoid instance overwrite and but with empty instance mentioned
// in https://github.com/apache/dubbo/issues/5885 and https://github.com/apache/dubbo/issues/5899
NacosInstanceManageUtil.initOrRefreshServiceInstanceList(serviceName, instances);
instances = NacosInstanceManageUtil.getAllCorrespondingServiceInstanceList(serviceName);
}
notifySubscriber(url, listener, instances);
}
};
return eventListener;
});
namingService.subscribe(serviceName, getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP), nacosListener);
}
Aggregations