Search in sources :

Example 31 with Values

use of org.apache.heron.api.tuple.Values in project heron by twitter.

the class TestBolt method execute.

@Override
public void execute(Tuple tuple) {
    AtomicInteger ackCount = (AtomicInteger) SingletonRegistry.INSTANCE.getSingleton(Constants.ACK_COUNT);
    AtomicInteger failCount = (AtomicInteger) SingletonRegistry.INSTANCE.getSingleton(Constants.FAIL_COUNT);
    AtomicInteger tupleExecutedCount = (AtomicInteger) SingletonRegistry.INSTANCE.getSingleton(Constants.EXECUTE_COUNT);
    CountDownLatch tupleExecutedLatch = (CountDownLatch) SingletonRegistry.INSTANCE.getSingleton(Constants.EXECUTE_LATCH);
    StringBuilder receivedStrings = (StringBuilder) SingletonRegistry.INSTANCE.getSingleton(Constants.RECEIVED_STRING_LIST);
    if (receivedStrings != null) {
        receivedStrings.append(tuple.getString(0));
    }
    if (tupleExecutedCount != null) {
        tupleExecutedCount.getAndIncrement();
    }
    if ((tupleExecuted & 1) == 0) {
        outputCollector.ack(tuple);
        if (ackCount != null) {
            ackCount.getAndIncrement();
        }
    } else {
        outputCollector.fail(tuple);
        if (failCount != null) {
            failCount.getAndIncrement();
        }
    }
    tupleExecuted++;
    outputCollector.emit(new Values(tuple.getString(0)));
    if (tupleExecutedLatch != null) {
        tupleExecutedLatch.countDown();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Values(org.apache.heron.api.tuple.Values) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 32 with Values

use of org.apache.heron.api.tuple.Values in project heron by twitter.

the class LocalFileSpout method nextTuple.

// We do not explicitly close the buffered reader, even on EoF. This is in case more content is
// added to file, we will read that content as well
@Override
public void nextTuple() {
    if (br == null) {
        return;
    }
    try {
        String currentLine;
        if ((currentLine = br.readLine()) != null) {
            collector.emit(new Values(currentLine));
        } else {
            br.close();
            br = null;
        }
    } catch (IOException e) {
        // Clean stuff if any exceptions
        try {
            // Close the outmost is enough
            if (br != null) {
                br.close();
            }
        } catch (IOException e1) {
            throw new RuntimeException("Unable to close stream reader", e1);
        }
        throw new RuntimeException("Unable to emit tuples normally", e);
    }
}
Also used : Values(org.apache.heron.api.tuple.Values) IOException(java.io.IOException)

Example 33 with Values

use of org.apache.heron.api.tuple.Values in project heron by twitter.

the class HdfsStringSpout method nextTuple.

@Override
public void nextTuple() {
    if (br == null) {
        return;
    }
    try {
        String line = "";
        if ((line = br.readLine()) != null) {
            collector.emit(new Values(line));
        } else {
            br.close();
            br = null;
        }
    } catch (IOException e) {
        // Clean stuff if any exceptions
        try {
            // Close the outmost is enough
            br.close();
        } catch (IOException e1) {
            throw new RuntimeException("Unable to close stream reader", e1);
        }
        throw new RuntimeException("Unable to emit tuples normally", e);
    }
}
Also used : Values(org.apache.heron.api.tuple.Values) IOException(java.io.IOException)

Example 34 with Values

use of org.apache.heron.api.tuple.Values in project heron by twitter.

the class TestBasicBolt method execute.

@Override
public void execute(Tuple input, BasicOutputCollector collector) {
    tupleExecuted++;
    collector.emit(new Values(input.getString(0)));
}
Also used : Values(org.apache.heron.api.tuple.Values)

Example 35 with Values

use of org.apache.heron.api.tuple.Values in project heron by twitter.

the class GeneralReduceByKeyAndWindowOperatorTest method getTupleWindow.

private TupleWindow getTupleWindow(int nkeys, int count) {
    TopologyAPI.StreamId componentStreamId = TopologyAPI.StreamId.newBuilder().setComponentName("sourceComponent").setId("default").build();
    List<Tuple> tuples = new LinkedList<>();
    for (int i = 0; i < nkeys; i++) {
        for (int j = 0; j < count; ++j) {
            Tuple tuple = getTuple(componentStreamId, new Fields("a"), new Values(new KeyValue<>(String.valueOf(i), j)));
            tuples.add(tuple);
        }
    }
    TupleWindow tupleWindow = new TupleWindowImpl(tuples, new LinkedList<>(), new LinkedList<>(), startTime, endTime);
    return tupleWindow;
}
Also used : Fields(org.apache.heron.api.tuple.Fields) KeyValue(org.apache.heron.streamlet.KeyValue) TupleWindowImpl(org.apache.heron.api.windowing.TupleWindowImpl) Values(org.apache.heron.api.tuple.Values) TupleWindow(org.apache.heron.api.windowing.TupleWindow) Tuple(org.apache.heron.api.tuple.Tuple) LinkedList(java.util.LinkedList) TopologyAPI(org.apache.heron.api.generated.TopologyAPI)

Aggregations

Values (org.apache.heron.api.tuple.Values)37 Tuple (org.apache.heron.api.tuple.Tuple)8 KeyValue (org.apache.heron.streamlet.KeyValue)7 TupleWindow (org.apache.heron.api.windowing.TupleWindow)6 Fields (org.apache.heron.api.tuple.Fields)5 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)3 TupleWindowImpl (org.apache.heron.api.windowing.TupleWindowImpl)3 KeyedWindow (org.apache.heron.streamlet.KeyedWindow)2 Window (org.apache.heron.streamlet.Window)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Random (java.util.Random)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 TopologyContext (org.apache.heron.api.topology.TopologyContext)1 SerializablePredicate (org.apache.heron.streamlet.SerializablePredicate)1