Search in sources :

Example 1 with SerializablePredicate

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);
}
Also used : Values(org.apache.heron.api.tuple.Values) SerializablePredicate(org.apache.heron.streamlet.SerializablePredicate) Map(java.util.Map)

Example 2 with SerializablePredicate

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;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SerializablePredicate(org.apache.heron.streamlet.SerializablePredicate) MalformedURLException(java.net.MalformedURLException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Config(org.apache.heron.api.Config) AbstractTestTopology(org.apache.heron.integration_test.common.AbstractTestTopology) HashMap(java.util.HashMap) Builder(org.apache.heron.streamlet.Builder) TestTopologyBuilder(org.apache.heron.integration_test.core.TestTopologyBuilder) BuilderImpl(org.apache.heron.streamlet.impl.BuilderImpl) Streamlet(org.apache.heron.streamlet.Streamlet) BuilderImpl(org.apache.heron.streamlet.impl.BuilderImpl) HashMap(java.util.HashMap) Builder(org.apache.heron.streamlet.Builder) TestTopologyBuilder(org.apache.heron.integration_test.core.TestTopologyBuilder) SerializablePredicate(org.apache.heron.streamlet.SerializablePredicate) TestTopologyBuilder(org.apache.heron.integration_test.core.TestTopologyBuilder)

Aggregations

Map (java.util.Map)2 SerializablePredicate (org.apache.heron.streamlet.SerializablePredicate)2 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Config (org.apache.heron.api.Config)1 Values (org.apache.heron.api.tuple.Values)1 AbstractTestTopology (org.apache.heron.integration_test.common.AbstractTestTopology)1 TestTopologyBuilder (org.apache.heron.integration_test.core.TestTopologyBuilder)1 Builder (org.apache.heron.streamlet.Builder)1 Streamlet (org.apache.heron.streamlet.Streamlet)1 BuilderImpl (org.apache.heron.streamlet.impl.BuilderImpl)1