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

    https://github.com/apache/brooklyn-server/pull/480#discussion_r103504542
  
    --- Diff: 
core/src/main/java/org/apache/brooklyn/util/core/task/ValueResolver.java ---
    @@ -352,33 +357,73 @@ public T get() {
             
             //if the expected type is a closure or map and that's what we 
have, we're done (or if it's null);
             //but not allowed to return a future or DeferredSupplier as the 
resolved value
    -        if (v==null || (!forceDeep && type.isInstance(v) && 
!Future.class.isInstance(v) && !DeferredSupplier.class.isInstance(v)))
    +        if (v==null || (!forceDeep && type.isInstance(v) && 
!Future.class.isInstance(v) && !DeferredSupplier.class.isInstance(v) && 
!TaskFactory.class.isInstance(v)))
                 return Maybe.of((T) v);
             
             try {
    -            if (immediately && v instanceof ImmediateSupplier) {
    -                final ImmediateSupplier<?> supplier = 
(ImmediateSupplier<?>) v;
    +            boolean allowImmediateExecution = false;
    +            boolean bailOutAfterImmediateExecution = false;
    +            
    +            if (v instanceof ImmediateSupplier) {
    +                allowImmediateExecution = true;
    +                
    +            } else {
    +                if ((v instanceof TaskFactory<?>) && !(v instanceof 
DeferredSupplier)) {
    +                    v = ((TaskFactory<?>)v).newTask();
    +                    allowImmediateExecution = true;
    +                    bailOutAfterImmediateExecution = true;
    +                    
BrooklynTaskTags.setTransient(((TaskAdaptable<?>)v).asTask());
    +                    if (isEvaluatingImmediately()) {
    +                        // not needed if executing immediately
    +                        BrooklynTaskTags.addTagDynamically( 
((TaskAdaptable<?>)v).asTask(), BrooklynTaskTags.IMMEDIATE_TASK_TAG );
    +                    }
    +                }
    +                
    +                //if it's a task or a future, we wait for the task to 
complete
    +                if (v instanceof TaskAdaptable<?>) {
    +                    v = ((TaskAdaptable<?>) v).asTask();
    +                }
    +            }
    +            
    +            if (allowImmediateExecution && isEvaluatingImmediately()) {
    +                // TODO could allow for everything, when evaluating 
immediately -- but if the target isn't safe to run again
    +                // then we have to fail if immediate didn't work; to avoid 
breaking semantics we only do that for a few cases;
    +                // might be nice to get to the point where we can break 
those semantics however, 
    +                // ie weakening what getImmediate supports and making it 
be non-blocking, so that bailOut=true is the default.
    +                // if: v instanceof TaskFactory -- it is safe, it's a new 
API (but it is currently the only one supported);
    +                //     more than safe, we have to do it -- or add code 
here to cancel tasks -- because it spawns new tasks
    +                //     (other objects passed through here don't get 
cancelled, because other things might try again later;
    +                //     ie a task or future passed in here might naturally 
be long-running so cancelling is wrong,
    +                //     but with a task factory generated task it would 
leak if we submitted and didn't cancel!)
    --- End diff --
    
    aha, `DST` which we mostly use is fine, but its `doCancel` method was 
missing from the lighter-weight `CompoundTask`; have added it there and test 
passes


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to