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

The following examples show how to use org.apache.storm.tuple.Tuple#getSourceTask() . 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: RollingCountAggBolt.java    From storm_spring_boot_demo with MIT License 6 votes vote down vote up
@Override
public void execute(Tuple tuple) {
  Object obj = tuple.getValue(0);
  long count = tuple.getLong(1);
  int source = tuple.getSourceTask();
  Map<Integer, Long> subCounts = counts.get(obj);
  if (subCounts == null) {
    subCounts = new HashMap<Integer, Long>();
    counts.put(obj, subCounts);
  }
  //Update the current count for this object
  subCounts.put(source, count);
  //Output the sum of all the known counts so for this key
  long sum = 0;
  for (Long val: subCounts.values()) {
    sum += val;
  }
  collector.emit(new Values(obj, sum));
}
 
Example 2
Source File: RollingCountAggBolt.java    From storm-net-adapter with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple tuple) {
    Object obj = tuple.getValue(0);
    long count = tuple.getLong(1);
    int source = tuple.getSourceTask();
    Map<Integer, Long> subCounts = counts.get(obj);
    if (subCounts == null) {
        subCounts = new HashMap<Integer, Long>();
        counts.put(obj, subCounts);
    }
    //Update the current count for this object
    subCounts.put(source, count);
    //Output the sum of all the known counts so for this key
    long sum = 0;
    for (Long val : subCounts.values()) {
        sum += val;
    }
    collector.emit(new Values(obj, sum));
}