Java Code Examples for org.apache.storm.topology.BasicOutputCollector#emit()

The following examples show how to use org.apache.storm.topology.BasicOutputCollector#emit() . 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: FilteringBolt.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector basicOutputCollector) {
    int operation = tuple.getIntegerByField("operation");
    if(operation > 0 ) {
        basicOutputCollector.emit(tuple.getValues());
    }
}
 
Example 2
Source File: FastWordCountTopology.java    From storm-net-adapter with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    String word = tuple.getString(0);
    Integer count = counts.get(word);
    if (count == null) {
        count = 0;
    }
    count++;
    counts.put(word, count);
    collector.emit(new Values(word, count));
}
 
Example 3
Source File: FastWordCountTopology.java    From storm-net-adapter with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    String sentence = tuple.getString(0);
    for (String word : sentence.split("\\s+")) {
        collector.emit(new Values(word, 1));
    }
}
 
Example 4
Source File: AnchoredWordCount.java    From storm-net-adapter with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    String word = tuple.getString(0);
    Integer count = counts.get(word);
    if (count == null) {
        count = 0;
    }
    count++;
    counts.put(word, count);
    collector.emit(new Values(word, count));
}
 
Example 5
Source File: AnchoredWordCount.java    From storm-net-adapter with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    String sentence = tuple.getString(0);
    for (String word : sentence.split("\\s+")) {
        collector.emit(new Values(word, 1));
    }
}
 
Example 6
Source File: ReachTopology.java    From storm-net-adapter with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    Object id = tuple.getValue(0);
    String tweeter = tuple.getString(1);
    List<String> followers = FOLLOWERS_DB.get(tweeter);
    if (followers != null) {
        for (String follower : followers) {
            collector.emit(new Values(id, follower));
        }
    }
}
 
Example 7
Source File: HttpdLoglineParserBolt.java    From logparser with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    String apacheLogLine = tuple.getStringByField(readFieldName);
    try {
        List<Object> out = new ArrayList<>();
        out.add(parser.parse(apacheLogLine));
        collector.emit(out);
    } catch (MissingDissectorsException
            |InvalidDissectorException
            |DissectionFailure e) {
        e.printStackTrace();
    }
}
 
Example 8
Source File: WordCountTopology.java    From storm-net-adapter with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    String word = tuple.getString(0);
    Integer count = counts.get(word);
    if (count == null) {
        count = 0;
    }
    count++;
    counts.put(word, count);
    collector.emit(new Values(word, count));
}
 
Example 9
Source File: ConvertIPBolt.java    From storm-statistic with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
    byte[] binary = input.getBinary(0);
    String line = new String(binary);
    String[] fields = line.split("\t");

    if(fields == null || fields.length < 10) {
        return;
    }

    // 获取ip和mid
    String ip = fields[1];
    String mid = fields[2];

    // 根据ip获取其所属地(省份)
    String province = null;
    if (ip != null) {
        Jedis jedis = JedisUtil.getJedis();
        province = jedis.hget("ip_info_en", ip);
        // 需要释放jedis的资源,否则会报can not get resource from the pool
        JedisUtil.returnJedis(jedis);
    }

    // 发送数据到下一个bolt,只发送实现业务功能需要的province和mid
    collector.emit(new Values(province, mid));

}
 
Example 10
Source File: SentenceWordCountTopology.java    From incubator-heron with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
  String word = tuple.getString(0);
  Integer count = counts.get(word);
  if (count == null) {
    count = 0;
  }
  count++;
  counts.put(word, count);
  collector.emit(new Values(word, count));
}
 
Example 11
Source File: SentenceWordCountTopology.java    From incubator-heron with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
  String sentence = tuple.getString(0);
  for (String word : sentence.split("\\s+")) {
    collector.emit(new Values(word, 1));
  }
}
 
Example 12
Source File: PartitionDataBolt.java    From incubator-retired-pirk with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector outputCollector)
{
  int hash = tuple.getIntegerByField(StormConstants.HASH_FIELD);
  json = (JSONObject) tuple.getValueByField(StormConstants.JSON_DATA_FIELD);

  try
  {
    List<BigInteger> partitions = QueryUtils.partitionDataElement(qSchema, json, embedSelector);

    logger.debug("HashSelectorsAndPartitionDataBolt processing {} outputting results - {}", json.toString(), partitions.size());

    // splitPartitions determines whether each partition piece is sent individually or the full Array is sent together.
    // Since processing in the follow-on bolt (EncRowCalcBolt) is computationally expensive, current working theory is
    // that splitting them up allows for better throughput. Though maybe with better knowledge/tuning of Storm internals
    // and paramters (e.g. certain buffer sizes), it may make no difference.
    if (splitPartitions)
    {
      for (BigInteger partition : partitions)
      {
        outputCollector.emit(new Values(hash, partition));
      }
    }
    else
    {
      outputCollector.emit(new Values(hash, partitions));
    }

  } catch (Exception e)
  {
    logger.warn("Failed to partition data for record -- " + json + "\n", e);
  }
}
 
Example 13
Source File: SplitSentenceBolt.java    From storm_spring_boot_demo with MIT License 5 votes vote down vote up
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
    String sentence = input.getStringByField("value");
    for(int i=0;i<sentence.length();i++){
        char word = sentence.charAt(i);
        collector.emit(new Values(word+""));//分词emit,只有1个单词的元组Tuple
    }
}
 
Example 14
Source File: SentenceWordCountTopology.java    From twister2 with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
  String sentence = tuple.getString(0);
  System.out.println("Sentence received : " + sentence);
  for (String word : sentence.split("\\s+")) {
    collector.emit(new Values(word, 1));
  }
}
 
Example 15
Source File: WordCountTopologyNode.java    From storm-net-adapter with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    String word = tuple.getString(0);
    Integer count = counts.get(word);
    if (count == null) {
        count = 0;
    }
    count++;
    counts.put(word, count);
    collector.emit(new Values(word, count));
}
 
Example 16
Source File: AbstractRankerBolt.java    From storm-net-adapter with Apache License 2.0 4 votes vote down vote up
private void emitRankings(BasicOutputCollector collector) {
    collector.emit(new Values(rankings.copy()));
    getLogger().debug("Rankings: " + rankings);
}
 
Example 17
Source File: EvenAndOddBolt.java    From incubator-heron with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
  int number = getTupleValue(input, 0);

  if (number % 2 == 0) {
    System.out.println("Emitting to evens stream: " + number);
    collector.emit("evens", tuple(input.getValues().get(0)));

  } else {
    System.out.println("emitting to odds stream: " + number);
    collector.emit("odds", tuple(input.getValues().get(0)));
  }

  collector.emit(tuple(input.getValues().get(0)));



}
 
Example 18
Source File: ManualDRPC.java    From storm-net-adapter with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    String arg = tuple.getString(0);
    Object retInfo = tuple.getValue(1);
    collector.emit(new Values(arg + "!!!", retInfo));
}
 
Example 19
Source File: BasicDRPCTopology.java    From storm-net-adapter with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    String input = tuple.getString(1);
    collector.emit(new Values(tuple.getValue(0), input + "!"));
}
 
Example 20
Source File: AbstractRankerBolt.java    From storm_spring_boot_demo with MIT License 4 votes vote down vote up
private void emitRankings(BasicOutputCollector collector) {
  collector.emit(new Values(rankings.copy()));
  getLogger().debug("Rankings: " + rankings);
}