Java Code Examples for backtype.storm.tuple.Tuple#getSourceComponent()

The following examples show how to use backtype.storm.tuple.Tuple#getSourceComponent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SingleJoinBolt.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple tuple) {
    List<Object> id = tuple.select(_idFields);
    GlobalStreamId streamId = new GlobalStreamId(tuple.getSourceComponent(), tuple.getSourceStreamId());
    if (!_pending.containsKey(id)) {
        _pending.put(id, new HashMap<GlobalStreamId, Tuple>());
    }
    Map<GlobalStreamId, Tuple> parts = _pending.get(id);
    if (parts.containsKey(streamId))
        throw new RuntimeException("Received same side of single join twice");
    parts.put(streamId, tuple);
    if (parts.size() == _numSources) {
        _pending.remove(id);
        List<Object> joinResult = new ArrayList<Object>();
        for (String outField : _outFields) {
            GlobalStreamId loc = _fieldLocations.get(outField);
            joinResult.add(parts.get(loc).getValueByField(outField));
        }
        _collector.emit(new ArrayList<Tuple>(parts.values()), joinResult);
        
        for (Tuple part : parts.values()) {
            _collector.ack(part);
        }
    }
}
 
Example 2
Source File: TupleCaptureBolt.java    From jstorm with Apache License 2.0 5 votes vote down vote up
public void execute(Tuple input) {
    String component = input.getSourceComponent();
    Map<String, List<FixedTuple>> captured = emitted_tuples.get(_name);
    if (!captured.containsKey(component)) {
        captured.put(component, new ArrayList<FixedTuple>());
    }
    captured.get(component).add(new FixedTuple(input.getSourceStreamId(), input.getValues()));
    _collector.ack(input);
}
 
Example 3
Source File: SingleJoinBolt.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple) {
    List<Object> id = tuple.select(_idFields);
    GlobalStreamId streamId = new GlobalStreamId(tuple.getSourceComponent(), tuple.getSourceStreamId());
    if (!_pending.containsKey(id)) {
        _pending.put(id, new HashMap<GlobalStreamId, Tuple>());
    }
    Map<GlobalStreamId, Tuple> parts = _pending.get(id);
    if (parts.containsKey(streamId))
        throw new RuntimeException("Received same side of single join twice");
    parts.put(streamId, tuple);
    if (parts.size() == _numSources) {
        _pending.remove(id);
        List<Object> joinResult = new ArrayList<Object>();
        for (String outField : _outFields) {
            GlobalStreamId loc = _fieldLocations.get(outField);
            joinResult.add(parts.get(loc).getValueByField(outField));
        }
        _collector.emit(new ArrayList<Tuple>(parts.values()), joinResult);

        for (Tuple part : parts.values()) {
            _collector.ack(part);
        }
        
        SingleJoinTest.receiveCounter.incrementAndGet();
    }
}