use of org.apache.dubbo.registry.NotifyListener in project dubbo by alibaba.
the class AbstractRegistryTest method testUnsubscribeIfUrlNull.
@Test
public void testUnsubscribeIfUrlNull() throws Exception {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false);
NotifyListener listener = urls -> notified.set(Boolean.TRUE);
abstractRegistry.unsubscribe(null, listener);
Assertions.fail("unsubscribe url == null");
});
}
use of org.apache.dubbo.registry.NotifyListener in project dubbo by alibaba.
the class AbstractRegistryTest method testNotify.
/**
* Test method for
* {@link org.apache.dubbo.registry.support.AbstractRegistry#notify(List)}.
*/
@Test
public void testNotify() throws Exception {
final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false);
NotifyListener listener1 = urls -> notified.set(Boolean.TRUE);
URL url1 = new URL("dubbo", "192.168.0.1", 2200, parametersConsumer);
abstractRegistry.subscribe(url1, listener1);
NotifyListener listener2 = urls -> notified.set(Boolean.TRUE);
URL url2 = new URL("dubbo", "192.168.0.2", 2201, parametersConsumer);
abstractRegistry.subscribe(url2, listener2);
NotifyListener listener3 = urls -> notified.set(Boolean.TRUE);
URL url3 = new URL("dubbo", "192.168.0.3", 2202, parametersConsumer);
abstractRegistry.subscribe(url3, listener3);
List<URL> urls = new ArrayList<>();
urls.add(url1);
urls.add(url2);
urls.add(url3);
abstractRegistry.notify(url1, listener1, urls);
Map<URL, Map<String, List<URL>>> map = abstractRegistry.getNotified();
MatcherAssert.assertThat(true, Matchers.equalTo(map.containsKey(url1)));
MatcherAssert.assertThat(false, Matchers.equalTo(map.containsKey(url2)));
MatcherAssert.assertThat(false, Matchers.equalTo(map.containsKey(url3)));
}
use of org.apache.dubbo.registry.NotifyListener in project dubbo by alibaba.
the class AbstractRegistryTest method testNotifyList.
/**
* test notifyList
*/
@Test
public void testNotifyList() throws Exception {
final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false);
NotifyListener listener1 = urls -> notified.set(Boolean.TRUE);
URL url1 = new URL("dubbo", "192.168.0.1", 2200, parametersConsumer);
abstractRegistry.subscribe(url1, listener1);
NotifyListener listener2 = urls -> notified.set(Boolean.TRUE);
URL url2 = new URL("dubbo", "192.168.0.2", 2201, parametersConsumer);
abstractRegistry.subscribe(url2, listener2);
NotifyListener listener3 = urls -> notified.set(Boolean.TRUE);
URL url3 = new URL("dubbo", "192.168.0.3", 2202, parametersConsumer);
abstractRegistry.subscribe(url3, listener3);
List<URL> urls = new ArrayList<>();
urls.add(url1);
urls.add(url2);
urls.add(url3);
abstractRegistry.notify(urls);
Map<URL, Map<String, List<URL>>> map = abstractRegistry.getNotified();
MatcherAssert.assertThat(true, Matchers.equalTo(map.containsKey(url1)));
MatcherAssert.assertThat(true, Matchers.equalTo(map.containsKey(url2)));
MatcherAssert.assertThat(true, Matchers.equalTo(map.containsKey(url3)));
}
use of org.apache.dubbo.registry.NotifyListener in project dubbo by alibaba.
the class MulticastRegistry method unregistered.
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 (CollectionUtils.isEmpty(urls)) {
if (urls == null) {
urls = new ConcurrentHashSet<URL>();
}
URL empty = url.setProtocol(EMPTY_PROTOCOL);
urls.add(empty);
}
List<URL> list = toList(urls);
for (NotifyListener listener : entry.getValue()) {
notify(key, listener, list);
}
}
}
}
use of org.apache.dubbo.registry.NotifyListener in project dubbo by alibaba.
the class MulticastRegistry method registered.
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.computeIfAbsent(key, k -> new ConcurrentHashSet<>());
urls.add(url);
List<URL> list = toList(urls);
for (final NotifyListener listener : entry.getValue()) {
notify(key, listener, list);
synchronized (listener) {
listener.notify();
}
}
}
}
}
Aggregations