curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [6/8] curator git commit: Don't let thread interrupt status get reset. The only proper reason for these loops to exit if the instance is closed
Date Sun, 17 Jan 2016 22:26:46 GMT
Don't let thread interrupt status get reset. The only proper reason for these loops to exit
if the instance is closed


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

Branch: refs/heads/master
Commit: 5a51b0939bbee46e1d22f30fbaacd35685cdd9f0
Parents: 737d2aa
Author: randgalt <randgalt@apache.org>
Authored: Thu Jan 14 22:41:44 2016 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Thu Jan 14 22:41:44 2016 -0500

----------------------------------------------------------------------
 .../framework/state/ConnectionStateManager.java | 14 ++++---
 .../recipes/queue/DistributedQueue.java         | 39 +++++++++++---------
 .../framework/recipes/queue/QueueSharder.java   | 14 ++++---
 3 files changed, 38 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/5a51b093/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java
b/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java
index 67ff13d..8cc37aa 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java
@@ -238,9 +238,9 @@ public class ConnectionStateManager implements Closeable
 
     private void processEvents()
     {
-        try
+        while ( state.get() == State.STARTED )
         {
-            while ( !Thread.currentThread().isInterrupted() )
+            try
             {
                 final ConnectionState newState = eventQueue.take();
 
@@ -262,10 +262,12 @@ public class ConnectionStateManager implements Closeable
                         }
                     );
             }
-        }
-        catch ( InterruptedException e )
-        {
-            Thread.currentThread().interrupt();
+            catch ( InterruptedException e )
+            {
+                // swallow the interrupt as it's only possible from either a background
+                // operation and, thus, doesn't apply to this loop or the instance
+                // is being closed in which case the while test will get it
+            }
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/5a51b093/curator-recipes/src/main/java/org/apache/curator/framework/recipes/queue/DistributedQueue.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/queue/DistributedQueue.java
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/queue/DistributedQueue.java
index 43291e4..14d1266 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/queue/DistributedQueue.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/queue/DistributedQueue.java
@@ -545,34 +545,39 @@ public class DistributedQueue<T> implements QueueBase<T>
         long         maxWaitMs = -1;
         try
         {
-            while ( !Thread.currentThread().isInterrupted()  )
+            while ( state.get() == State.STARTED  )
             {
-                ChildrenCache.Data      data = (maxWaitMs > 0) ? childrenCache.blockingNextGetData(currentVersion,
maxWaitMs, TimeUnit.MILLISECONDS) : childrenCache.blockingNextGetData(currentVersion);
-                currentVersion = data.version;
+                try
+                {
+                    ChildrenCache.Data      data = (maxWaitMs > 0) ? childrenCache.blockingNextGetData(currentVersion,
maxWaitMs, TimeUnit.MILLISECONDS) : childrenCache.blockingNextGetData(currentVersion);
+                    currentVersion = data.version;
 
-                List<String>        children = Lists.newArrayList(data.children);
-                sortChildren(children); // makes sure items are processed in the correct
order
+                    List<String>        children = Lists.newArrayList(data.children);
+                    sortChildren(children); // makes sure items are processed in the correct
order
 
-                if ( children.size() > 0 )
-                {
-                    maxWaitMs = getDelay(children.get(0));
-                    if ( maxWaitMs > 0 )
+                    if ( children.size() > 0 )
+                    {
+                        maxWaitMs = getDelay(children.get(0));
+                        if ( maxWaitMs > 0 )
+                        {
+                            continue;
+                        }
+                    }
+                    else
                     {
                         continue;
                     }
+
+                    processChildren(children, currentVersion);
                 }
-                else
+                catch ( InterruptedException e )
                 {
-                    continue;
+                    // swallow the interrupt as it's only possible from either a background
+                    // operation and, thus, doesn't apply to this loop or the instance
+                    // is being closed in which case the while test will get it
                 }
-
-                processChildren(children, currentVersion);
             }
         }
-        catch ( InterruptedException ignore )
-        {
-            Thread.currentThread().interrupt();
-        }
         catch ( Exception e )
         {
             log.error("Exception caught in background handler", e);

http://git-wip-us.apache.org/repos/asf/curator/blob/5a51b093/curator-recipes/src/main/java/org/apache/curator/framework/recipes/queue/QueueSharder.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/queue/QueueSharder.java
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/queue/QueueSharder.java
index 24a56f8..3cd0cdb 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/queue/QueueSharder.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/queue/QueueSharder.java
@@ -124,17 +124,19 @@ public class QueueSharder<U, T extends QueueBase<U>> implements
Closeable
                 @Override
                 public Void call() throws Exception
                 {
-                    try
+                    while ( state.get() == State.STARTED )
                     {
-                        while ( !Thread.currentThread().isInterrupted() && (state.get()
== State.STARTED) )
+                        try
                         {
                             Thread.sleep(policies.getThresholdCheckMs());
                             checkThreshold();
                         }
-                    }
-                    catch ( InterruptedException e )
-                    {
-                        Thread.currentThread().interrupt();
+                        catch ( InterruptedException e )
+                        {
+                            // swallow the interrupt as it's only possible from either a
background
+                            // operation and, thus, doesn't apply to this loop or the instance
+                            // is being closed in which case the while test will get it
+                        }
                     }
                     return null;
                 }


Mime
View raw message