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

The following examples show how to use org.apache.storm.tuple.Tuple#getIntegerByField() . 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: FileWritingBolt.java    From tutorials with MIT License 6 votes vote down vote up
@Override
public void execute(Tuple tuple) {
    int sumOfOperations = tuple.getIntegerByField("sumOfOperations");
    long beginningTimestamp = tuple.getLongByField("beginningTimestamp");
    long endTimestamp = tuple.getLongByField("endTimestamp");

    if(sumOfOperations > 200) {
        AggregatedWindow aggregatedWindow = new AggregatedWindow(sumOfOperations, beginningTimestamp, endTimestamp);
        try {
            writer.write(objectMapper.writeValueAsString(aggregatedWindow));
            writer.write("\n");
            writer.flush();
        } catch (IOException e) {
            logger.error("Failed to write data to file.", e);
        }
    }
}
 
Example 2
Source File: ClusterSumStormWorkersTopology.java    From 163-bigdate-note with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 也是一个死循环,用于获取 Spout 发送过来的数据
 * @param input
 */
@Override
public void execute(Tuple input) {
    // Bolt 中获取值可以根据 index 获取,也可以根据上一个环节中定义的 field 的名称获取(建议使用这种方法获取)
    Integer value = input.getIntegerByField("num");
    sum += value;
    System.out.println("Bolt: sum = " + sum);
}
 
Example 3
Source File: ClusterSumStormAckerTopology.java    From 163-bigdate-note with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 也是一个死循环,用于获取 Spout 发送过来的数据
 * @param input
 */
@Override
public void execute(Tuple input) {
    // Bolt 中获取值可以根据 index 获取,也可以根据上一个环节中定义的 field 的名称获取(建议使用这种方法获取)
    Integer value = input.getIntegerByField("num");
    sum += value;
    System.out.println("Bolt: sum = " + sum);
}
 
Example 4
Source File: ClusterSumStormExecutorsTopology.java    From 163-bigdate-note with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 也是一个死循环,用于获取 Spout 发送过来的数据
 * @param input
 */
@Override
public void execute(Tuple input) {
    // Bolt 中获取值可以根据 index 获取,也可以根据上一个环节中定义的 field 的名称获取(建议使用这种方法获取)
    Integer value = input.getIntegerByField("num");
    sum += value;
    System.out.println("Bolt: sum = " + sum);
}
 
Example 5
Source File: ClusterSumStormTopology.java    From 163-bigdate-note with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 也是一个死循环,用于获取 Spout 发送过来的数据
 * @param input
 */
@Override
public void execute(Tuple input) {
    // Bolt 中获取值可以根据 index 获取,也可以根据上一个环节中定义的 field 的名称获取(建议使用这种方法获取)
    Integer value = input.getIntegerByField("num");
    sum += value;
    System.out.println("Bolt: sum = " + sum);
}
 
Example 6
Source File: ClusterSumFieldGroupingStormTopology.java    From 163-bigdate-note with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 也是一个死循环,用于获取 Spout 发送过来的数据
 * @param input
 */
@Override
public void execute(Tuple input) {
    // Bolt 中获取值可以根据 index 获取,也可以根据上一个环节中定义的 field 的名称获取(建议使用这种方法获取)
    Integer value = input.getIntegerByField("num");
    sum += value;
    System.out.println("Bolt: sum = " + sum);
    System.out.println("Thread id: " + Thread.currentThread().getId() + ", receive data is: " + value);
}
 
Example 7
Source File: LocalSumStormTopology.java    From 163-bigdate-note with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 也是一个死循环,用于获取 Spout 发送过来的数据
 * @param input
 */
@Override
public void execute(Tuple input) {
    // Bolt 中获取值可以根据 index 获取,也可以根据上一个环节中定义的 field 的名称获取(建议使用这种方法获取)
    Integer value = input.getIntegerByField("num");
    sum += value;
    System.out.println("Bolt: sum = " + sum);
}
 
Example 8
Source File: ClusterSumStormTasksTopology.java    From 163-bigdate-note with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 也是一个死循环,用于获取 Spout 发送过来的数据
 * @param input
 */
@Override
public void execute(Tuple input) {
    // Bolt 中获取值可以根据 index 获取,也可以根据上一个环节中定义的 field 的名称获取(建议使用这种方法获取)
    Integer value = input.getIntegerByField("num");
    sum += value;
    System.out.println("Bolt: sum = " + sum);
}
 
Example 9
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 10
Source File: StatefulWindowingTopology.java    From storm-net-adapter with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(TupleWindow inputWindow) {
    for (Tuple tuple : inputWindow.get()) {
        sum += tuple.getIntegerByField("value");
    }
    state.put("sum", sum);
    collector.emit(new Values(sum));
}
 
Example 11
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 12
Source File: EncRowCalcBolt.java    From incubator-retired-pirk with Apache License 2.0 4 votes vote down vote up
/***
 * Extracts (hash, data partitions) from tuple. Encrypts the data partitions. Returns all of the pairs of (col index, col value). Also advances the
 * colIndexByRow and hitsByRow appropriately.
 *
 * @param tuple
 *          {@code Tuple}
 * @return {@code List<Tuple2>}
 */
private List<Tuple2<Long,BigInteger>> processTupleFromPartitionDataBolt(Tuple tuple)
{
  matrixElements.clear();
  int rowIndex = tuple.getIntegerByField(StormConstants.HASH_FIELD);

  if (!colIndexByRow.containsKey(rowIndex))
  {
    colIndexByRow.put(rowIndex, 0);
    hitsByRow.put(rowIndex, 0);
  }

  if (splitPartitions)
  {
    dataArray.add((BigInteger) tuple.getValueByField(StormConstants.PARTIONED_DATA_FIELD));
  }
  else
  {
    dataArray = (ArrayList<BigInteger>) tuple.getValueByField(StormConstants.PARTIONED_DATA_FIELD);
  }
  logger.debug("Retrieving {} elements in EncRowCalcBolt.", dataArray.size());

  try
  {
    int colIndex = colIndexByRow.get(rowIndex);
    int numRecords = hitsByRow.get(rowIndex);

    if (limitHitsPerSelector && numRecords < maxHitsPerSelector)
    {
      logger.debug("computing matrix elements.");
      matrixElements = ComputeEncryptedRow.computeEncRow(dataArray, query, rowIndex, colIndex);
      colIndexByRow.put(rowIndex, colIndex + matrixElements.size());
      hitsByRow.put(rowIndex, numRecords + 1);
    }
    else if (limitHitsPerSelector)
    {
      logger.info("maxHits: rowIndex = " + rowIndex + " elementCounter = " + numRecords);
    }
  } catch (IOException e)
  {
    logger.warn("Caught IOException while encrypting row. ", e);
  }

  dataArray.clear();
  return matrixElements;
}