Here are the examples of the java api org.apache.dubbo.registry.NotifyListener taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
115 Examples
19
Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz
with Apache License 2.0
from mercyblitz
/**
* Get the service names from the specified {@link URL url}
*
* @param url {@link URL}
* @param listener {@link NotifyListener}
* @return non-null
*/
private Set<String> getServiceNames(URL url, NotifyListener listener) {
if (isAdminProtocol(url)) {
scheduleServiceNamesLookup(url, listener);
return getServiceNamesForOps(url);
} else {
return getServiceNames0(url);
}
}
19
Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz
with Apache License 2.0
from mercyblitz
@Override
public void doUnsubscribe(URL url, NotifyListener listener) {
if (isAdminProtocol(url)) {
shutdownServiceNamesLookup();
}
}
19
Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz
with Apache License 2.0
from mercyblitz
/**
* Notify the Healthy {@link Instance instances} to subscriber.
*
* @param url {@link URL}
* @param listener {@link NotifyListener}
* @param instances all {@link Instance instances}
*/
private void notifySubscriber(URL url, NotifyListener listener, Collection<Instance> instances) {
List<Instance> healthyInstances = new LinkedList<>(instances);
if (healthyInstances.size() > 0) {
// Healthy Instances
filterHealthyInstances(healthyInstances);
}
List<URL> urls = toUrlWithEmpty(url, healthyInstances);
NacosRegistry.this.notify(url, listener, urls);
}
19
Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz
with Apache License 2.0
from mercyblitz
private void scheduleServiceNamesLookup(final URL url, final NotifyListener listener) {
if (scheduledExecutorService == null) {
scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
scheduledExecutorService.scheduleAtFixedRate(() -> {
Set<String> serviceNames = getAllServiceNames();
filterData(serviceNames, serviceName -> {
boolean accepted = false;
for (String category : ALL_SUPPORTED_CATEGORIES) {
String prefix = category + SERVICE_NAME_SEPARATOR;
if (serviceName != null && serviceName.startsWith(prefix)) {
accepted = true;
break;
}
}
return accepted;
});
doSubscribe(url, listener, serviceNames);
}, LOOKUP_INTERVAL, LOOKUP_INTERVAL, TimeUnit.SECONDS);
}
}
19
Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz
with Apache License 2.0
from mercyblitz
@Override
public void doSubscribe(final URL url, final NotifyListener listener) {
Set<String> serviceNames = getServiceNames(url, listener);
// Set corresponding serviceNames for easy search later
if (isServiceNamesWithCompatibleMode(url)) {
for (String serviceName : serviceNames) {
NacosInstanceManageUtil.setCorrespondingServiceNames(serviceName, serviceNames);
}
}
doSubscribe(url, listener, serviceNames);
}
19
Source : MulticastRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
protected void registered(URL url) {
for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
URL key = entry.getKey();
if (UrlUtils.isMatch(key, url)) {
Set<URL> urls = received.get(key);
if (urls == null) {
received.putIfAbsent(key, new ConcurrentHashSet<URL>());
urls = received.get(key);
}
urls.add(url);
List<URL> list = toList(urls);
for (NotifyListener listener : entry.getValue()) {
notify(key, listener, list);
synchronized (listener) {
listener.notify();
}
}
}
}
}
19
Source : MulticastRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
@Override
public void unsubscribe(URL url, NotifyListener listener) {
super.unsubscribe(url, listener);
received.remove(url);
}
19
Source : MulticastRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
@Override
public void doUnsubscribe(URL url, NotifyListener listener) {
if (!Constants.ANY_VALUE.equals(url.getServiceInterface()) && url.getParameter(Constants.REGISTER_KEY, true)) {
unregister(url);
}
multicast(Constants.UNSUBSCRIBE + " " + url.toFullString());
}
19
Source : MulticastRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
protected void subscribed(URL url, NotifyListener listener) {
List<URL> urls = lookup(url);
notify(url, listener, urls);
}
19
Source : MulticastRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
@Override
public void subscribe(URL url, NotifyListener listener) {
super.subscribe(url, listener);
subscribed(url, listener);
}
19
Source : AbstractRegistryService.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
public void unsubscribe(String service, URL url, NotifyListener listener) {
if (service == null) {
throw new IllegalArgumentException("service == null");
}
if (url == null) {
throw new IllegalArgumentException("parameters == null");
}
if (listener == null) {
throw new IllegalArgumentException("listener == null");
}
subscribed.remove(service);
removeListener(service, listener);
}
19
Source : DubboRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
@Override
public void doSubscribe(URL url, NotifyListener listener) {
registryService.subscribe(url, listener);
}
19
Source : DubboRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
@Override
public void doUnsubscribe(URL url, NotifyListener listener) {
registryService.unsubscribe(url, listener);
}
19
Source : FailbackRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
@Override
public void subscribe(URL url, NotifyListener listener) {
super.subscribe(url, listener);
removeFailedSubscribed(url, listener);
try {
// Sending a subscription request to the server side
doSubscribe(url, listener);
} catch (Exception e) {
Throwable t = e;
List<URL> urls = getCacheUrls(url);
if (CollectionUtils.isNotEmpty(urls)) {
notify(url, listener, urls);
logger.error("Failed to subscribe " + url + ", Using cached list: " + urls + " from cache file: " + getUrl().getParameter(Constants.FILE_KEY, System.getProperty("user.home") + "/dubbo-registry-" + url.getHost() + ".cache") + ", cause: " + t.getMessage(), t);
} else {
// If the startup detection is opened, the Exception is thrown directly.
boolean check = getUrl().getParameter(Constants.CHECK_KEY, true) && url.getParameter(Constants.CHECK_KEY, true);
boolean skipFailback = t instanceof SkipFailbackWrapperException;
if (check || skipFailback) {
if (skipFailback) {
t = t.getCause();
}
throw new IllegalStateException("Failed to subscribe " + url + ", cause: " + t.getMessage(), t);
} else {
logger.error("Failed to subscribe " + url + ", waiting for retry, cause: " + t.getMessage(), t);
}
}
// Record a failed registration request to a failed list, retry regularly
addFailedSubscribed(url, listener);
}
}
19
Source : FailbackRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
private void addFailedSubscribed(URL url, NotifyListener listener) {
Holder h = new Holder(url, listener);
FailedSubscribedTask oldOne = failedSubscribed.get(h);
if (oldOne != null) {
return;
}
FailedSubscribedTask newTask = new FailedSubscribedTask(url, this, listener);
oldOne = failedSubscribed.putIfAbsent(h, newTask);
if (oldOne == null) {
// never has a retry task. then start a new task for retry.
retryTimer.newTimeout(newTask, retryPeriod, TimeUnit.MILLISECONDS);
}
}
19
Source : FailbackRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
protected void doNotify(URL url, NotifyListener listener, List<URL> urls) {
super.notify(url, listener, urls);
}
19
Source : FailbackRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
public void removeFailedSubscribedTask(URL url, NotifyListener listener) {
Holder h = new Holder(url, listener);
failedSubscribed.remove(h);
}
19
Source : FailbackRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
private void addFailedUnsubscribed(URL url, NotifyListener listener) {
Holder h = new Holder(url, listener);
FailedUnsubscribedTask oldOne = failedUnsubscribed.get(h);
if (oldOne != null) {
return;
}
FailedUnsubscribedTask newTask = new FailedUnsubscribedTask(url, this, listener);
oldOne = failedUnsubscribed.putIfAbsent(h, newTask);
if (oldOne == null) {
// never has a retry task. then start a new task for retry.
retryTimer.newTimeout(newTask, retryPeriod, TimeUnit.MILLISECONDS);
}
}
19
Source : FailbackRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
@Override
public void unsubscribe(URL url, NotifyListener listener) {
super.unsubscribe(url, listener);
removeFailedSubscribed(url, listener);
try {
// Sending a canceling subscription request to the server side
doUnsubscribe(url, listener);
} catch (Exception e) {
Throwable t = e;
// If the startup detection is opened, the Exception is thrown directly.
boolean check = getUrl().getParameter(Constants.CHECK_KEY, true) && url.getParameter(Constants.CHECK_KEY, true);
boolean skipFailback = t instanceof SkipFailbackWrapperException;
if (check || skipFailback) {
if (skipFailback) {
t = t.getCause();
}
throw new IllegalStateException("Failed to unsubscribe " + url + " to registry " + getUrl().getAddress() + ", cause: " + t.getMessage(), t);
} else {
logger.error("Failed to unsubscribe " + url + ", waiting for retry, cause: " + t.getMessage(), t);
}
// Record a failed registration request to a failed list, retry regularly
addFailedUnsubscribed(url, listener);
}
}
19
Source : FailbackRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
public void removeFailedNotifiedTask(URL url, NotifyListener listener) {
Holder h = new Holder(url, listener);
failedNotified.remove(h);
}
19
Source : FailbackRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
@Override
protected void notify(URL url, NotifyListener listener, List<URL> urls) {
if (url == null) {
throw new IllegalArgumentException("notify url == null");
}
if (listener == null) {
throw new IllegalArgumentException("notify listener == null");
}
try {
doNotify(url, listener, urls);
} catch (Exception t) {
// Record a failed registration request to a failed list, retry regularly
addFailedNotified(url, listener, urls);
logger.error("Failed to notify for subscribe " + url + ", waiting for retry, cause: " + t.getMessage(), t);
}
}
19
Source : FailbackRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
private void removeFailedNotified(URL url, NotifyListener listener) {
Holder h = new Holder(url, listener);
FailedNotifiedTask f = failedNotified.remove(h);
if (f != null) {
f.cancel();
}
}
19
Source : FailbackRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
@Override
protected void recover() throws Exception {
// register
Set<URL> recoverRegistered = new HashSet<URL>(getRegistered());
if (!recoverRegistered.isEmpty()) {
if (logger.isInfoEnabled()) {
logger.info("Recover register url " + recoverRegistered);
}
for (URL url : recoverRegistered) {
addFailedRegistered(url);
}
}
// subscribe
Map<URL, Set<NotifyListener>> recoverSubscribed = new HashMap<URL, Set<NotifyListener>>(getSubscribed());
if (!recoverSubscribed.isEmpty()) {
if (logger.isInfoEnabled()) {
logger.info("Recover subscribe url " + recoverSubscribed.keySet());
}
for (Map.Entry<URL, Set<NotifyListener>> entry : recoverSubscribed.entrySet()) {
URL url = entry.getKey();
for (NotifyListener listener : entry.getValue()) {
addFailedSubscribed(url, listener);
}
}
}
}
19
Source : FailbackRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
public void removeFailedUnsubscribedTask(URL url, NotifyListener listener) {
Holder h = new Holder(url, listener);
failedUnsubscribed.remove(h);
}
19
Source : FailbackRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
private void addFailedNotified(URL url, NotifyListener listener, List<URL> urls) {
Holder h = new Holder(url, listener);
FailedNotifiedTask newTask = new FailedNotifiedTask(url, listener);
FailedNotifiedTask f = failedNotified.putIfAbsent(h, newTask);
if (f == null) {
// never has a retry task. then start a new task for retry.
newTask.addUrlToRetry(urls);
retryTimer.newTimeout(newTask, retryPeriod, TimeUnit.MILLISECONDS);
} else {
// just add urls which needs retry.
newTask.addUrlToRetry(urls);
}
}
19
Source : FailedUnsubscribedTask.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
/**
* FailedUnsubscribedTask
*/
public final clreplaced FailedUnsubscribedTask extends AbstractRetryTask {
private static final String NAME = "retry unsubscribe";
private final NotifyListener listener;
public FailedUnsubscribedTask(URL url, FailbackRegistry registry, NotifyListener listener) {
super(url, registry, NAME);
if (listener == null) {
throw new IllegalArgumentException();
}
this.listener = listener;
}
@Override
protected void doRetry(URL url, FailbackRegistry registry, Timeout timeout) {
registry.unsubscribe(url, listener);
registry.removeFailedUnsubscribedTask(url, listener);
}
}
19
Source : FailedSubscribedTask.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
/**
* FailedSubscribedTask
*/
public final clreplaced FailedSubscribedTask extends AbstractRetryTask {
private static final String NAME = "retry subscribe";
private final NotifyListener listener;
public FailedSubscribedTask(URL url, FailbackRegistry registry, NotifyListener listener) {
super(url, registry, NAME);
if (listener == null) {
throw new IllegalArgumentException();
}
this.listener = listener;
}
@Override
protected void doRetry(URL url, FailbackRegistry registry, Timeout timeout) {
registry.doSubscribe(url, listener);
registry.removeFailedSubscribedTask(url, listener);
}
}
19
Source : SofaRegistry.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Override
public void doSubscribe(URL url, final NotifyListener listener) {
if (!url.getParameter(SUBSCRIBE_KEY, true) || PROVIDER_PROTOCOL.equals(url.getProtocol())) {
return;
}
String serviceName = buildServiceName(url);
// com.alipay.test.TestService:1.0:group@dubbo
Subscriber listSubscriber = subscribers.get(serviceName);
if (listSubscriber != null) {
LOGGER.warn("Service name [" + serviceName + "] have bean registered in SOFARegistry.");
CountDownLatch countDownLatch = new CountDownLatch(1);
handleRegistryData(listSubscriber.peekData(), listener, countDownLatch);
waitAddress(serviceName, countDownLatch);
return;
}
final CountDownLatch latch = new CountDownLatch(1);
SubscriberRegistration subscriberRegistration = new SubscriberRegistration(serviceName, (dataId, data) -> {
// record change
printAddressData(dataId, data);
handleRegistryData(data, listener, latch);
});
addAttributesForSub(subscriberRegistration);
listSubscriber = registryClient.register(subscriberRegistration);
subscribers.put(serviceName, listSubscriber);
waitAddress(serviceName, latch);
}
19
Source : EtcdRegistry.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Override
public void doUnsubscribe(URL url, NotifyListener listener) {
ConcurrentMap<NotifyListener, ChildListener> listeners = etcdListeners.get(url);
if (listeners != null) {
ChildListener etcdListener = listeners.get(listener);
if (etcdListener != null) {
// maybe url has many subscribed paths
for (String path : toUnsubscribedPath(url)) {
etcdClient.removeChildListener(path, etcdListener);
}
}
}
}
19
Source : DubboCloudRegistry.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
private void subscribeDubboMetadataServiceURLs(URL subscribedURL, NotifyListener listener, String serviceName) {
String serviceInterface = subscribedURL.getServiceInterface();
String version = subscribedURL.getParameter(VERSION_KEY);
String protocol = subscribedURL.getParameter(PROTOCOL_KEY);
List<ServiceInstance> serviceInstances = getServiceInstances(serviceName);
List<URL> urls = dubboMetadataUtils.getDubboMetadataServiceURLs(serviceInstances, serviceInterface, version, protocol);
notifyAllSubscribedURLs(subscribedURL, urls, listener);
}
19
Source : DubboCloudRegistry.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
private void subscribeURLs(URL url, Set<String> serviceNames, NotifyListener listener) {
List<URL> subscribedURLs = new LinkedList<>();
serviceNames.forEach(serviceName -> {
subscribeURLs(url, subscribedURLs, serviceName, () -> getServiceInstances(serviceName));
});
// Notify all
notifyAllSubscribedURLs(url, subscribedURLs, listener);
}
19
Source : DubboCloudRegistry.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
private void subscribeDubboMetadataServiceURLs(URL subscribedURL, NotifyListener listener) {
// Sync subscription
subscribeDubboMetadataServiceURLs(subscribedURL, listener, getServiceName(subscribedURL));
// Sync subscription
if (containsProviderCategory(subscribedURL)) {
registerServiceInstancesChangedListener(subscribedURL, new ApplicationListener<ServiceInstancesChangedEvent>() {
private final URL url2subscribe = subscribedURL;
@Override
@Order(Ordered.LOWEST_PRECEDENCE - 1)
public void onApplicationEvent(ServiceInstancesChangedEvent event) {
String sourceServiceName = event.getServiceName();
String serviceName = getServiceName(subscribedURL);
if (Objects.equals(sourceServiceName, serviceName)) {
subscribeDubboMetadataServiceURLs(subscribedURL, listener, sourceServiceName);
}
}
@Override
public String toString() {
return "ServiceInstancesChangedEventListener:" + subscribedURL.getServiceKey();
}
});
}
}
19
Source : DubboCloudRegistry.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
private void subscribeURLs(URL url, NotifyListener listener) {
// Sync subscription
subscribeURLs(url, getServices(url), listener);
// Async subscription
registerServiceInstancesChangedListener(url, new ApplicationListener<ServiceInstancesChangedEvent>() {
private final URL url2subscribe = url;
@Override
@Order
public void onApplicationEvent(ServiceInstancesChangedEvent event) {
Set<String> serviceNames = getServices(url);
String serviceName = event.getServiceName();
if (serviceNames.contains(serviceName)) {
subscribeURLs(url, serviceNames, listener);
}
}
@Override
public String toString() {
return "ServiceInstancesChangedEventListener:" + url.getServiceKey();
}
});
}
19
Source : DubboCloudRegistry.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
@Override
public final void doUnsubscribe(URL url, NotifyListener listener) {
// TODO
}
19
Source : DubboCloudRegistry.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
@Override
public final void doSubscribe(URL url, NotifyListener listener) {
if (isAdminURL(url)) {
// TODO in future
if (logger.isWarnEnabled()) {
logger.warn("This feature about admin will be supported in the future.");
}
} else if (isDubboMetadataServiceURL(url)) {
// for DubboMetadataService
subscribeDubboMetadataServiceURLs(url, listener);
} else {
// for general Dubbo Services
subscribeURLs(url, listener);
}
}
19
Source : AbstractSpringCloudRegistry.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
/**
* Register a {@link ApplicationListener listener} for
* {@link ServiceInstancesChangedEvent}.
* @param url {@link URL}
* @param listener {@link NotifyListener}
*/
private void registerServiceInstancesChangedEventListener(URL url, NotifyListener listener) {
String listenerId = generateId(url);
if (REGISTER_LISTENERS.add(listenerId)) {
applicationContext.addApplicationListener(new ApplicationListener<ServiceInstancesChangedEvent>() {
@Override
public void onApplicationEvent(ServiceInstancesChangedEvent event) {
String serviceName = event.getServiceName();
Collection<ServiceInstance> serviceInstances = event.getServiceInstances();
subscribeDubboServiceURL(url, listener, serviceName, s -> serviceInstances);
}
});
}
}
19
Source : AbstractSpringCloudRegistry.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
private void subscribeDubboMetadataServiceURLs(URL url, NotifyListener listener) {
List<URL> urls = repository.findSubscribedDubboMetadataServiceURLs(url);
listener.notify(urls);
}
19
Source : AbstractSpringCloudRegistry.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
protected void subscribeDubboServiceURLs(URL url, NotifyListener listener) {
doSubscribeDubboServiceURLs(url, listener);
registerServiceInstancesChangedEventListener(url, listener);
}
19
Source : AbstractSpringCloudRegistry.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
@Override
public final void doSubscribe(URL url, NotifyListener listener) {
if (isAdminURL(url)) {
// TODO in future
} else if (isDubboMetadataServiceURL(url)) {
// for DubboMetadataService
subscribeDubboMetadataServiceURLs(url, listener);
if (from(url).getParameter(CATEGORY_KEY) != null && from(url).getParameter(CATEGORY_KEY).contains(PROVIDER)) {
// Fix #1259 and #753 Listene meta service change events to remove useless
// clients
registerServiceInstancesChangedEventListener(url, listener);
}
} else {
// for general Dubbo Services
subscribeDubboServiceURLs(url, listener);
}
}
19
Source : AbstractSpringCloudRegistry.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
@Override
public final void doUnsubscribe(URL url, NotifyListener listener) {
// if (isAdminURL(url)) {
// }
}
18
Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz
with Apache License 2.0
from mercyblitz
private void subscribeEventListener(String serviceName, final URL url, final NotifyListener listener) throws NacosException {
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);
}
};
namingService.subscribe(serviceName, eventListener);
}
18
Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz
with Apache License 2.0
from mercyblitz
private void doSubscribe(final URL url, final NotifyListener listener, final Set<String> serviceNames) {
execute(namingService -> {
if (isServiceNamesWithCompatibleMode(url)) {
List<Instance> allCorrespondingInstanceList = Lists.newArrayList();
/**
* Get all instances with 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
*/
for (String serviceName : serviceNames) {
List<Instance> instances = namingService.getAllInstances(serviceName);
NacosInstanceManageUtil.initOrRefreshServiceInstanceList(serviceName, instances);
allCorrespondingInstanceList.addAll(instances);
}
notifySubscriber(url, listener, allCorrespondingInstanceList);
for (String serviceName : serviceNames) {
subscribeEventListener(serviceName, url, listener);
}
} else {
List<Instance> instances = new LinkedList();
for (String serviceName : serviceNames) {
instances.addAll(namingService.getAllInstances(serviceName));
notifySubscriber(url, listener, instances);
subscribeEventListener(serviceName, url, listener);
}
}
});
}
18
Source : NewSubscriberEvent.java
with Apache License 2.0
from huaweicloud
with Apache License 2.0
from huaweicloud
public clreplaced NewSubscriberEvent extends ApplicationEvent {
private static final long serialVersionUID = 1L;
private final URL url;
private final NotifyListener notifyListener;
public NewSubscriberEvent(URL url, NotifyListener notifyListener) {
super(url);
this.url = url;
this.notifyListener = notifyListener;
}
public URL getUrl() {
return url;
}
public NotifyListener getNotifyListener() {
return notifyListener;
}
}
18
Source : ZookeeperRegistryTest.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
@Test
public void testSubscribe() {
NotifyListener listener = mock(NotifyListener.clreplaced);
zookeeperRegistry.subscribe(serviceUrl, listener);
Map<URL, Set<NotifyListener>> subscribed = zookeeperRegistry.getSubscribed();
replacedertThat(subscribed.size(), is(1));
replacedertThat(subscribed.get(serviceUrl).size(), is(1));
zookeeperRegistry.unsubscribe(serviceUrl, listener);
subscribed = zookeeperRegistry.getSubscribed();
replacedertThat(subscribed.size(), is(1));
replacedertThat(subscribed.get(serviceUrl).size(), is(0));
}
18
Source : ZookeeperRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
@Override
public void doUnsubscribe(URL url, NotifyListener listener) {
ConcurrentMap<NotifyListener, ChildListener> listeners = zkListeners.get(url);
if (listeners != null) {
ChildListener zkListener = listeners.get(listener);
if (zkListener != null) {
if (Constants.ANY_VALUE.equals(url.getServiceInterface())) {
String root = toRootPath();
zkClient.removeChildListener(root, zkListener);
} else {
for (String path : toCategoriesPath(url)) {
zkClient.removeChildListener(path, zkListener);
}
}
}
}
}
18
Source : ZookeeperRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
@Override
public void doSubscribe(final URL url, final NotifyListener listener) {
try {
if (Constants.ANY_VALUE.equals(url.getServiceInterface())) {
String root = toRootPath();
ConcurrentMap<NotifyListener, ChildListener> listeners = zkListeners.get(url);
if (listeners == null) {
zkListeners.putIfAbsent(url, new ConcurrentHashMap<>());
listeners = zkListeners.get(url);
}
ChildListener zkListener = listeners.get(listener);
if (zkListener == null) {
listeners.putIfAbsent(listener, (parentPath, currentChilds) -> {
for (String child : currentChilds) {
child = URL.decode(child);
if (!anyServices.contains(child)) {
anyServices.add(child);
subscribe(url.setPath(child).addParameters(Constants.INTERFACE_KEY, child, Constants.CHECK_KEY, String.valueOf(false)), listener);
}
}
});
zkListener = listeners.get(listener);
}
zkClient.create(root, false);
List<String> services = zkClient.addChildListener(root, zkListener);
if (CollectionUtils.isNotEmpty(services)) {
for (String service : services) {
service = URL.decode(service);
anyServices.add(service);
subscribe(url.setPath(service).addParameters(Constants.INTERFACE_KEY, service, Constants.CHECK_KEY, String.valueOf(false)), listener);
}
}
} else {
List<URL> urls = new ArrayList<>();
for (String path : toCategoriesPath(url)) {
ConcurrentMap<NotifyListener, ChildListener> listeners = zkListeners.get(url);
if (listeners == null) {
zkListeners.putIfAbsent(url, new ConcurrentHashMap<>());
listeners = zkListeners.get(url);
}
ChildListener zkListener = listeners.get(listener);
if (zkListener == null) {
listeners.putIfAbsent(listener, (parentPath, currentChilds) -> ZookeeperRegistry.this.notify(url, listener, toUrlsWithEmpty(url, parentPath, currentChilds)));
zkListener = listeners.get(listener);
}
zkClient.create(path, false);
List<String> children = zkClient.addChildListener(path, zkListener);
if (children != null) {
urls.addAll(toUrlsWithEmpty(url, path, children));
}
}
// 把现有的动态配置触发一下,urls就是动态配置orverride
notify(url, listener, urls);
}
} catch (Throwable e) {
throw new RpcException("Failed to subscribe " + url + " to zookeeper " + getUrl() + ", cause: " + e.getMessage(), e);
}
}
18
Source : RedisRegistryTest.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
@Test
public void testSubscribeAndUnsubscribe() {
NotifyListener listener = new NotifyListener() {
@Override
public void notify(List<URL> urls) {
}
};
redisRegistry.subscribe(serviceUrl, listener);
Map<URL, Set<NotifyListener>> subscribed = redisRegistry.getSubscribed();
replacedertThat(subscribed.size(), is(1));
replacedertThat(subscribed.get(serviceUrl).size(), is(1));
redisRegistry.unsubscribe(serviceUrl, listener);
subscribed = redisRegistry.getSubscribed();
replacedertThat(subscribed.get(serviceUrl).size(), is(0));
}
18
Source : RedisRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
@Override
public void doUnsubscribe(URL url, NotifyListener listener) {
}
18
Source : MulticastRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
protected void unregistered(URL url) {
for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
URL key = entry.getKey();
if (UrlUtils.isMatch(key, url)) {
Set<URL> urls = received.get(key);
if (urls != null) {
urls.remove(url);
}
if (urls == null || urls.isEmpty()) {
if (urls == null) {
urls = new ConcurrentHashSet<URL>();
}
URL empty = url.setProtocol(Constants.EMPTY_PROTOCOL);
urls.add(empty);
}
List<URL> list = toList(urls);
for (NotifyListener listener : entry.getValue()) {
notify(key, listener, list);
}
}
}
}
18
Source : MulticastRegistry.java
with Apache License 2.0
from boomblog
with Apache License 2.0
from boomblog
@Override
public void doSubscribe(URL url, NotifyListener listener) {
if (Constants.ANY_VALUE.equals(url.getServiceInterface())) {
admin = true;
}
multicast(Constants.SUBSCRIBE + " " + url.toFullString());
synchronized (listener) {
try {
listener.wait(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
} catch (InterruptedException e) {
}
}
}
See More Examples