All Downloads are FREE. Search and download functionalities are using the official Maven repository.

brooklyn.entity.basic.ExplicitEffector Maven / Gradle / Ivy

There is a newer version: 0.7.0-M1
Show newest version
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