From dcd394d83fed984df5341624271f506404dbe886 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 21 Jun 2016 15:39:55 -0400 Subject: [PATCH] Inline TaskManager#register --- .../org/elasticsearch/tasks/TaskManager.java | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/tasks/TaskManager.java b/core/src/main/java/org/elasticsearch/tasks/TaskManager.java index 95adc850f82..7a7a71174a6 100644 --- a/core/src/main/java/org/elasticsearch/tasks/TaskManager.java +++ b/core/src/main/java/org/elasticsearch/tasks/TaskManager.java @@ -92,23 +92,7 @@ public class TaskManager extends AbstractComponent implements ClusterStateListen } if (task instanceof CancellableTask) { - CancellableTask cancellableTask = (CancellableTask) task; - CancellableTaskHolder holder = new CancellableTaskHolder(cancellableTask); - CancellableTaskHolder oldHolder = cancellableTasks.put(task.getId(), holder); - assert oldHolder == null; - // Check if this task was banned before we start it - if (task.getParentTaskId().isSet() && banedParents.isEmpty() == false) { - String reason = banedParents.get(task.getParentTaskId()); - if (reason != null) { - try { - holder.cancel(reason); - throw new IllegalStateException("Task cancelled before it started: " + reason); - } finally { - // let's clean up the registration - unregister(task); - } - } - } + registerCancellableTask(task); } else { Task previousTask = tasks.put(task.getId(), task); assert previousTask == null; @@ -116,6 +100,26 @@ public class TaskManager extends AbstractComponent implements ClusterStateListen return task; } + private void registerCancellableTask(Task task) { + CancellableTask cancellableTask = (CancellableTask) task; + CancellableTaskHolder holder = new CancellableTaskHolder(cancellableTask); + CancellableTaskHolder oldHolder = cancellableTasks.put(task.getId(), holder); + assert oldHolder == null; + // Check if this task was banned before we start it + if (task.getParentTaskId().isSet() && banedParents.isEmpty() == false) { + String reason = banedParents.get(task.getParentTaskId()); + if (reason != null) { + try { + holder.cancel(reason); + throw new IllegalStateException("Task cancelled before it started: " + reason); + } finally { + // let's clean up the registration + unregister(task); + } + } + } + } + /** * Cancels a task *