use of org.apache.dubbo.registry.NotifyListener in project dubbo by alibaba.
the class SimpleRegistryService method disconnect.
public void disconnect() {
String client = RpcContext.getContext().getRemoteAddressString();
if (logger.isInfoEnabled()) {
logger.info("Disconnected " + client);
}
ConcurrentMap<String, URL> urls = remoteRegistered.get(client);
if (urls != null && urls.size() > 0) {
for (Map.Entry<String, URL> entry : urls.entrySet()) {
super.unregister(entry.getKey(), entry.getValue());
}
}
Map<String, NotifyListener> listeners = remoteListeners.get(client);
if (listeners != null && listeners.size() > 0) {
for (Map.Entry<String, NotifyListener> entry : listeners.entrySet()) {
String service = entry.getKey();
super.unsubscribe(service, new URL("subscribe", RpcContext.getContext().getRemoteHost(), RpcContext.getContext().getRemotePort(), RegistryService.class.getName(), getSubscribed(service)), entry.getValue());
}
}
}
use of org.apache.dubbo.registry.NotifyListener in project dubbo by alibaba.
the class AbstractRegistryService method doNotify.
private void doNotify(String service, List<URL> urls) {
notified.put(service, urls);
List<NotifyListener> listeners = notifyListeners.get(service);
if (listeners != null) {
for (NotifyListener listener : listeners) {
try {
notify(service, urls, listener);
} catch (Throwable t) {
logger.error("Failed to notify registry event, service: " + service + ", urls: " + urls + ", cause: " + t.getMessage(), t);
}
}
}
}
use of org.apache.dubbo.registry.NotifyListener in project dubbo by alibaba.
the class MultipleRegistry2S2RTest method testRegistryAndUnRegistry.
@Test
public void testRegistryAndUnRegistry() throws InterruptedException {
URL serviceUrl = URL.valueOf("http2://multiple/" + SERVICE_NAME + "?notify=false&methods=test1,test2&category=providers");
// URL serviceUrl2 = URL.valueOf("http2://multiple2/" + SERVICE_NAME + "?notify=false&methods=test1,test2&category=providers");
multipleRegistry.register(serviceUrl);
String path = "/dubbo/" + SERVICE_NAME + "/providers";
List<String> providerList = zookeeperClient.getChildren(path);
Assertions.assertTrue(!providerList.isEmpty());
System.out.println(providerList.get(0));
Assertions.assertNotNull(MultipleRegistryTestUtil.getRedisHashContent(redisServerPort, path, serviceUrl.toFullString()));
final List<URL> list = new ArrayList<URL>();
multipleRegistry.subscribe(serviceUrl, new NotifyListener() {
@Override
public void notify(List<URL> urls) {
System.out.println("invoke notify: " + urls);
list.clear();
list.addAll(urls);
}
});
Thread.sleep(1500);
Assertions.assertEquals(2, list.size());
multipleRegistry.unregister(serviceUrl);
Thread.sleep(1500);
Assertions.assertEquals(1, list.size());
List<URL> urls = MultipleRegistryTestUtil.getProviderURLsFromNotifyURLS(list);
Assertions.assertEquals(1, list.size());
Assertions.assertEquals("empty", list.get(0).getProtocol());
}
use of org.apache.dubbo.registry.NotifyListener in project dubbo by alibaba.
the class EtcdRegistry method doUnsubscribe.
@Override
public void doUnsubscribe(URL url, NotifyListener listener) {
ConcurrentMap<NotifyListener, ChildListener> listeners = etcdListeners.get(url);
if (listeners != null) {
ChildListener etcdListener = listeners.remove(listener);
if (etcdListener != null) {
if (ANY_VALUE.equals(url.getServiceInterface())) {
String root = toRootPath();
etcdClient.removeChildListener(root, etcdListener);
} else {
// maybe url has many subscribed paths
for (String path : toUnsubscribedPath(url)) {
etcdClient.removeChildListener(path, etcdListener);
}
}
}
if (listeners.isEmpty()) {
etcdListeners.remove(url);
}
}
}
use of org.apache.dubbo.registry.NotifyListener in project dubbo by alibaba.
the class FailbackRegistryTest method testRecover.
@Test
public void testRecover() throws Exception {
CountDownLatch countDownLatch = new CountDownLatch(6);
final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false);
NotifyListener listener = new NotifyListener() {
@Override
public void notify(List<URL> urls) {
notified.set(Boolean.TRUE);
}
};
MockRegistry mockRegistry = new MockRegistry(registryUrl, countDownLatch);
mockRegistry.register(serviceUrl);
mockRegistry.subscribe(serviceUrl, listener);
Assertions.assertEquals(1, mockRegistry.getRegistered().size());
Assertions.assertEquals(1, mockRegistry.getSubscribed().size());
mockRegistry.recover();
countDownLatch.await();
Assertions.assertEquals(0, mockRegistry.getFailedRegistered().size());
FailbackRegistry.Holder h = new FailbackRegistry.Holder(registryUrl, listener);
Assertions.assertNull(mockRegistry.getFailedSubscribed().get(h));
Assertions.assertEquals(countDownLatch.getCount(), 0);
}
Aggregations