Inline TaskManager#register

This commit is contained in:
Jason Tedor 2016-06-21 15:39:55 -04:00
parent 8078c205f9
commit dcd394d83f
1 changed files with 21 additions and 17 deletions

View File

@ -92,23 +92,7 @@ public class TaskManager extends AbstractComponent implements ClusterStateListen
} }
if (task instanceof CancellableTask) { if (task instanceof CancellableTask) {
CancellableTask cancellableTask = (CancellableTask) task; registerCancellableTask(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);
}
}
}
} else { } else {
Task previousTask = tasks.put(task.getId(), task); Task previousTask = tasks.put(task.getId(), task);
assert previousTask == null; assert previousTask == null;
@ -116,6 +100,26 @@ public class TaskManager extends AbstractComponent implements ClusterStateListen
return task; 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 * Cancels a task
* <p> * <p>