some reformatting
Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/8b250ccd Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/8b250ccd Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/8b250ccd Branch: refs/heads/master Commit: 8b250ccd60d1536a930cf4102b36fa0098ed486a Parents: 03879d1 Author: randgalt <randg...@apache.org> Authored: Mon Apr 27 16:07:22 2015 -0500 Committer: randgalt <randg...@apache.org> Committed: Mon Apr 27 16:07:22 2015 -0500 ---------------------------------------------------------------------- .../discovery/details/ServiceDiscoveryImpl.java | 63 ++++++++++---------- 1 file changed, 33 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/8b250ccd/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java ---------------------------------------------------------------------- diff --git a/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java b/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java index 7b2a9ec..7b0bffe 100644 --- a/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java +++ b/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java @@ -195,7 +195,7 @@ public class ServiceDiscoveryImpl<T> implements ServiceDiscovery<T> Entry<T> entry = services.get(service.getId()); if ( entry == null ) { - throw new Exception("Service has been unregistered: " + service); + throw new Exception("Service not registered: " + service); } synchronized(entry) { @@ -238,7 +238,8 @@ public class ServiceDiscoveryImpl<T> implements ServiceDiscovery<T> @Override public void unregisterService(ServiceInstance<T> service) throws Exception { - internalUnregisterService(services.remove(service.getId())); + Entry<T> entry = services.remove(service.getId()); + internalUnregisterService(entry); } /** @@ -445,42 +446,44 @@ public class ServiceDiscoveryImpl<T> implements ServiceDiscovery<T> private NodeCache makeNodeCache(final ServiceInstance<T> instance) { - final NodeCache nodeCache = watchInstances ? new NodeCache(client, pathForInstance(instance.getName(), instance.getId())) : null; - if ( nodeCache != null ) + if ( !watchInstances ) { - try - { - nodeCache.start(true); - } - catch ( Exception e ) - { - log.error("Could not start node cache for: " + instance, e); - } - NodeCacheListener listener = new NodeCacheListener() + return null; + } + + final NodeCache nodeCache = new NodeCache(client, pathForInstance(instance.getName(), instance.getId())); + try + { + nodeCache.start(true); + } + catch ( Exception e ) + { + log.error("Could not start node cache for: " + instance, e); + } + NodeCacheListener listener = new NodeCacheListener() + { + @Override + public void nodeChanged() throws Exception { - @Override - public void nodeChanged() throws Exception + if ( nodeCache.getCurrentData() != null ) { - if ( nodeCache.getCurrentData() != null ) + ServiceInstance<T> newInstance = serializer.deserialize(nodeCache.getCurrentData().getData()); + Entry<T> entry = services.get(newInstance.getId()); + if ( entry != null ) { - ServiceInstance<T> newInstance = serializer.deserialize(nodeCache.getCurrentData().getData()); - Entry<T> entry = services.get(newInstance.getId()); - if ( entry != null ) + synchronized(entry) { - synchronized(entry) - { - entry.service = newInstance; - } + entry.service = newInstance; } } - else - { - log.warn("Instance data has been deleted for: " + instance); - } } - }; - nodeCache.getListenable().addListener(listener); - } + else + { + log.warn("Instance data has been deleted for: " + instance); + } + } + }; + nodeCache.getListenable().addListener(listener); return nodeCache; }