curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject git commit: wrapExecutor was wrong - there's no way to use the ThreadFactory. Just ignore it now
Date Sat, 07 Sep 2013 03:01:00 GMT
Updated Branches:
  refs/heads/master 50e8fbb8c -> 35d68e172


wrapExecutor was wrong - there's no way to use the ThreadFactory. Just ignore it now


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

Branch: refs/heads/master
Commit: 35d68e1724dd66fd48b6a25ae07976d10097168a
Parents: 50e8fbb
Author: randgalt <randgalt@apache.org>
Authored: Fri Sep 6 20:01:07 2013 -0700
Committer: randgalt <randgalt@apache.org>
Committed: Fri Sep 6 20:01:07 2013 -0700

----------------------------------------------------------------------
 .../recipes/leader/LeaderSelector.java          | 30 ++++++++++++++------
 1 file changed, 21 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-curator/blob/35d68e17/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelector.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelector.java
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelector.java
index afb07bc..c8247ca 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelector.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelector.java
@@ -22,6 +22,7 @@ package org.apache.curator.framework.recipes.leader;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.recipes.locks.InterProcessMutex;
 import org.apache.curator.utils.CloseableExecutorService;
@@ -100,10 +101,11 @@ public class LeaderSelector implements Closeable
      * @param listener      listener
      * @deprecated This constructor was poorly thought out. Custom executor is useless. Use
this version instead: {@link #LeaderSelector(CuratorFramework, String, ExecutorService, LeaderSelectorListener)}
      */
+    @SuppressWarnings("UnusedParameters")
     @Deprecated
     public LeaderSelector(CuratorFramework client, String leaderPath, ThreadFactory threadFactory,
Executor executor, LeaderSelectorListener listener)
     {
-        this(client, leaderPath, wrapExecutor(threadFactory, executor), listener);
+        this(client, leaderPath, wrapExecutor(executor), listener);
     }
 
     /**
@@ -415,45 +417,55 @@ public class LeaderSelector implements Closeable
     }
 
     // temporary wrapper for deprecated constructor
-    private static ExecutorService wrapExecutor(ThreadFactory threadFactory, final Executor
executor)
+    private static ExecutorService wrapExecutor(final Executor executor)
     {
-        final ExecutorService service = Executors.newSingleThreadExecutor(threadFactory);
         return new AbstractExecutorService()
         {
+            private volatile boolean isShutdown = false;
+            private volatile boolean isTerminated = false;
+
             @Override
             public void shutdown()
             {
-                service.shutdown();
+                isShutdown = true;
             }
 
             @Override
             public List<Runnable> shutdownNow()
             {
-                return service.shutdownNow();
+                return Lists.newArrayList();
             }
 
             @Override
             public boolean isShutdown()
             {
-                return service.isShutdown();
+                return isShutdown;
             }
 
             @Override
             public boolean isTerminated()
             {
-                return service.isTerminated();
+                return isTerminated;
             }
 
             @Override
             public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
             {
-                return service.awaitTermination(timeout, unit);
+                throw new UnsupportedOperationException();
             }
 
             @Override
             public void execute(Runnable command)
             {
-                executor.execute(command);
+                try
+                {
+                    executor.execute(command);
+                }
+                finally
+                {
+                    isShutdown = true;
+                    isTerminated = true;
+                }
             }
         };
     }


Mime
View raw message