Search in sources :

Example 1 with RubyOperator

use of org.apache.apex.malhar.contrib.ruby.RubyOperator in project apex-malhar by apache.

the class RubyOperatorBenchmarkApplication method populateDAG.

@Override
public void populateDAG(DAG dag, Configuration conf) {
    RandomEventGenerator rand = dag.addOperator("rand", new RandomEventGenerator());
    rand.setMaxvalue(3000);
    rand.setTuplesBlast(120);
    RandomMapOutput randMap = dag.addOperator("randMap", new RandomMapOutput());
    randMap.setKey("val");
    RubyOperator ruby = dag.addOperator("ruby", new RubyOperator());
    String setupScript = "def square(val)\n";
    setupScript += "  return val*val\nend\n";
    ruby.addSetupScript(setupScript);
    ruby.setInvoke("square");
    ruby.setPassThru(true);
    ConsoleOutputOperator console = dag.addOperator("console", new ConsoleOutputOperator());
    dag.getMeta(console).getMeta(console.input).getAttributes().put(PortContext.QUEUE_CAPACITY, QUEUE_CAPACITY);
    dag.getMeta(ruby).getMeta(ruby.result).getAttributes().put(PortContext.QUEUE_CAPACITY, QUEUE_CAPACITY);
    dag.addStream("rand_randMap", rand.integer_data, randMap.input).setLocality(Locality.THREAD_LOCAL);
    dag.addStream("randMap_ruby", randMap.map_data, ruby.inBindings).setLocality(locality);
    dag.addStream("ruby_console", ruby.result, console.input).setLocality(locality);
}
Also used : ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator) RandomMapOutput(org.apache.apex.benchmark.RandomMapOutput) RubyOperator(org.apache.apex.malhar.contrib.ruby.RubyOperator) RandomEventGenerator(org.apache.apex.malhar.lib.testbench.RandomEventGenerator)

Aggregations

RandomMapOutput (org.apache.apex.benchmark.RandomMapOutput)1 RubyOperator (org.apache.apex.malhar.contrib.ruby.RubyOperator)1 ConsoleOutputOperator (org.apache.apex.malhar.lib.io.ConsoleOutputOperator)1 RandomEventGenerator (org.apache.apex.malhar.lib.testbench.RandomEventGenerator)1