Github user aledsage commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/816#discussion_r141560042
--- Diff:
core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionContext.java
---
@@ -100,6 +123,121 @@ public ExecutionManager getExecutionManager() {
@Override
public Set<Task<?>> getTasks() { return
executionManager.getTasksWithAllTags(tags); }
+ @Override
+ public <T> T get(TaskAdaptable<T> task) {
+ final TaskInternal<T> t = (TaskInternal<T>) task.asTask();
+
+ if (t.isQueuedOrSubmitted()) {
+ if (t.isDone()) {
+ return t.getUnchecked();
+ } else {
+ throw new ImmediateUnsupportedException("Task is in
progress and incomplete: "+t);
+ }
+ }
+
+ ContextSwitchingInfo<T> switchContextWrapper =
getContextSwitchingTask(t, Collections.emptyList(), false);
+ if (switchContextWrapper!=null) {
+ return
switchContextWrapper.context.get(switchContextWrapper.wrapperTask);
+ }
+
+ try {
+ return runInSameThread(t, new Callable<Maybe<T>>() {
--- End diff --
This feels dangerous. When someone calls `executionContext.get(task)` on a
task that is not yet submitted, it will execute that task's job while
continuing to hold all the synchronization locks that the current thread has.
That's a big change of semantics for submitting tasks, which could easily lead
to deadlock.
---