brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aledsage <>
Subject [GitHub] brooklyn-server pull request #480: Config self reference fix
Date Tue, 28 Feb 2017 14:08:25 GMT
Github user aledsage commented on a diff in the pull request:
    --- Diff: core/src/main/java/org/apache/brooklyn/util/core/task/
    @@ -96,7 +98,50 @@ public ExecutionManager getExecutionManager() {
         /** returns tasks started by this context (or tasks which have all the tags on this
object) */
         public Set<Task<?>> getTasks() { return executionManager.getTasksWithAllTags(tags);
    +    /** performs execution without spawning a new task thread, though it does temporarily
set a fake task for the purpose of getting context;
    +     * currently supports suppliers or callables  */
    +    @SuppressWarnings("unchecked")
    +    @Override
    +    public <T> Maybe<T> getImmediately(Object callableOrSupplier) {
    +        BasicTask<?> fakeTaskForContext;
    +        if (callableOrSupplier instanceof BasicTask) {
    +            fakeTaskForContext = (BasicTask<?>)callableOrSupplier;
    --- End diff --
    Under what code path do we get here? Looking at `ValueResolver.getMaybeInternal(...)`,
`allowImmediateExecution` will be false if the object is a task (rather than a `TaskFactory`
or `DeferredSupplier`). 
    For example, the test below fails (added to `ValueResolverTest`). It leaves a single instance
of the task executing.
        public void testTaskGetImmediatelyDoesNotBlock() {
            final AtomicInteger executingCount = new AtomicInteger();
            final Task<String> task = new BasicTask<>(new Callable<String>()
                public String call() {
                    try {
                        return "myval";
                    } finally {
            for (int i = 0; i < 3; i++) {
                Maybe<String> result = Tasks.resolving(task).as(String.class).context(app).immediately(true).getMaybe();
                Asserts.assertTrue(result.isAbsent(), "result="+result);
            // The call below default times out after 30s while the task above is still running
            // Expect the task to not be left running.
            Asserts.succeedsEventually(new Runnable() {
                public void run() {
                    Asserts.assertEquals(executingCount.get(), 0);
    I'm not convinced that we want to support setting a config key with a value of type `Task`
(long term). But I guess that will require more work, to change how `DependentConfiguration`
is implemented. So we do need to support it short-term :-(

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

View raw message