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;
}
Aggregations