Search in sources :

Example 6 with GroovyScriptEngine

use of com.hortonworks.streamline.streams.runtime.script.engine.GroovyScriptEngine in project streamline by hortonworks.

the class RuleProcessorRuntime method createGroovyScript.

private Script createGroovyScript(Rule rule) {
    LOG.info("Creating groovy execution script for rule {} ", rule);
    GroovyExpression groovyExpression = new GroovyExpression(rule.getCondition());
    GroovyScriptEngine groovyScriptEngine = new GroovyScriptEngine();
    GroovyScript<Boolean> groovyScript = createHelperGroovyScript(groovyExpression, groovyScriptEngine);
    GroovyScript<Collection<StreamlineEvent>> wrapper = new GroovyScript<Collection<StreamlineEvent>>(groovyExpression.asString(), groovyScriptEngine) {

        @Override
        public Collection<StreamlineEvent> evaluate(StreamlineEvent event) throws ScriptException {
            if (groovyScript.evaluate(event)) {
                return Collections.singletonList(event);
            } else {
                return Collections.emptyList();
            }
        }
    };
    return wrapper;
}
Also used : GroovyScript(com.hortonworks.streamline.streams.runtime.script.GroovyScript) GroovyScriptEngine(com.hortonworks.streamline.streams.runtime.script.engine.GroovyScriptEngine) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Collection(java.util.Collection) GroovyExpression(com.hortonworks.streamline.streams.runtime.rule.condition.expression.GroovyExpression)

Aggregations

GroovyScriptEngine (com.hortonworks.streamline.streams.runtime.script.engine.GroovyScriptEngine)6 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)4 ArrayList (java.util.ArrayList)3 GroovyExpression (com.hortonworks.streamline.streams.runtime.rule.condition.expression.GroovyExpression)1 GroovyScript (com.hortonworks.streamline.streams.runtime.script.GroovyScript)1 Collection (java.util.Collection)1 Random (java.util.Random)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ScriptException (javax.script.ScriptException)1