Repository: helix Updated Branches: refs/heads/master 3ed9cebbc -> e96ea8e20
[HELIX-537] Shutdown executors Project: http://git-wip-us.apache.org/repos/asf/helix/repo Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/e96ea8e2 Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/e96ea8e2 Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/e96ea8e2 Branch: refs/heads/master Commit: e96ea8e20e6a2ceff0a6fbf915d96257137ccda3 Parents: 3ed9ceb Author: Antony T Curtis <[email protected]> Authored: Tue Nov 11 11:17:43 2014 -0800 Committer: Kanak Biscuitwala <[email protected]> Committed: Tue Nov 11 20:55:17 2014 -0800 ---------------------------------------------------------------------- .../messaging/handling/HelixTaskExecutor.java | 2 ++ .../org/apache/helix/task/TaskStateModel.java | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/helix/blob/e96ea8e2/helix-core/src/main/java/org/apache/helix/messaging/handling/HelixTaskExecutor.java ---------------------------------------------------------------------- diff --git a/helix-core/src/main/java/org/apache/helix/messaging/handling/HelixTaskExecutor.java b/helix-core/src/main/java/org/apache/helix/messaging/handling/HelixTaskExecutor.java index 8a380c4..6fd463f 100644 --- a/helix-core/src/main/java/org/apache/helix/messaging/handling/HelixTaskExecutor.java +++ b/helix-core/src/main/java/org/apache/helix/messaging/handling/HelixTaskExecutor.java @@ -155,6 +155,7 @@ public class HelixTaskExecutor implements MessageListener, TaskExecutor { if (prevExecutor != null) { LOG.warn("Skip creating a new thread pool for type: " + type + ", already existing pool: " + prevExecutor + ", isShutdown: " + prevExecutor.isShutdown()); + newPool.shutdown(); newPool = null; } LOG.info("Registered message handler factory for type: " + type + ", poolSize: " @@ -485,6 +486,7 @@ public class HelixTaskExecutor implements MessageListener, TaskExecutor { // Will happen if we register and call init LOG.info("Skip init a new thread pool for type: " + msgType + ", already existing pool: " + prevPool + ", isShutdown: " + prevPool.isShutdown()); + newPool.shutdown(); newPool = null; } } http://git-wip-us.apache.org/repos/asf/helix/blob/e96ea8e2/helix-core/src/main/java/org/apache/helix/task/TaskStateModel.java ---------------------------------------------------------------------- diff --git a/helix-core/src/main/java/org/apache/helix/task/TaskStateModel.java b/helix-core/src/main/java/org/apache/helix/task/TaskStateModel.java index c790608..7f483f6 100644 --- a/helix-core/src/main/java/org/apache/helix/task/TaskStateModel.java +++ b/helix-core/src/main/java/org/apache/helix/task/TaskStateModel.java @@ -25,6 +25,7 @@ import java.util.TimerTask; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; import org.apache.helix.HelixManager; import org.apache.helix.NotificationContext; @@ -54,6 +55,25 @@ public class TaskStateModel extends TransitionHandler { }); } + public boolean isShutdown() { + return _taskExecutor.isShutdown(); + } + + public boolean isTerminated() { + return _taskExecutor.isTerminated(); + } + + public void shutdown() { + reset(); + _taskExecutor.shutdown(); + _timer.cancel(); + } + + public boolean awaitTermination(long timeout, TimeUnit unit) + throws InterruptedException { + return _taskExecutor.awaitTermination(timeout, unit); + } + @Transition(to = "RUNNING", from = "INIT") public void onBecomeRunningFromInit(Message msg, NotificationContext context) { startTask(msg, msg.getPartitionName());
