Making Connection erros less verbose. Only first error is logged with
error level; subsequent errors are logged as debug

Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/ab3ff72d
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/ab3ff72d
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/ab3ff72d

Branch: refs/heads/CURATOR-105
Commit: ab3ff72d309378f3c6e166e47e75b7ba49835f20
Parents: 0f7acf7
Author: eceejcr <evaristojo...@yahoo.es>
Authored: Fri May 2 23:53:40 2014 +0200
Committer: eceejcr <evaristojo...@yahoo.es>
Committed: Fri May 2 23:53:40 2014 +0200

----------------------------------------------------------------------
 .../framework/imps/CuratorFrameworkImpl.java    | 29 +++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/ab3ff72d/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
----------------------------------------------------------------------
diff --git 
a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
 
b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
index 7854308..d6a5973 100644
--- 
a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
+++ 
b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
@@ -51,6 +51,7 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 
 public class CuratorFrameworkImpl implements CuratorFramework
@@ -72,6 +73,7 @@ public class CuratorFrameworkImpl implements CuratorFramework
     private final NamespaceWatcherMap                                   
namespaceWatcherMap = new NamespaceWatcherMap(this);
 
     private volatile ExecutorService                                    
executorService;
+    private AtomicBoolean                                               
logAsErrorConnectionErrors = new AtomicBoolean(false);
 
     interface DebugBackgroundListener
     {
@@ -231,7 +233,19 @@ public class CuratorFrameworkImpl implements 
CuratorFramework
         try
         {
             connectionStateManager.start(); // ordering dependency - must be 
called before client.start()
+            ConnectionStateListener listener = new ConnectionStateListener() {
+                               @Override
+                               public void stateChanged(CuratorFramework 
client, ConnectionState newState) {
+                                       if ( ConnectionState.CONNECTED == 
newState || ConnectionState.RECONNECTED == newState )
+                                       {
+                                               
logAsErrorConnectionErrors.set(true);
+                                       }
+                               }
+                       };
+                       
this.getConnectionStateListenable().addListener(listener);
+
             client.start();
+
             executorService = Executors.newFixedThreadPool(2, threadFactory);  
// 1 for listeners, 1 for background ops
 
             executorService.submit
@@ -509,7 +523,20 @@ public class CuratorFrameworkImpl implements 
CuratorFramework
 
         if ( 
!Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES) || !(e 
instanceof KeeperException) )
         {
-            log.error(reason, e);
+            if ( e instanceof KeeperException.ConnectionLossException || e 
instanceof CuratorConnectionLossException ) {
+                if ( logAsErrorConnectionErrors.compareAndSet(true, false) )
+                {
+                    log.error(reason, e);
+                }
+                else
+                {
+                    log.debug(reason, e);
+                }
+            }
+            else
+            {
+                log.error(reason, e);
+            }
         }
 
         final String        localReason = reason;

Reply via email to