brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [19/23] brooklyn-server git commit: Tasks.tryQueueing won't queue if calling thread is interrupted
Date Fri, 06 Oct 2017 08:06:43 GMT
Tasks.tryQueueing won't queue if calling thread is interrupted

means more things work in immediate mode.
could be un-done if DynamicSequentialTask removes the DST manager thread.
fixes a few failing tests in the previous commit.


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

Branch: refs/heads/master
Commit: 8b7276976721ef440c858ee8253227169c32f5e0
Parents: 9888870
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Wed Oct 4 10:57:17 2017 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Wed Oct 4 14:45:19 2017 +0100

----------------------------------------------------------------------
 .../brooklyn/util/core/task/DynamicTasks.java   | 21 ++++++--------------
 .../apache/brooklyn/util/core/task/Tasks.java   |  6 +++---
 2 files changed, 9 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8b727697/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 20b80ab..9026798 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
@@ -199,11 +199,7 @@ public class DynamicTasks {
      * {@link BasicExecutionContext}.
      */
     public static <T> TaskQueueingResult<T> queueIfPossible(TaskAdaptable<T>
task) {
-        TaskQueueingContext adder = getTaskQueuingContext();
-        boolean result = false;
-        if (adder!=null)
-            result = Tasks.tryQueueing(adder, task);
-        return new TaskQueueingResult<T>(task, result);
+        return new TaskQueueingResult<T>(task, Tasks.tryQueueing(getTaskQueuingContext(),
task));
     }
 
     /** @see #queueIfPossible(TaskAdaptable) */
@@ -214,22 +210,17 @@ public class DynamicTasks {
     /** adds the given task to the nearest task addition context,
      * either set as a thread-local, or in the current task, or the submitter of the task,
etc
      * <p>
-     * throws if it cannot add */
+     * throws if it cannot add or addition/execution would fail including if calling thread
is interrupted */
     public static <T> Task<T> queueInTaskHierarchy(Task<T> task) {
         Preconditions.checkNotNull(task, "Task to queue cannot be null");
         Preconditions.checkState(!Tasks.isQueuedOrSubmitted(task), "Task to queue must not
yet be submitted: {}", task);
         
-        TaskQueueingContext adder = getTaskQueuingContext();
-        if (adder!=null) { 
-            if (Tasks.tryQueueing(adder, task)) {
-                log.debug("Queued task {} at context {} (no hierarchy)", task, adder);
-                return task;
-            }
+        if (Tasks.tryQueueing(getTaskQueuingContext(), task)) {
+            log.debug("Queued task {} at context {} (no hierarchy)", task, getTaskQueuingContext());
+            return task;
         }
         
-        Task<?> t = Tasks.current();
-        Preconditions.checkState(t!=null || adder!=null, "No task addition context available
for queueing task "+task);
-        
+        Task<?> t = Tasks.current();        
         while (t!=null) {
             if (t instanceof TaskQueueingContext) {
                 if (Tasks.tryQueueing((TaskQueueingContext)t, task)) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8b727697/core/src/main/java/org/apache/brooklyn/util/core/task/Tasks.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/task/Tasks.java b/core/src/main/java/org/apache/brooklyn/util/core/task/Tasks.java
index 12247c4..90a6bdc 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/task/Tasks.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/task/Tasks.java
@@ -278,11 +278,11 @@ public class Tasks {
     }
     
     /**
-     * Adds the given task to the given context. Does not throw an exception if the addition
fails.
-     * @return true if the task was added, false otherwise.
+     * Adds the given task to the given context. Does not throw an exception if the addition
fails or would fail.
+     * @return true if the task was added, false otherwise including if context is null or
thread is interrupted.
      */
     public static boolean tryQueueing(TaskQueueingContext adder, TaskAdaptable<?> task)
{
-        if (task==null || isQueued(task))
+        if (task==null || adder==null || isQueued(task) || Thread.currentThread().isInterrupted())
             return false;
         try {
             adder.queue(task.asTask());


Mime
View raw message