Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/1160#discussion_r50317800
  
    --- Diff: 
brooklyn-server/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
 ---
    @@ -526,19 +538,63 @@ public String toString() {
             }
         }
     
    -    private final static class ListenableForwardingFutureForTask<T> 
extends ListenableForwardingFuture<T> {
    +    @SuppressWarnings("deprecation")
    +    // TODO do we even need a listenable future here?  possibly if someone 
wants to interrogate the future it might
    +    // be interesting, so possibly it is useful that we implement 
ListenableFuture...
    +    private final static class 
CancellingListenableForwardingFutureForTask<T> extends 
ListenableForwardingFuture<T> {
             private final Task<T> task;
    +        private BasicExecutionManager execMgmt;
     
    -        private ListenableForwardingFutureForTask(Future<T> delegate, 
ExecutionList list, Task<T> task) {
    +        private 
CancellingListenableForwardingFutureForTask(BasicExecutionManager execMgmt, 
Future<T> delegate, ExecutionList list, Task<T> task) {
                 super(delegate, list);
    +            this.execMgmt = execMgmt;
                 this.task = task;
             }
     
             @Override
    -        public boolean cancel(boolean mayInterruptIfRunning) {
    +        public boolean cancel(TaskCancellationMode mode) {
                 boolean result = false;
    -            if (!task.isCancelled()) result |= 
task.cancel(mayInterruptIfRunning);
    -            result |= super.cancel(mayInterruptIfRunning);
    +            if (log.isTraceEnabled()) {
    +                log.trace("CLFFT cancelling "+task+" mode "+mode);
    +            }
    +            if (!task.isCancelled()) result |= 
((TaskInternal<T>)task).cancel(mode);
    +            result |= delegate().cancel(mode.isAllowedToInterruptTask());
    +            
    +            if (mode.isAllowedToInterruptAllSubmittedTasks() || 
mode.isAllowedToInterruptDependentSubmittedTasks()) {
    +                int subtasksFound=0;
    +                int subtasksReallyCancelled=0;
    +                
    +                if (task instanceof HasTaskChildren) {
    +                    for (Task<?> child: 
((HasTaskChildren)task).getChildren()) {
    +                        if (log.isTraceEnabled()) {
    +                            log.trace("Cancelling "+child+" on recursive 
cancellation of "+task);
    +                        }
    +                        subtasksFound++;
    +                        if (((TaskInternal<?>)child).cancel(mode)) {
    +                            result = true;
    +                            subtasksReallyCancelled++;
    +                        }
    +                    }
    +                }
    +                for (Task<?> t: execMgmt.getAllTasks()) {
    --- End diff --
    
    have added a TODO -- i agree with your intuition, but would rather work on 
optimising tasks as a separate exercise


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to