use of org.apache.storm.tuple.Tuple in project cradle by BingLau7.
the class WordNormailzer method execute.
@Override
public void execute(Tuple input) {
String sentence = input.getString(0);
String[] words = sentence.split(" ");
for (String word : words) {
word = word.trim();
if (!word.isEmpty()) {
word = word.toLowerCase();
List<Tuple> a = new ArrayList<>();
a.add(input);
collector.emit(a, new Values(word));
}
}
collector.ack(input);
}
use of org.apache.storm.tuple.Tuple in project heron by twitter.
the class OutputCollectorImpl method emitDirect.
@Override
public void emitDirect(int taskId, String streamId, Collection<Tuple> anchors, List<Object> tuple) {
if (anchors != null) {
ArrayList<com.twitter.heron.api.tuple.Tuple> l = new ArrayList<com.twitter.heron.api.tuple.Tuple>();
for (Tuple t : anchors) {
TupleImpl i = (TupleImpl) t;
l.add(i.getDelegate());
}
delegate.emitDirect(taskId, streamId, l, tuple);
} else {
delegate.emitDirect(taskId, streamId, (Collection<com.twitter.heron.api.tuple.Tuple>) null, tuple);
}
}
use of org.apache.storm.tuple.Tuple in project heron by twitter.
the class OutputCollectorImpl method emit.
@Override
public List<Integer> emit(String streamId, Collection<Tuple> anchors, List<Object> tuple) {
if (anchors != null) {
ArrayList<com.twitter.heron.api.tuple.Tuple> l = new ArrayList<com.twitter.heron.api.tuple.Tuple>();
for (Tuple t : anchors) {
TupleImpl i = (TupleImpl) t;
l.add(i.getDelegate());
}
return delegate.emit(streamId, l, tuple);
} else {
return delegate.emit(streamId, (Collection<com.twitter.heron.api.tuple.Tuple>) null, tuple);
}
}
use of org.apache.storm.tuple.Tuple in project storm by apache.
the class CoordinatedBolt method checkFinishId.
private boolean checkFinishId(Tuple tup, TupleType type) {
Object id = tup.getValue(0);
boolean failed = false;
synchronized (_tracked) {
TrackingInfo track = _tracked.get(id);
try {
if (track != null) {
boolean delayed = false;
if (_idStreamSpec == null && type == TupleType.COORD || _idStreamSpec != null && type == TupleType.ID) {
track.ackTuples.add(tup);
delayed = true;
}
if (track.failed) {
failed = true;
for (Tuple t : track.ackTuples) {
_collector.fail(t);
}
_tracked.remove(id);
} else if (track.receivedId && (_sourceArgs.isEmpty() || track.reportCount == _numSourceReports && track.expectedTupleCount == track.receivedTuples)) {
if (_delegate instanceof FinishedCallback) {
((FinishedCallback) _delegate).finishedId(id);
}
if (!(_sourceArgs.isEmpty() || type != TupleType.REGULAR)) {
throw new IllegalStateException("Coordination condition met on a non-coordinating tuple. Should be impossible");
}
Iterator<Integer> outTasks = _countOutTasks.iterator();
while (outTasks.hasNext()) {
int task = outTasks.next();
int numTuples = get(track.taskEmittedTuples, task, 0);
_collector.emitDirect(task, Constants.COORDINATED_STREAM_ID, tup, new Values(id, numTuples));
}
for (Tuple t : track.ackTuples) {
_collector.ack(t);
}
track.finished = true;
_tracked.remove(id);
}
if (!delayed && type != TupleType.REGULAR) {
if (track.failed) {
_collector.fail(tup);
} else {
_collector.ack(tup);
}
}
} else {
if (type != TupleType.REGULAR)
_collector.fail(tup);
}
} catch (FailedException e) {
LOG.error("Failed to finish batch", e);
for (Tuple t : track.ackTuples) {
_collector.fail(t);
}
_tracked.remove(id);
failed = true;
}
}
return failed;
}
use of org.apache.storm.tuple.Tuple in project storm by apache.
the class EsIndexBoltTest method testEsIndexBolt.
@Test
public void testEsIndexBolt() throws Exception {
String index = "index1";
String type = "type1";
Tuple tuple = createTestTuple(index, type);
bolt.execute(tuple);
verify(outputCollector).ack(tuple);
node.client().admin().indices().prepareRefresh(index).execute().actionGet();
CountResponse resp = node.client().prepareCount(index).setQuery(new TermQueryBuilder("_type", type)).execute().actionGet();
Assert.assertEquals(1, resp.getCount());
}
Aggregations