use of org.apache.heron.streamlet.SerializablePredicate in project heron by twitter.
the class SplitOperator method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(Tuple tuple) {
R obj = (R) tuple.getValue(0);
for (Map.Entry<String, SerializablePredicate<R>> entry : splitFns.entrySet()) {
if (entry.getValue().test(obj)) {
collector.emit(entry.getKey(), new Values(obj));
}
}
collector.ack(tuple);
}
use of org.apache.heron.streamlet.SerializablePredicate in project heron by twitter.
the class StreamletWithSplitAndWithStream method buildTopology.
@Override
protected TestTopologyBuilder buildTopology(TestTopologyBuilder testTopologyBuilder) {
Map<String, SerializablePredicate<Integer>> splitter = new HashMap();
splitter.put("all", i -> true);
splitter.put("positive", i -> i > 0);
splitter.put("negative", i -> i < 0);
Builder streamletBuilder = Builder.newBuilder();
Streamlet<Integer> multi = streamletBuilder.newSource(() -> atomicInteger.getAndIncrement()).setName("incremented-numbers-from--3").filter(i -> i <= 4).setName("numbers-lower-than-4").split(splitter).setName("split");
multi.withStream("all").map((Integer i) -> String.format("all_%d", i));
multi.withStream("positive").map((Integer i) -> String.format("pos_%d", i));
multi.withStream("negative").map((Integer i) -> String.format("neg_%d", i));
BuilderImpl streamletBuilderImpl = (BuilderImpl) streamletBuilder;
TestTopologyBuilder topology = (TestTopologyBuilder) streamletBuilderImpl.build(testTopologyBuilder);
return topology;
}
Aggregations