Java Code Examples for backtype.storm.tuple.Tuple#getLongByField()

The following examples show how to use backtype.storm.tuple.Tuple#getLongByField() . 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: FlattenEventMapper.java    From eagle with Apache License 2.0 6 votes vote down vote up
@Override
public List<StreamEvent> map(Tuple tuple) throws Exception {
    long timestamp;
    if (tuple.getFields().contains(TIMESTAMP_FIELD)) {
        try {
            timestamp = tuple.getLongByField("timestamp");
        } catch (Exception ex) {
            // if timestamp is not null
            LOGGER.error(ex.getMessage(), ex);
            timestamp = 0;
        }
    } else {
        timestamp = System.currentTimeMillis();
    }
    Object[] values = new Object[tuple.getFields().size()];
    for (int i = 0; i < tuple.getFields().size(); i++) {
        values[i] = tuple.getValue(i);
    }
    StreamEvent event = new StreamEvent();
    event.setTimestamp(timestamp);
    event.setStreamId(streamId);
    event.setData(values);
    return Collections.singletonList(event);
}
 
Example 2
Source File: AggregationBolt.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple) {
    Long startTime = tuple.getLongByField("startTime");
    LOG.info("get startTime {}", startTime);
    Long endTime = startTime + stormConfig.aggregationDuration * 1000;

    if (metricsAggregateContainer.aggregate(startTime, endTime)) {
        collector.ack(tuple);
        LOG.info("succeed startTime {}", startTime);
    } else {
        collector.fail(tuple);
        LOG.warn("failed startTime {}", startTime);
    }
}
 
Example 3
Source File: CVParticle.java    From StormCV with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a generic type based on the provided tuple. The tuple must contain streamID and sequenceNR
 * values. 
 * @param tuple
 */
@SuppressWarnings("unchecked")
public CVParticle(Tuple tuple){
	this(tuple.getStringByField(CVParticleSerializer.STREAMID), 
			tuple.getLongByField(CVParticleSerializer.SEQUENCENR));
	this.tuple = tuple;
	this.setRequestId(tuple.getLongByField(CVParticleSerializer.REQUESTID));
	this.setMetadata((HashMap<String, Object>)tuple.getValueByField(CVParticleSerializer.METADATA));
}
 
Example 4
Source File: FeatureSerializer.java    From StormCV with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected Feature createObject(Tuple tuple) throws IOException {
	List<Descriptor> sparseDescriptors = (List<Descriptor>) tuple.getValueByField(SPARSE_DESCR);
	float[][][] denseDescriptors = (float[][][])tuple.getValueByField(DENSE_DESCR);
	Feature feature = new Feature(tuple, tuple.getStringByField(NAME), tuple.getLongByField(DURATION), sparseDescriptors, denseDescriptors);
	return feature;
}
 
Example 5
Source File: FrameSerializer.java    From StormCV with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected Frame createObject(Tuple tuple) throws IOException {
	byte[] buffer = tuple.getBinaryByField(IMAGE);
	Frame frame;
	if(buffer == null){
		frame = new Frame(tuple, tuple.getStringByField(IMAGETYPE), null, tuple.getLongByField(TIMESTAMP), (Rectangle)tuple.getValueByField(BOUNDINGBOX));
	}else{
		frame = new Frame(tuple, tuple.getStringByField(IMAGETYPE), buffer, tuple.getLongByField(TIMESTAMP), (Rectangle)tuple.getValueByField(BOUNDINGBOX));
	}
	frame.getFeatures().addAll((List<Feature>)tuple.getValueByField(FEATURES));
	return frame;
}
 
Example 6
Source File: TupleTableConfig.java    From opensoc-streaming with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a HBase {@link Put} from a Storm {@link Tuple}
 * 
 * @param tuple
 *          The {@link Tuple}
 * @return {@link Put}
 */
public Put getPutFromTuple(final Tuple tuple) {
  byte[] rowKey = Bytes.toBytes(tuple.getStringByField(tupleRowKeyField));
  
  long ts = 0;
  if (!tupleTimestampField.equals("")) {
    ts = tuple.getLongByField(tupleTimestampField);
  }
  
  Put p = new Put(rowKey);
  
  p.setDurability(durability);
  
  if (columnFamilies.size() > 0) {
    for (String cf : columnFamilies.keySet()) {
      byte[] cfBytes = Bytes.toBytes(cf);
      for (String cq : columnFamilies.get(cf)) {
        byte[] cqBytes = Bytes.toBytes(cq);
        byte[] val = tuple.getBinaryByField(cq);
        
        if (ts > 0) {
          p.add(cfBytes, cqBytes, ts, val);
        } else {
          p.add(cfBytes, cqBytes, val);
        }
      }
    }
  }
  
  return p;
}
 
Example 7
Source File: CheckpointTupleForwarder.java    From jstorm with Apache License 2.0 5 votes vote down vote up
/**
 * Invokes handleCheckpoint once checkpoint tuple is received on
 * all input checkpoint streams to this component.
 */
private void processCheckpoint(Tuple input) {
    Action action = (Action) input.getValueByField(CheckpointSpout.CHECKPOINT_FIELD_ACTION);
    long txid = input.getLongByField(CheckpointSpout.CHECKPOINT_FIELD_TXID);
    if (shouldProcessTransaction(action, txid)) {
        LOG.debug("Processing action {}, txid {}", action, txid);
        try {
            if (txid >= lastTxid) {
                handleCheckpoint(input, action, txid);
                if (action == CheckPointState.Action.ROLLBACK) {
                    lastTxid = txid - 1;
                } else {
                    lastTxid = txid;
                }
            } else {
                LOG.debug("Ignoring old transaction. Action {}, txid {}", action, txid);
                collector.ack(input);
            }
        } catch (Throwable th) {
            LOG.error("Got error while processing checkpoint tuple", th);
            collector.fail(input);
            collector.reportError(th);
        }
    } else {
        LOG.debug("Waiting for action {}, txid {} from all input tasks. checkPointInputTaskCount {}, " +
                "transactionRequestCount {}", action, txid, checkPointInputTaskCount, transactionRequestCount);
        collector.ack(input);
    }
}
 
Example 8
Source File: WindowedBoltExecutor.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple input) {
    if (isTupleTs()) {
        long ts = input.getLongByField(tupleTsFieldName);
        if (waterMarkEventGenerator.track(input.getSourceGlobalStreamid(), ts)) {
            windowManager.add(input, ts);
        } else {
            LOG.info("Received a late tuple {} with ts {}. This will not processed.", input, ts);
        }
    } else {
        windowManager.add(input);
    }
}
 
Example 9
Source File: VideoChunkSerializer.java    From StormCV with Apache License 2.0 4 votes vote down vote up
@Override
protected VideoChunk createObject(Tuple tuple) throws IOException {
	return new VideoChunk(tuple, tuple.getLongByField(TIMESTAMP), 
			tuple.getBinaryByField(VIDEO), tuple.getStringByField(CONTAINER));
}
 
Example 10
Source File: ReportBolt.java    From storm-example with Apache License 2.0 4 votes vote down vote up
public void execute(Tuple tuple) {
    String word = tuple.getStringByField("word");
    Long count = tuple.getLongByField("count");
    this.counts.put(word, count);
}
 
Example 11
Source File: ReportBolt.java    From storm-example with Apache License 2.0 4 votes vote down vote up
public void execute(Tuple tuple) {
    String word = tuple.getStringByField("word");
    Long count = tuple.getLongByField("count");
    this.counts.put(word, count);
    this.collector.ack(tuple);
}
 
Example 12
Source File: StatefulWindowedBoltExecutor.java    From jstorm with Apache License 2.0 4 votes vote down vote up
private long getMsgId(Tuple input) {
    return input.getLongByField(msgIdFieldName);
}