Search in sources :

Example 1 with GroovyScript

use of com.hortonworks.streamline.streams.runtime.script.GroovyScript 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

StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)1 GroovyExpression (com.hortonworks.streamline.streams.runtime.rule.condition.expression.GroovyExpression)1 GroovyScript (com.hortonworks.streamline.streams.runtime.script.GroovyScript)1 GroovyScriptEngine (com.hortonworks.streamline.streams.runtime.script.engine.GroovyScriptEngine)1 Collection (java.util.Collection)1