brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From geom...@apache.org
Subject [06/13] brooklyn-server git commit: Stop recursive resolving of DSL results on DslCallable
Date Tue, 20 Dec 2016 11:10:24 GMT
Stop recursive resolving of DSL results on DslCallable

Lets us call methods on DslCallable methods and at the same time resolve the object if it's
the last of the chain.


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

Branch: refs/heads/master
Commit: e831d75471554f57709f14889c7b0ff78dec6e63
Parents: 42bc7c1
Author: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Authored: Mon Dec 12 18:03:35 2016 +0200
Committer: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Committed: Tue Dec 13 09:15:37 2016 +0200

----------------------------------------------------------------------
 .../spi/dsl/DslDeferredFunctionCall.java        | 35 ++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e831d754/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/DslDeferredFunctionCall.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/DslDeferredFunctionCall.java
b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/DslDeferredFunctionCall.java
index 7a31ee0..9835be6 100644
--- a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/DslDeferredFunctionCall.java
+++ b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/DslDeferredFunctionCall.java
@@ -21,6 +21,7 @@ import java.util.concurrent.Callable;
 
 import org.apache.brooklyn.api.mgmt.Task;
 import org.apache.brooklyn.camp.brooklyn.spi.dsl.methods.BrooklynDslCommon;
+import org.apache.brooklyn.core.entity.EntityInternal;
 import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
 import org.apache.brooklyn.util.core.task.Tasks;
 import org.apache.brooklyn.util.exceptions.Exceptions;
@@ -47,7 +48,7 @@ public class DslDeferredFunctionCall extends BrooklynDslDeferredSupplier<Object>
 
     @Override
     public Maybe<Object> getImmediately() {
-        Maybe<?> obj = object.getImmediately();
+        Maybe<?> obj = resolveImmediate(object);
         if (obj.isPresent()) {
             if (obj.isNull()) {
                 throw new IllegalArgumentException("Deferred function call, " + object +

@@ -67,7 +68,7 @@ public class DslDeferredFunctionCall extends BrooklynDslDeferredSupplier<Object>
                 .body(new Callable<Object>() {
                     @Override
                     public Object call() throws Exception {
-                        Object obj = object.get();
+                        Object obj = DslDeferredFunctionCall.this.resolveBlocking(object).orNull();
                         if (obj == null) {
                             throw new IllegalArgumentException("Deferred function call, "
+ object + 
                                     " evaluates to null (when calling " + fnName + "(" +
DslDeferredFunctionCall.toString(args) + "))");
@@ -78,6 +79,36 @@ public class DslDeferredFunctionCall extends BrooklynDslDeferredSupplier<Object>
                 }).build();
     }
 
+    protected Maybe<?> resolveImmediate(Object object) {
+        return resolve(object, true);
+    }
+    protected Maybe<?> resolveBlocking(Object object) {
+        return resolve(object, false);
+    }
+    protected Maybe<?> resolve(Object object, boolean immediate) {
+        if (object instanceof DslCallable || object == null) {
+            return Maybe.of(object);
+        }
+        Maybe<?> resultMaybe = Tasks.resolving(object, Object.class)
+                .context(((EntityInternal)entity()).getExecutionContext())
+                .deep(true)
+                .immediately(immediate)
+                .recursive(false)
+                .getMaybe();
+        if (resultMaybe.isAbsent()) {
+            return resultMaybe;
+        } else {
+            // No nice way to figure out whether the object is deferred. Try to resolve it
+            // until it matches the input value as a poor man's replacement.
+            Object result = resultMaybe.get();
+            if (result == object) {
+                return resultMaybe;
+            } else {
+                return resolve(result, immediate);
+            }
+        }
+    }
+
     protected Object invokeOn(Object obj) {
         return invokeOn(obj, fnName, args);
     }


Mime
View raw message