brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [01/23] brooklyn-server git commit: task optimization: some queued-or-submitted tasks use foreground for executing
Date Fri, 06 Oct 2017 08:06:25 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 54f9c708a -> a73ee1728


task optimization: some queued-or-submitted tasks use foreground for executing


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/4430f769
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/4430f769
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/4430f769

Branch: refs/heads/master
Commit: 4430f769077210bf253a8d70a69482c1c2119d39
Parents: 7f4d7bd
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Fri Sep 15 11:07:27 2017 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Mon Sep 18 17:10:54 2017 +0100

----------------------------------------------------------------------
 .../brooklyn/util/core/task/DynamicTasks.java       | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4430f769/core/src/main/java/org/apache/brooklyn/util/core/task/DynamicTasks.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/task/DynamicTasks.java b/core/src/main/java/org/apache/brooklyn/util/core/task/DynamicTasks.java
index 15b062a..5426baf 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/task/DynamicTasks.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/task/DynamicTasks.java
@@ -107,7 +107,7 @@ public class DynamicTasks {
             this.execContext = ((EntityInternal)entity).getExecutionContext();
             return this;
         }
-        private boolean orSubmitInternal() {
+        private boolean orSubmitInternal(boolean samethread) {
             if (!wasQueued()) {
                 if (isQueuedOrSubmitted()) {
                     log.warn("Redundant call to execute "+getTask()+"; skipping");
@@ -118,7 +118,8 @@ public class DynamicTasks {
                         ec = BasicExecutionContext.getCurrentExecutionContext();
                     if (ec==null)
                         throw new IllegalStateException("Cannot execute "+getTask()+" without
an execution context; ensure caller is in an ExecutionContext");
-                    ec.submit(getTask());
+                    if (samethread) ec.get(getTask());
+                    else ec.submit(getTask());
                     return true;
                 }
             } else {
@@ -128,7 +129,7 @@ public class DynamicTasks {
         /** causes the task to be submitted (asynchronously) if it hasn't already been,
          * requiring an entity execution context (will try to find a default if not set)
*/
         public TaskQueueingResult<T> orSubmitAsync() {
-            orSubmitInternal();
+            orSubmitInternal(false);
             return this;
         }
         /** convenience for setting {@link #executionContext(ExecutionContext)} then submitting
async */
@@ -141,7 +142,7 @@ public class DynamicTasks {
          * (which assumes all commands complete immediately);
          * requiring an entity execution context (will try to find a default if not set)
*/
         public TaskQueueingResult<T> orSubmitAndBlock() {
-            if (orSubmitInternal()) task.getUnchecked();
+            orSubmitInternal(true);
             return this;
         }
         /** convenience for setting {@link #executionContext(ExecutionContext)} then submitting
blocking */
@@ -288,12 +289,9 @@ public class DynamicTasks {
         return task;
     }
     
-    /** submits/queues the given task if needed, and gets the result (unchecked) 
-     * only permitted in a queueing context (ie a DST main job) if the task is not yet submitted
*/
-    // things get really confusing if you try to queueInTaskHierarchy -- easy to cause deadlocks!
+    /** submits/queues the given task if needed, and gets the result (unchecked) */
     public static <T> T get(TaskAdaptable<T> t) {
-        // TODO do in foreground?
-        return queueIfNeeded(t).asTask().getUnchecked();
+        return queueIfPossible(t).orSubmitAndBlock().andWaitForSuccess();
     }
 
     /** As {@link #drain(Duration, boolean)} waiting forever and throwing the first error



Mime
View raw message