You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2014/05/20 17:32:04 UTC

[02/13] git commit: Added System property to choose if connection issues are always logged as error level or only first issue is logged as error level, and subsequent issues are logged as debug. By default only first issue is logged as error

Added System property to choose if connection issues are always logged
as error level or only first issue is logged as error level, and
subsequent issues are logged as debug. By default only first issue is
logged as error

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

Branch: refs/heads/CURATOR-96
Commit: 048688a36856d1ef7e080410b8818952210fb1e8
Parents: ab3ff72
Author: eceejcr <ec...@E7B499BAE9DDE0.ericsson.se>
Authored: Sun May 11 01:05:03 2014 +0200
Committer: eceejcr <ec...@E7B499BAE9DDE0.ericsson.se>
Committed: Sun May 11 01:05:03 2014 +0200

----------------------------------------------------------------------
 .../org/apache/curator/utils/DebugUtils.java    |  1 +
 .../framework/imps/CuratorFrameworkImpl.java    | 33 ++++++++++++--------
 2 files changed, 21 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/048688a3/curator-client/src/main/java/org/apache/curator/utils/DebugUtils.java
----------------------------------------------------------------------
diff --git a/curator-client/src/main/java/org/apache/curator/utils/DebugUtils.java b/curator-client/src/main/java/org/apache/curator/utils/DebugUtils.java
index 64c2d6e..0ce2729 100644
--- a/curator-client/src/main/java/org/apache/curator/utils/DebugUtils.java
+++ b/curator-client/src/main/java/org/apache/curator/utils/DebugUtils.java
@@ -22,6 +22,7 @@ public class DebugUtils
 {
     public static final String          PROPERTY_LOG_EVENTS = "curator-log-events";
     public static final String          PROPERTY_DONT_LOG_CONNECTION_ISSUES = "curator-dont-log-connection-problems";
+    public static final String          PROPERTY_LOG_ALL_CONNECTION_ISSUES_AS_ERROR_LEVEL = "curator-log-all-connection-issues-as-error-level";
 
     private DebugUtils()
     {

http://git-wip-us.apache.org/repos/asf/curator/blob/048688a3/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 d6a5973..3a78967 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
@@ -56,7 +56,8 @@ import java.util.concurrent.atomic.AtomicReference;
 
 public class CuratorFrameworkImpl implements CuratorFramework
 {
-    private final Logger                                                log = LoggerFactory.getLogger(getClass());
+
+	private final Logger                                                log = LoggerFactory.getLogger(getClass());
     private final CuratorZookeeperClient                                client;
     private final ListenerContainer<CuratorListener>                    listeners;
     private final ListenerContainer<UnhandledErrorListener>             unhandledErrorListeners;
@@ -73,7 +74,9 @@ public class CuratorFrameworkImpl implements CuratorFramework
     private final NamespaceWatcherMap                                   namespaceWatcherMap = new NamespaceWatcherMap(this);
 
     private volatile ExecutorService                                    executorService;
-    private AtomicBoolean                                               logAsErrorConnectionErrors = new AtomicBoolean(false);
+    private final AtomicBoolean                                         logAsErrorConnectionErrors = new AtomicBoolean(false);
+
+    private static final boolean                                        LOG_ALL_CONNECTION_ISSUES_AS_ERROR_LEVEL = Boolean.getBoolean(DebugUtils.PROPERTY_LOG_ALL_CONNECTION_ISSUES_AS_ERROR_LEVEL);
 
     interface DebugBackgroundListener
     {
@@ -233,16 +236,20 @@ 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);
+            
+            final 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();
 
@@ -524,7 +531,7 @@ public class CuratorFrameworkImpl implements CuratorFramework
         if ( !Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES) || !(e instanceof KeeperException) )
         {
             if ( e instanceof KeeperException.ConnectionLossException || e instanceof CuratorConnectionLossException ) {
-                if ( logAsErrorConnectionErrors.compareAndSet(true, false) )
+                if ( LOG_ALL_CONNECTION_ISSUES_AS_ERROR_LEVEL || logAsErrorConnectionErrors.compareAndSet(true, false) )
                 {
                     log.error(reason, e);
                 }