Java Code Examples for org.apache.storm.tuple.Values#add()

The following examples show how to use org.apache.storm.tuple.Values#add() . 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: NiFiSpout.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void nextTuple() {
    NiFiDataPacket data = queue.poll();
    if (data == null) {
        Utils.sleep(50);
    } else {
        // always start with the data packet
        Values values = new Values(data);

        // add additional values based on the specified attribute names
        for (String attributeName : attributeNames) {
            if (data.getAttributes().containsKey(attributeName)) {
                values.add(data.getAttributes().get(attributeName));
            }
        }

        spoutOutputCollector.emit(values);
    }
}
 
Example 2
Source File: JSONScheme.java    From nightwatch with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public List<Object> deserialize(ByteBuffer ser) {
    String jsonStr = null;
    if (ser.hasArray()) {
        int base = ser.arrayOffset();
        jsonStr = new String(ser.array(), base + ser.position(), ser.remaining());
    } else {
        jsonStr = new String(Utils.toByteArray(ser), UTF8_CHARSET);
    }
    JSONObject jsonObject = JSONObject.fromObject(jsonStr);
    Values values = new Values();
    for (String outputField : outputFields) {
        if("jsonBody".equals(outputField)) {
            values.add(jsonStr);
        } else {
            if(!jsonObject.containsKey(outputField)) {
                JSONObject rcMsgpara = JSONObject.fromObject(jsonObject.get("rc_msg_para"));
                values.add(rcMsgpara.get(outputField));
            } else {
                values.add(jsonObject.get(outputField));
            }
        }
    }
    return values;
}
 
Example 3
Source File: NiFiSpout.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void nextTuple() {
    NiFiDataPacket data = queue.poll();
    if (data == null) {
        Utils.sleep(50);
    } else {
        // always start with the data packet
        Values values = new Values(data);

        // add additional values based on the specified attribute names
        for (String attributeName : attributeNames) {
            if (data.getAttributes().containsKey(attributeName)) {
                values.add(data.getAttributes().get(attributeName));
            }
        }

        spoutOutputCollector.emit(values);
    }
}
 
Example 4
Source File: SimpleStormKafkaBuilder.java    From metron with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a list of tuples using the ConsumerRecord specified as parameter
 *
 * @param consumerRecord whose contents are used to build tuples
 * @return list of tuples
 */
@Override
public List<Object> apply(ConsumerRecord<K, V> consumerRecord) {
  Values ret = new Values();
  for(FieldsConfiguration config : configurations) {
    ret.add(config.recordExtractor.apply(consumerRecord));
  }
  return ret;
}