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

The following examples show how to use org.apache.storm.tuple.Tuple#getValue() . 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: SlidingWindowTopology.java    From storm-net-adapter with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(TupleWindow inputWindow) {
    int sum = 0;
    List<Tuple> tuplesInWindow = inputWindow.get();
    LOG.debug("Events in current window: " + tuplesInWindow.size());
    if (tuplesInWindow.size() > 0) {
        /*
         * Since this is a tumbling window calculation,
         * we use all the tuples in the window to compute the avg.
         */
        for (Tuple tuple : tuplesInWindow) {
            sum += (int) tuple.getValue(0);
        }
        collector.emit(new Values(sum / tuplesInWindow.size()));
    }
}
 
Example 2
Source File: EventProcessingBolt.java    From monasca-thresh with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple tuple) {
  try {
    Object event = tuple.getValue(0);
    logger.trace("Received event for processing {}", event);
    if (event instanceof AlarmDefinitionCreatedEvent) {
      handle((AlarmDefinitionCreatedEvent) event);
    } else if (event instanceof AlarmDefinitionUpdatedEvent) {
        handle((AlarmDefinitionUpdatedEvent) event);
    } else if (event instanceof AlarmDefinitionDeletedEvent) {
      handle((AlarmDefinitionDeletedEvent) event);
    } else if (event instanceof AlarmDeletedEvent) {
      handle((AlarmDeletedEvent) event);
    } else if (event instanceof AlarmUpdatedEvent) {
      handle((AlarmUpdatedEvent) event);
    }
  } catch (Exception e) {
    logger.error("Error processing tuple {}", tuple, e);
  } finally {
    collector.ack(tuple);
  }
}
 
Example 3
Source File: SlidingWindowTopology.java    From incubator-heron with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(TupleWindow inputWindow) {
  int sum = 0;
  List<Tuple> tuplesInWindow = inputWindow.get();
  LOG.fine("Events in current window: " + tuplesInWindow.size());
  if (tuplesInWindow.size() > 0) {
            /*
            * Since this is a tumbling window calculation,
            * we use all the tuples in the window to compute the avg.
            */
    for (Tuple tuple : tuplesInWindow) {
      sum += (int) tuple.getValue(0);
    }
    collector.emit(new Values(sum / tuplesInWindow.size()));
  }
}
 
Example 4
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 5
Source File: StormTupleBytesConverter.java    From elasticsearch-hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public void convert(Object from, BytesArray to) {
    Assert.isTrue(from == null || from instanceof Tuple,
            String.format("Unexpected object type, expecting [%s], given [%s]", Tuple.class, from.getClass()));

    // handle common cases
    Tuple tuple = (Tuple) from;

    if (tuple == null || tuple.size() == 0) {
        to.bytes("{}");
        return;
    }
    Assert.isTrue(tuple.size() == 1, "When using JSON input, only one field is expected");

    super.convert(tuple.getValue(0), to);
}
 
Example 6
Source File: QueryBolt.java    From bullet-storm with Apache License 2.0 5 votes vote down vote up
/**
 * Handles a metadata message for a query.
 *
 * @param tuple The metadata tuple.
 * @return The created {@link Metadata}.
 */
protected Metadata onMeta(Tuple tuple) {
    String id = tuple.getString(TopologyConstants.ID_POSITION);
    Metadata metadata = (Metadata) tuple.getValue(TopologyConstants.METADATA_POSITION);
    if (metadata == null) {
        return null;
    }
    Metadata.Signal signal = metadata.getSignal();
    if (signal == Metadata.Signal.KILL || signal == Metadata.Signal.COMPLETE) {
        removeQuery(id);
        log.info("Received {} signal and killed query: {}", signal, id);
    }
    return metadata;
}
 
Example 7
Source File: WriterBolt.java    From metron with Apache License 2.0 5 votes vote down vote up
private JSONObject getMessage(Tuple tuple) {
  Object ret = tuple.getValueByField("message");
  if(ret != null) {
    ret = tuple.getValue(0);
  }
  if(ret != null) {
    return (JSONObject)((JSONObject)ret).clone();
  }
  else {
    return null;
  }
}
 
Example 8
Source File: ResultBolt.java    From bullet-storm with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple) {
    String id = tuple.getString(TopologyConstants.ID_POSITION);
    String result = tuple.getString(TopologyConstants.RESULT_POSITION);
    Metadata metadata = (Metadata) tuple.getValue(TopologyConstants.RESULT_METADATA_POSITION);
    publish(new PubSubMessage(id, result, metadata), tuple);
}
 
Example 9
Source File: FilterBolt.java    From bullet-storm with Apache License 2.0 5 votes vote down vote up
private void updateLatency(Tuple tuple) {
    if (metricsEnabled && tuple.size() > 1) {
        // Could use named fields instead
        Long timestamp = (Long) tuple.getValue(TopologyConstants.RECORD_TIMESTAMP_POSITION);
        averageLatency.update(System.currentTimeMillis() - timestamp);
    }
}
 
Example 10
Source File: LoopBolt.java    From bullet-storm with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple) {
    String id = tuple.getString(TopologyConstants.ID_POSITION);
    Metadata metadata = (Metadata) tuple.getValue(TopologyConstants.METADATA_POSITION);
    log.info("Looping back metadata with signal {} for {}", metadata.getSignal(), id);
    publish(new PubSubMessage(id, (byte[]) null, metadata), tuple);
}
 
Example 11
Source File: RemoteDRPCTopology.java    From 163-bigdate-note with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(Tuple input) {
    Object requestId = input.getValue(0);
    String name = input.getString(1);

    //业务逻辑
    String result = "add user:" + name;
    this.outputCollector.emit(new Values(requestId, result));
}
 
Example 12
Source File: IPFraudKafkaBolt.java    From Building-Data-Streaming-Applications-with-Apache-Kafka with MIT License 5 votes vote down vote up
public void execute(Tuple input) {

        dataToTopic = (String) input.getValue(0);
        ProducerRecord data = new ProducerRecord<String, String>(topic, this.dataToTopic);
        Future<RecordMetadata> recordMetadata = producer.send(data);
        _collector.ack(input);

    }
 
Example 13
Source File: IPFraudHiveBolt.java    From Building-Data-Streaming-Applications-with-Apache-Kafka with MIT License 5 votes vote down vote up
public void execute(Tuple input) {
    String ipRecord = (String) input.getValue(0);
    String[] columns = ipRecord.split(",");
    Values value = new Values(columns[0], columns[3], columns[4], columns[5], columns[6]);
    _collector.emit(value);
    _collector.ack(input);


}
 
Example 14
Source File: AlarmBolt.java    From nightwatch with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void execute(Tuple input) {
    if(alarmEPLManager.isUpdate()) {
        try {
            alarmEPLManager.getCountDownLatch().await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    String streamName = input.getValue(0).toString();
    Map<String, Object> record = (Map<String, Object>) input.getValue(1);
    alarmEPLManager.getEPRuntime().sendEvent(record, streamName);
    collector.ack(input);
}
 
Example 15
Source File: KeyedScottyWindowOperator.java    From scotty-window-processor with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector basicOutputCollector) {
    //The input is a tuple
    Key currentKey = (Key) tuple.getValue(0);
    if (!slicingWindowOperatorMap.containsKey(currentKey)) {
        slicingWindowOperatorMap.put(currentKey, initWindowOperator());
    }
    SlicingWindowOperator<Value> slicingWindowOperator = slicingWindowOperatorMap.get(currentKey);
    //We only process the Value of a tuple
    slicingWindowOperator.processElement((Value) tuple.getValue(1), tuple.getLong(2));
    processWatermark(currentKey, tuple.getLong(2), basicOutputCollector);
}
 
Example 16
Source File: LocalDRPCTopology.java    From 163-bigdate-note with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(Tuple input) {
    Object requestId = input.getValue(0);
    String name = input.getString(1);

    //业务逻辑
    String result = "add user:" + name;
    this.outputCollector.emit(new Values(requestId, result));
}
 
Example 17
Source File: TotalRankingsBolt.java    From storm_spring_boot_demo with MIT License 4 votes vote down vote up
@Override
void updateRankingsWithTuple(Tuple tuple) {
  Rankings rankingsToBeMerged = (Rankings) tuple.getValue(0);
  super.getRankings().updateWith(rankingsToBeMerged);
  super.getRankings().pruneZeroCounts();
}
 
Example 18
Source File: DSLBolt.java    From bullet-storm with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(Tuple tuple) {
    List<Object> objects = (List<Object>) tuple.getValue(TopologyConstants.RECORD_POSITION);
    objects.forEach(this::convertAndEmit);
    collector.ack(tuple);
}
 
Example 19
Source File: FilterBolt.java    From bullet-storm with Apache License 2.0 4 votes vote down vote up
private void onRecord(Tuple tuple) {
    BulletRecord record = (BulletRecord) tuple.getValue(TopologyConstants.RECORD_POSITION);
    handleCategorizedQueries(manager.categorize(record));
}
 
Example 20
Source File: RollingCountBolt.java    From storm-net-adapter with Apache License 2.0 4 votes vote down vote up
private void countObjAndAck(Tuple tuple) {
    Object obj = tuple.getValue(0);
    counter.incrementCount(obj);
    collector.ack(tuple);
}