brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From drigod...@apache.org
Subject [3/7] brooklyn-server git commit: Add locking on cachedTask for DSL effector
Date Tue, 28 Feb 2017 15:02:11 GMT
Add locking on cachedTask for DSL effector


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

Branch: refs/heads/master
Commit: 3bb0397cac9c2d62d757f5e27547a28c789cf2f4
Parents: 8efc762
Author: Andrew Donald Kennedy <andrew.kennedy@cloudsoftcorp.com>
Authored: Wed Aug 10 09:04:04 2016 +0100
Committer: Andrew Donald Kennedy <andrew.kennedy@cloudsoftcorp.com>
Committed: Tue Feb 28 14:26:43 2017 +0000

----------------------------------------------------------------------
 .../brooklyn/spi/dsl/methods/DslComponent.java  | 35 ++++++++++++++------
 1 file changed, 25 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3bb0397c/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/DslComponent.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/DslComponent.java
b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/DslComponent.java
index 891f1f2..3df68db 100644
--- a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/DslComponent.java
+++ b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/DslComponent.java
@@ -539,12 +539,14 @@ public class DslComponent extends BrooklynDslDeferredSupplier<Entity>
implements
         private final Map<String, ?> args;
         private final List<? extends Object> argList;
         private Task<?> cachedTask;
+
         public ExecuteEffector(DslComponent component, String effectorName, Map<String,
?> args) {
             this.component = Preconditions.checkNotNull(component);
             this.effectorName = effectorName;
             this.args = args;
             this.argList = null;
         }
+
         public ExecuteEffector(DslComponent component, String effectorName, List<? extends
Object> args) {
             this.component = Preconditions.checkNotNull(component);
             this.effectorName = effectorName;
@@ -560,20 +562,26 @@ public class DslComponent extends BrooklynDslDeferredSupplier<Entity>
implements
             if (targetEffector.isAbsentOrNull()) {
                 throw new IllegalArgumentException("Effector " + effectorName + " not found
on entity: " + targetEntity);
             }
-            if (cachedTask == null) {
-                if (argList == null) {
-                    cachedTask = Entities.invokeEffector(targetEntity, targetEntity, targetEffector.get(),
args);
-                } else {
-                    cachedTask = invokeWithDeferredArgs(targetEntity, targetEffector.get(),
argList);
+            synchronized (this) {
+                if (cachedTask == null) {
+                    if (argList == null) {
+                        cachedTask = Entities.invokeEffector(targetEntity, targetEntity,
targetEffector.get(), args);
+                    } else {
+                        cachedTask = invokeWithDeferredArgs(targetEntity, targetEffector.get(),
argList);
+                    }
                 }
             }
             return (Task<Object>) cachedTask;
         }
+
         private Task<Object> invokeWithDeferredArgs(final Entity targetEntity, final
Effector<?> targetEffector, final List<? extends Object> args) {
             List<TaskAdaptable<Object>> taskArgs = Lists.newArrayList();
             for (Object arg : args) {
-                if (arg instanceof TaskAdaptable) taskArgs.add((TaskAdaptable<Object>)
arg);
-                else if (arg instanceof TaskFactory) taskArgs.add(((TaskFactory<TaskAdaptable<Object>>)
arg).newTask());
+                if (arg instanceof TaskAdaptable) {
+                    taskArgs.add((TaskAdaptable<Object>) arg);
+                } else if (arg instanceof TaskFactory) {
+                    taskArgs.add(((TaskFactory<TaskAdaptable<Object>>) arg).newTask());
+                }
             }
 
             return DependentConfiguration.transformMultiple(
@@ -585,9 +593,13 @@ public class DslComponent extends BrooklynDslDeferredSupplier<Entity>
implements
                             Object[] vv = new Object[args.size()];
                             int i=0;
                             for (Object arg : args) {
-                                if (arg instanceof TaskAdaptable || arg instanceof TaskFactory)
vv[i] = tri.next();
-                                else if (arg instanceof DeferredSupplier) vv[i] = ((DeferredSupplier<?>)
arg).get();
-                                else vv[i] = arg;
+                                if (arg instanceof TaskAdaptable || arg instanceof TaskFactory)
{
+                                    vv[i] = tri.next();
+                                } else if (arg instanceof DeferredSupplier) {
+                                    vv[i] = ((DeferredSupplier<?>) arg).get();
+                                } else {
+                                    vv[i] = arg;
+                                }
                                 i++;
                             }
                             return Entities.invokeEffectorWithArgs(targetEntity, targetEntity,
targetEffector, vv);
@@ -595,10 +607,12 @@ public class DslComponent extends BrooklynDslDeferredSupplier<Entity>
implements
                     },
                     taskArgs);
         }
+
         @Override
         public int hashCode() {
             return Objects.hashCode(component, effectorName);
         }
+
         @Override
         public boolean equals(Object obj) {
             if (this == obj) return true;
@@ -607,6 +621,7 @@ public class DslComponent extends BrooklynDslDeferredSupplier<Entity>
implements
             return Objects.equal(this.component, that.component) &&
                     Objects.equal(this.effectorName, that.effectorName);
         }
+
         @Override
         public String toString() {
             return (component.scope==Scope.THIS ? "" : component.toString()+".") +


Mime
View raw message