You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by dr...@apache.org on 2017/02/28 15:02:12 UTC
[4/7] brooklyn-server git commit: Tidy up DSL effector method
Tidy up DSL effector method
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/8efc7627
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/8efc7627
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/8efc7627
Branch: refs/heads/master
Commit: 8efc762725c03b5860d52038b1b1c49e119d891e
Parents: 5118a35
Author: Andrew Donald Kennedy <an...@cloudsoftcorp.com>
Authored: Tue Jul 5 07:22:51 2016 +0100
Committer: Andrew Donald Kennedy <an...@cloudsoftcorp.com>
Committed: Tue Feb 28 14:26:43 2017 +0000
----------------------------------------------------------------------
.../brooklyn/spi/dsl/methods/DslComponent.java | 53 ++++++++++----------
1 file changed, 26 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8efc7627/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 f08e4bd..891f1f2 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
@@ -560,46 +560,45 @@ public class DslComponent extends BrooklynDslDeferredSupplier<Entity> implements
if (targetEffector.isAbsentOrNull()) {
throw new IllegalArgumentException("Effector " + effectorName + " not found on entity: " + targetEntity);
}
- if (null == cachedTask) {
- cachedTask = null == argList
- ? Entities.invokeEffector(targetEntity, targetEntity, targetEffector.get(), args)
- : invokeWithDeferredArgs(targetEntity, targetEffector.get(), argList);
-// : Entities.invokeEffectorWithArgs(targetEntity, targetEntity, targetEffector.get(), argList.toArray());
+ 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;
}
-
- public static Task<Object> invokeWithDeferredArgs(final Entity targetEntity, final Effector<?> targetEffector, final List<? extends Object> args) {
+ 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() );
+ 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());
}
return DependentConfiguration.transformMultiple(
- MutableMap.<String,String>of("displayName", "invoking '"+targetEffector.getName()+"' with "+taskArgs.size()+" task"+(taskArgs.size()!=1?"s":"")),
+ MutableMap.of("displayName", "invoking '"+targetEffector.getName()+"' with "+taskArgs.size()+" task"+(taskArgs.size()!=1?"s":"")),
new Function<List<Object>, Object>() {
- @Override public Object apply(List<Object> input) {
- Iterator<?> tri = input.iterator();
- 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;
- i++;
- }
-
- return Entities.invokeEffectorWithArgs(targetEntity, targetEntity, targetEffector, vv);
- }},
- taskArgs);
+ @Override
+ public Object apply(List<Object> input) {
+ Iterator<?> tri = input.iterator();
+ 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;
+ i++;
+ }
+ return Entities.invokeEffectorWithArgs(targetEntity, targetEntity, targetEffector, vv);
+ }
+ },
+ taskArgs);
}
-
@Override
public int hashCode() {
return Objects.hashCode(component, effectorName);
}
-
@Override
public boolean equals(Object obj) {
if (this == obj) return true;