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

The following examples show how to use org.apache.storm.tuple.Tuple#getBinary() . 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: 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 2
Source File: JSONFromPosition.java    From metron with Apache License 2.0 5 votes vote down vote up
@Override
public JSONObject get(Tuple tuple) {
  String s = null;
  try {
    s =  new String(tuple.getBinary(position), Charsets.UTF_8);
    return (JSONObject) parser.get().parse(s);
  } catch (Exception e) {
    throw new IllegalStateException("Unable to parse " + s + " due to " + e.getMessage(), e);
  }
}
 
Example 3
Source File: BytesFromPosition.java    From metron with Apache License 2.0 4 votes vote down vote up
@Override
public byte[] get(Tuple tuple) {
  return tuple.getBinary(position);
}