Return-Path: X-Original-To: apmail-curator-commits-archive@minotaur.apache.org Delivered-To: apmail-curator-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5745717364 for ; Mon, 27 Apr 2015 22:09:54 +0000 (UTC) Received: (qmail 27702 invoked by uid 500); 27 Apr 2015 22:09:54 -0000 Delivered-To: apmail-curator-commits-archive@curator.apache.org Received: (qmail 27627 invoked by uid 500); 27 Apr 2015 22:09:54 -0000 Mailing-List: contact commits-help@curator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@curator.apache.org Delivered-To: mailing list commits@curator.apache.org Received: (qmail 27359 invoked by uid 99); 27 Apr 2015 22:09:54 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Apr 2015 22:09:54 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 031E9E30F6; Mon, 27 Apr 2015 22:09:54 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: randgalt@apache.org To: commits@curator.apache.org Date: Mon, 27 Apr 2015 22:10:03 -0000 Message-Id: In-Reply-To: <6d208746131d46098ce206cdaf8c97d0@git.apache.org> References: <6d208746131d46098ce206cdaf8c97d0@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [11/12] curator git commit: some reformatting 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 Authored: Mon Apr 27 16:07:22 2015 -0500 Committer: randgalt 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 implements ServiceDiscovery Entry 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 implements ServiceDiscovery @Override public void unregisterService(ServiceInstance service) throws Exception { - internalUnregisterService(services.remove(service.getId())); + Entry entry = services.remove(service.getId()); + internalUnregisterService(entry); } /** @@ -445,42 +446,44 @@ public class ServiceDiscoveryImpl implements ServiceDiscovery private NodeCache makeNodeCache(final ServiceInstance 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 newInstance = serializer.deserialize(nodeCache.getCurrentData().getData()); + Entry entry = services.get(newInstance.getId()); + if ( entry != null ) { - ServiceInstance newInstance = serializer.deserialize(nodeCache.getCurrentData().getData()); - Entry 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; }