@Test public void testSubcribe() throws Exception { URL url = new URL(ServiceType.CONSUMER.getLabel(), DemoService.class.getName()); RegistryDirectory registryDirectory = new RegistryDirectory(new DefaultProtocol(), DemoService.class); registry.subscribe(url, registryDirectory); }
@Override public void subscribe(final URL consumerUrl, final NotifyListener notifyListener) throws Exception { ConcurrentMap<NotifyListener, ChildListener> listeners = zkListeners.get(consumerUrl); if (listeners == null) { zkListeners.putIfAbsent(consumerUrl, new ConcurrentHashMap<NotifyListener, ChildListener>()); listeners = zkListeners.get(consumerUrl); } ChildListener childListener = listeners.get(notifyListener); if (childListener == null) { listeners.putIfAbsent(notifyListener, new ChildListener() { @Override public void childChanged(String path, List<String> children) throws Exception { ZookeeperRegistry.this.notify(consumerUrl, notifyListener, toProviderUrls(consumerUrl, children)); } }); childListener = listeners.get(notifyListener); } List<String> children = zookeeperClient.addNodeListener(consumerUrl, childListener); notify(consumerUrl, notifyListener, toProviderUrls(consumerUrl, children)); }
ZookeeperRegistry implements Registry { @Override public void subscribe(final URL consumerUrl, final NotifyListener notifyListener) throws Exception { ConcurrentMap<NotifyListener, ChildListener> listeners = zkListeners.get(consumerUrl); if (listeners == null) { zkListeners.putIfAbsent(consumerUrl, new ConcurrentHashMap<NotifyListener, ChildListener>()); listeners = zkListeners.get(consumerUrl); } ChildListener childListener = listeners.get(notifyListener); if (childListener == null) { listeners.putIfAbsent(notifyListener, new ChildListener() { @Override public void childChanged(String path, List<String> children) throws Exception { ZookeeperRegistry.this.notify(consumerUrl, notifyListener, toProviderUrls(consumerUrl, children)); } }); childListener = listeners.get(notifyListener); } List<String> children = zookeeperClient.addNodeListener(consumerUrl, childListener); notify(consumerUrl, notifyListener, toProviderUrls(consumerUrl, children)); } }
ZookeeperRegistry implements Registry { @Override public void subscribe(final URL consumerUrl, final NotifyListener notifyListener) throws Exception { ConcurrentMap<NotifyListener, ChildListener> listeners = zkListeners.get(consumerUrl); if (listeners == null) { zkListeners.putIfAbsent(consumerUrl, new ConcurrentHashMap<NotifyListener, ChildListener>()); listeners = zkListeners.get(consumerUrl); } ChildListener childListener = listeners.get(notifyListener); if (childListener == null) { listeners.putIfAbsent(notifyListener, new ChildListener() { @Override public void childChanged(String path, List<String> children) throws Exception { ZookeeperRegistry.this.notify(consumerUrl, notifyListener, toProviderUrls(consumerUrl, children)); } }); childListener = listeners.get(notifyListener); } List<String> children = zookeeperClient.addNodeListener(consumerUrl, childListener); notify(consumerUrl, notifyListener, toProviderUrls(consumerUrl, children)); } ZookeeperRegistry(); }
ZookeeperRegistry implements Registry { @Override public void subscribe(final URL consumerUrl, final NotifyListener notifyListener) throws Exception { ConcurrentMap<NotifyListener, ChildListener> listeners = zkListeners.get(consumerUrl); if (listeners == null) { zkListeners.putIfAbsent(consumerUrl, new ConcurrentHashMap<NotifyListener, ChildListener>()); listeners = zkListeners.get(consumerUrl); } ChildListener childListener = listeners.get(notifyListener); if (childListener == null) { listeners.putIfAbsent(notifyListener, new ChildListener() { @Override public void childChanged(String path, List<String> children) throws Exception { ZookeeperRegistry.this.notify(consumerUrl, notifyListener, toProviderUrls(consumerUrl, children)); } }); childListener = listeners.get(notifyListener); } List<String> children = zookeeperClient.addNodeListener(consumerUrl, childListener); notify(consumerUrl, notifyListener, toProviderUrls(consumerUrl, children)); } ZookeeperRegistry(); @Override void register(URL url); @Override void subscribe(final URL consumerUrl, final NotifyListener notifyListener); @Override List<URL> lookup(URL url); void notify(URL consumerURL, NotifyListener listener, List<URL> providerUrls); }
ZookeeperRegistry implements Registry { @Override public void subscribe(final URL consumerUrl, final NotifyListener notifyListener) throws Exception { ConcurrentMap<NotifyListener, ChildListener> listeners = zkListeners.get(consumerUrl); if (listeners == null) { zkListeners.putIfAbsent(consumerUrl, new ConcurrentHashMap<NotifyListener, ChildListener>()); listeners = zkListeners.get(consumerUrl); } ChildListener childListener = listeners.get(notifyListener); if (childListener == null) { listeners.putIfAbsent(notifyListener, new ChildListener() { @Override public void childChanged(String path, List<String> children) throws Exception { ZookeeperRegistry.this.notify(consumerUrl, notifyListener, toProviderUrls(consumerUrl, children)); } }); childListener = listeners.get(notifyListener); } List<String> children = zookeeperClient.addNodeListener(consumerUrl, childListener); notify(consumerUrl, notifyListener, toProviderUrls(consumerUrl, children)); } ZookeeperRegistry(); @Override void register(URL url); @Override void subscribe(final URL consumerUrl, final NotifyListener notifyListener); @Override List<URL> lookup(URL url); void notify(URL consumerURL, NotifyListener listener, List<URL> providerUrls);  }