org.apache.storm.tuple.Tuple.getValue()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(115)

本文整理了Java中org.apache.storm.tuple.Tuple.getValue()方法的一些代码示例,展示了Tuple.getValue()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tuple.getValue()方法的具体详情如下:
包路径:org.apache.storm.tuple.Tuple
类名称:Tuple
方法名:getValue

Tuple.getValue介绍

[英]Gets the field at position i in the tuple. Returns object since tuples are dynamically typed.
[中]获取元组中位置i处的字段。返回对象,因为元组是动态类型的。

代码示例

代码示例来源:origin: apache/storm

@SuppressWarnings("unchecked")
  @Override
  public T apply(Tuple input) {
    return (T) input.getValue(index);
  }
}

代码示例来源:origin: apache/storm

public static <T1, T2, T3, T4>
TupleValueMapper<Tuple4<T1, T2, T3, T4>> of(int index1,
                      int index2,
                      int index3,
                      int index4) {
  return input -> new Tuple4<>(
    (T1) input.getValue(index1),
    (T2) input.getValue(index2),
    (T3) input.getValue(index3),
    (T4) input.getValue(index4));
}

代码示例来源:origin: apache/storm

public static <T1, T2, T3>
TupleValueMapper<Tuple3<T1, T2, T3>> of(int index1,
                    int index2,
                    int index3) {
  return input -> new Tuple3<>(
    (T1) input.getValue(index1),
    (T2) input.getValue(index2),
    (T3) input.getValue(index3));
}

代码示例来源:origin: apache/storm

@SuppressWarnings("unchecked")
  @Override
  public Pair<K, V> apply(Tuple input) {
    return Pair.of((K) input.getValue(keyIndex), (V) input.getValue(valueIndex));
  }
}

代码示例来源:origin: apache/storm

@Override
  public ByteBuffer getMessageFromTuple(Tuple tuple) {
    return serializer.write((Values) tuple.getValue(1), null);
  }
}

代码示例来源:origin: apache/storm

/**
 * AvroGenericRecordBolt must override this method because messages with different schemas cannot be written to the
 * same file.  By treating the complete schema as the "key" AbstractHdfsBolt will associate a different writer for
 * every distinct schema.
 */
@Override
protected String getWriterKey(Tuple tuple) {
  Schema recordSchema = ((GenericRecord) tuple.getValue(0)).getSchema();
  return recordSchema.toString();
}

代码示例来源:origin: apache/storm

@Override
  protected AbstractHDFSWriter makeNewWriter(Path path, Tuple tuple) throws IOException {
    Schema recordSchema = ((GenericRecord) tuple.getValue(0)).getSchema();
    return new AvroGenericRecordHDFSWriter(this.rotationPolicy, path, this.fs.create(path), recordSchema);
  }
}

代码示例来源:origin: apache/storm

@Override
public void execute(Tuple input) {
  IMetricsConsumer.TaskInfo taskInfo = (IMetricsConsumer.TaskInfo) input.getValue(0);
  Collection<IMetricsConsumer.DataPoint> dataPoints = (Collection) input.getValue(1);
  Collection<IMetricsConsumer.DataPoint> expandedDataPoints = _expander.expandDataPoints(dataPoints);
  List<IMetricsConsumer.DataPoint> filteredDataPoints = getFilteredDataPoints(expandedDataPoints);
  MetricsTask metricsTask = new MetricsTask(taskInfo, filteredDataPoints);
  while (!_taskQueue.offer(metricsTask)) {
    _taskQueue.poll();
  }
  _collector.ack(input);
}

代码示例来源:origin: apache/storm

@Override
public void execute(Tuple tuple) {
  log.info("Received tuple : {}", tuple.getValue(0));
  count++;
  if (count == 3) {
    collector.fail(tuple);
  } else {
    collector.ack(tuple);
  }
}

代码示例来源:origin: apache/storm

public void fail(Tuple tuple) {
  Object id = tuple.getValue(0);
  synchronized (_tracked) {
    TrackingInfo track = _tracked.get(id);
    if (track != null) {
      track.failed = true;
    }
  }
  checkFinishId(tuple, TupleType.REGULAR);
  _delegate.fail(tuple);
}

代码示例来源:origin: apache/storm

private void countObjAndAck(Tuple tuple) {
  Object obj = tuple.getValue(0);
  counter.incrementCount(obj);
  collector.ack(tuple);
}

代码示例来源:origin: apache/storm

@Override
  public Values apply(Tuple input) {
    Values values = new Values();
    for (int i : indices) {
      values.add(input.getValue(i));
    }
    return values;
  }
}

代码示例来源:origin: apache/storm

@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
  Object id = tuple.getValue(0);
  String tweeter = tuple.getString(1);
  List<String> followers = FOLLOWERS_DB.get(tweeter);
  if (followers != null) {
    for (String follower : followers) {
      collector.emit(new Values(id, follower));
    }
  }
}

代码示例来源:origin: apache/storm

@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
  Object id = tuple.getValue(0);
  String url = tuple.getString(1);
  List<String> tweeters = TWEETERS_DB.get(url);
  if (tweeters != null) {
    for (String tweeter : tweeters) {
      collector.emit(new Values(id, tweeter));
    }
  }
}

代码示例来源:origin: apache/storm

@Override
protected void doWrite(Tuple tuple) throws IOException {
  GenericRecord avroRecord = (GenericRecord) tuple.getValue(0);
  avroWriter.append(avroRecord);
  offset = this.out.getPos();
  this.needsRotation = this.rotationPolicy.mark(tuple, offset);
}

代码示例来源:origin: apache/storm

@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
  String arg = tuple.getString(0);
  Object retInfo = tuple.getValue(1);
  collector.emit(new Values(arg + "!!!", retInfo));
}

代码示例来源:origin: apache/storm

@Override
public void execute(Tuple input) {
  Object id = input.getValue(0);
  IBatchBolt bolt = getBatchBolt(id);
  try {
    bolt.execute(input);
    _collector.ack(input);
  } catch (FailedException e) {
    LOG.error("Failed to process tuple in batch", e);
    _collector.fail(input);
  }
}

代码示例来源:origin: apache/storm

private void setUpPunctuation(Tuple punctuation) {
    Mockito.when(punctuation.size()).thenReturn(1);
    Mockito.when(punctuation.getValue(0)).thenReturn(WindowNode.PUNCTUATION);
    Mockito.when(punctuation.getSourceComponent()).thenReturn("bolt0");
    Mockito.when(punctuation.getSourceStreamId()).thenReturn("inputstream");
  }
}

代码示例来源:origin: apache/storm

private void setUpMockTuples(Tuple... tuples) {
  for (Tuple tuple : tuples) {
    Mockito.when(tuple.size()).thenReturn(1);
    Mockito.when(tuple.getValue(0)).thenReturn(100);
    Mockito.when(tuple.getSourceComponent()).thenReturn("bolt0");
    Mockito.when(tuple.getSourceStreamId()).thenReturn("inputstream");
  }
}

代码示例来源:origin: apache/storm

private void setUpMockTuples(Tuple... tuples) {
    for (Tuple tuple : tuples) {
      Mockito.when(tuple.size()).thenReturn(1);
      Mockito.when(tuple.getValue(0)).thenReturn(Pair.of("k", "v"));
      Mockito.when(tuple.getSourceComponent()).thenReturn("bolt0");
      Mockito.when(tuple.getSourceStreamId()).thenReturn("inputstream");
    }
  }
}

相关文章