Java Code Examples for org.apache.storm.tuple.Tuple#getSourceStreamId()

The following examples show how to use org.apache.storm.tuple.Tuple#getSourceStreamId() . 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 storm_spring_boot_demo with MIT License 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: SingleJoinBolt.java    From storm-net-adapter 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 3
Source File: RealtimeJoinBolt.java    From streamline with Apache License 2.0 5 votes vote down vote up
String getStreamId(Tuple ti) {
    switch (value) {
        case 0:
            return ti.getSourceStreamId();
        case 1:
            return ti.getSourceComponent();
        default:
            throw new RuntimeException(value + " is unexpected");
    }
}
 
Example 4
Source File: SLMultistreamTimestampExtractor.java    From streamline with Apache License 2.0 5 votes vote down vote up
@Override
public long extractTimestamp(Tuple tuple) {
    FieldSelector tsFieldSel = tsFields.get( tuple.getSourceStreamId() );
    if (tsFieldSel == null) {
        throw new IllegalArgumentException("Unrecognized source stream in Event: '" + tuple.getSourceStreamId() + "'");
    }
    Object tsField = tsFieldSel.findField(tuple);
    if (tsField == null) {
        throw new IllegalArgumentException("Timestamp field not found in event : '" + tsFieldSel.outputName + "'");
    }
    return Long.parseLong(tsField.toString());
}