You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sj...@apache.org on 2015/10/19 11:46:54 UTC

[5/7] incubator-brooklyn git commit: Support deferred suppliers within location config.

Support deferred suppliers within location config.


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

Branch: refs/heads/master
Commit: 3c3b4794ee805a083b82f6fb6758e8b8f151b859
Parents: 16f9a9a
Author: Alasdair Hodge <gi...@alasdairhodge.co.uk>
Authored: Fri Oct 9 13:37:41 2015 +0100
Committer: Alasdair Hodge <gi...@alasdairhodge.co.uk>
Committed: Mon Oct 19 08:51:15 2015 +0100

----------------------------------------------------------------------
 .../core/location/AbstractLocation.java         | 38 +++++++++++++++-----
 1 file changed, 29 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3c3b4794/core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java b/core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java
index 98a7e38..b5a91c7 100644
--- a/core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java
+++ b/core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java
@@ -34,6 +34,7 @@ import org.apache.brooklyn.api.entity.Group;
 import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.mgmt.ExecutionContext;
+import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.mgmt.SubscriptionContext;
 import org.apache.brooklyn.api.mgmt.SubscriptionHandle;
 import org.apache.brooklyn.api.mgmt.Task;
@@ -66,6 +67,9 @@ import org.apache.brooklyn.util.collections.SetFromLiveMap;
 import org.apache.brooklyn.util.core.config.ConfigBag;
 import org.apache.brooklyn.util.core.flags.FlagUtils;
 import org.apache.brooklyn.util.core.flags.TypeCoercions;
+import org.apache.brooklyn.util.core.task.DeferredSupplier;
+import org.apache.brooklyn.util.core.task.Tasks;
+import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.stream.Streams;
 import org.slf4j.Logger;
@@ -386,17 +390,33 @@ public abstract class AbstractLocation extends AbstractBrooklynObject implements
 
         @Override
         public <T> T get(ConfigKey<T> key) {
-            if (hasConfig(key, false)) return getLocalBag().get(key);
-            if (getParent() != null && isInherited(key)) {
-                return getParent().getConfig(key);
+            Object result = null;
+            if (hasConfig(key, false)) {
+                result = getLocalBag().getAllConfigRaw().get(key.getName());
+
+            } else if (getParent() != null && isInherited(key)) {
+                result = getParent().getConfig(key);
+
+            } else {
+                // In case this entity class has overridden the given key (e.g. to set default), then retrieve this entity's key
+                // TODO when locations become entities, the duplication of this compared to EntityConfigMap.getConfig will disappear.
+                @SuppressWarnings("unchecked")
+                ConfigKey<T> ownKey = (ConfigKey<T>) elvis(locationType.getConfigKey(key.getName()), key);
+                result = ownKey.getDefaultValue();
+            }
+
+            if (result instanceof DeferredSupplier<?>) {
+                try {
+                    ManagementContext mgmt = AbstractLocation.this.getManagementContext();
+                    ExecutionContext exec = mgmt.getServerExecutionContext();
+                    result = Tasks.resolveValue(result, key.getType(), exec);
+
+                } catch (Exception e) {
+                    throw Exceptions.propagate(e);
+                }
             }
-            
-            // In case this entity class has overridden the given key (e.g. to set default), then retrieve this entity's key
-            // TODO when locations become entities, the duplication of this compared to EntityConfigMap.getConfig will disappear.
-            @SuppressWarnings("unchecked")
-            ConfigKey<T> ownKey = (ConfigKey<T>) elvis(locationType.getConfigKey(key.getName()), key);
 
-            return ownKey.getDefaultValue();
+            return TypeCoercions.coerce(result, key.getTypeToken());
         }
 
         @Override