brooklyn.entity.basic.ExplicitEffector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of brooklyn-core Show documentation
Show all versions of brooklyn-core Show documentation
Entity implementation classes, events, and other core elements
package brooklyn.entity.basic;
import groovy.lang.Closure;
import java.util.List;
import java.util.Map;
import brooklyn.entity.Entity;
import brooklyn.entity.ParameterType;
import com.google.common.collect.ImmutableList;
public abstract class ExplicitEffector extends AbstractEffector {
public ExplicitEffector(String name, Class type, String description) {
this(name, type, ImmutableList.>of(), description);
}
public ExplicitEffector(String name, Class type, List> parameters, String description) {
super(name, type, parameters, description);
}
public T call(Entity entity, Map parameters) {
return invokeEffector((I) entity, parameters );
}
public abstract T invokeEffector(I trait, Map parameters);
/** convenience to create an effector supplying a closure; annotations are preferred,
* and subclass here would be failback, but this is offered as
* workaround for bug GROOVY-5122, as discussed in test class CanSayHi
*/
public static ExplicitEffector create(String name, Class type, List> parameters, String description, Closure body) {
return new ExplicitEffectorFromClosure(name, type, parameters, description, body);
}
private static class ExplicitEffectorFromClosure extends ExplicitEffector {
final Closure body;
public ExplicitEffectorFromClosure(String name, Class type, List> parameters, String description, Closure body) {
super(name, type, parameters, description);
this.body = body;
}
public T invokeEffector(I trait, Map parameters) { return body.call(trait, parameters); }
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy