Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/155#discussion_r73860519
  
    --- Diff: 
camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/DslComponent.java
 ---
    @@ -275,6 +285,95 @@ public String toString() {
             }
         }
     
    +    public BrooklynDslDeferredSupplier<?> effector(final String 
effectorName) {
    +        return new ExecuteEffector(this, effectorName, 
ImmutableMap.<String, Object>of());
    +    }
    +    public BrooklynDslDeferredSupplier<?> effector(final String 
effectorName, final Map<String, ?> args) {
    +        return new ExecuteEffector(this, effectorName, args);
    +    }
    +    public BrooklynDslDeferredSupplier<?> effector(final String 
effectorName, Object... args) {
    +        return new ExecuteEffector(this, effectorName, 
ImmutableList.copyOf(args));
    +    }
    +    protected static class ExecuteEffector extends 
BrooklynDslDeferredSupplier<Object> implements HasSideEffects {
    +        private static final long serialVersionUID = 1740899524088902383L;
    +        private final DslComponent component;
    +        private final String effectorName;
    +        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;
    +            this.argList = args;
    +            this.args = null;
    +        }
    +        @SuppressWarnings("unchecked")
    +        @Override
    +        public Task<Object> newTask() {
    +            Entity targetEntity = component.get();
    +            Maybe<Effector<?>> targetEffector = 
targetEntity.getEntityType().getEffectorByName(effectorName);
    +            if (targetEffector.isAbsentOrNull()) {
    +                throw new IllegalArgumentException("Effector " + 
effectorName + " not found on entity: " + targetEntity);
    +            }
    +            if (cachedTask == null) {
    --- End diff --
    
    `cachedTask` is accessed from multiple threads. Should we use some locking 
to make sure we are creating it only once?


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

Reply via email to