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

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

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

Tuple.getSourceComponent介绍

[英]Gets the id of the component that created this tuple.
[中]获取创建此元组的组件的id。

代码示例

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

private String getStreamSelector(Tuple ti) {
  switch (selectorType) {
    case STREAM:
      return ti.getSourceStreamId();
    case SOURCE:
      return ti.getSourceComponent();
    default:
      throw new RuntimeException(selectorType + " stream selector type not yet supported");
  }
}

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

public static boolean isTick(Tuple tuple) {
  return tuple != null
      && Constants.SYSTEM_COMPONENT_ID.equals(tuple.getSourceComponent())
      && Constants.SYSTEM_TICK_STREAM_ID.equals(tuple.getSourceStreamId());
}

代码示例来源:origin: elastic/elasticsearch-hadoop

public static boolean isTickTuple(Tuple tuple) {
    return tuple.getSourceComponent().equals(Constants.SYSTEM_COMPONENT_ID)
        && tuple.getSourceStreamId().equals(Constants.SYSTEM_TICK_STREAM_ID);
  }
}

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

public void execute(Tuple input) {
  String component = input.getSourceComponent();
  Map<String, List<FixedTuple>> captured = emitted_tuples.get(_name);
  if (!captured.containsKey(component)) {
    captured.put(component, new ArrayList<FixedTuple>());
  }
  captured.get(component).add(new FixedTuple(input.getSourceStreamId(), input.getValues()));
  _collector.ack(input);
}

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

public void execute(Tuple tuple) {
  Object requestId = tuple.getValue(0);
  if (tuple.getSourceComponent().equals(returnComponent)) {
    returns.put(requestId, tuple);
  } else {
    results.put(requestId, tuple);
  }
  if (returns.containsKey(requestId) && results.containsKey(requestId)) {
    Tuple result = results.remove(requestId);
    Tuple returner = returns.remove(requestId);
    LOG.debug(result.getValue(1).toString());
    List<Tuple> anchors = new ArrayList<>();
    anchors.add(result);
    anchors.add(returner);
    _collector.emit(anchors, new Values("" + result.getValue(1), returner.getValue(1)));
    _collector.ack(result);
    _collector.ack(returner);
  }
}

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

@Override
public void execute(Tuple input) {
  LOG.debug("** EventLoggerBolt got tuple from sourceComponent {}, with values {}", input.getSourceComponent(), input.getValues());
  Object msgId = input.getValueByField(FIELD_MESSAGE_ID);
  EventInfo eventInfo = new EventInfo(input.getLongByField(FIELD_TS), input.getSourceComponent(),
                    input.getSourceTask(), msgId, (List<Object>) input.getValueByField(FIELD_VALUES));
  for (IEventLogger eventLogger : eventLoggers) {
    eventLogger.log(eventInfo);
  }
}

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

public static Tuple mockTuple(String componentId, String streamId) {
    Tuple tuple = Mockito.mock(Tuple.class);
    Mockito.when(tuple.getSourceComponent()).thenReturn(componentId);
    Mockito.when(tuple.getSourceStreamId()).thenReturn(streamId);
    return tuple;
  }
}

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

@Override
public void execute(Tuple tuple) {
  List<Object> id = tuple.select(_idFields);
  GlobalStreamId streamId = new GlobalStreamId(tuple.getSourceComponent(), tuple.getSourceStreamId());
  if (!_pending.containsKey(id)) {
    _pending.put(id, new HashMap<GlobalStreamId, Tuple>());
  }
  Map<GlobalStreamId, Tuple> parts = _pending.get(id);
  if (parts.containsKey(streamId)) {
    throw new RuntimeException("Received same side of single join twice");
  }
  parts.put(streamId, tuple);
  if (parts.size() == _numSources) {
    _pending.remove(id);
    List<Object> joinResult = new ArrayList<Object>();
    for (String outField : _outFields) {
      GlobalStreamId loc = _fieldLocations.get(outField);
      joinResult.add(parts.get(loc).getValueByField(outField));
    }
    _collector.emit(new ArrayList<Tuple>(parts.values()), joinResult);
    for (Tuple part : parts.values()) {
      _collector.ack(part);
    }
  }
}

代码示例来源: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(100);
    Mockito.when(tuple.getSourceComponent()).thenReturn("bolt0");
    Mockito.when(tuple.getSourceStreamId()).thenReturn("inputstream");
  }
}

代码示例来源: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(Pair.of("k", "v"));
      Mockito.when(tuple.getSourceComponent()).thenReturn("bolt0");
      Mockito.when(tuple.getSourceStreamId()).thenReturn("inputstream");
    }
  }
}

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

public TupleImpl(Tuple t) {
  this.values = t.getValues();
  this.taskId = t.getSourceTask();
  this.streamId = t.getSourceStreamId();
  this.id = t.getMessageId();
  this.context = t.getContext();
  this.srcComponent = t.getSourceComponent();
  try {
    TupleImpl ti = (TupleImpl) t;
    this._processSampleStartTime = ti._processSampleStartTime;
    this._executeSampleStartTime = ti._executeSampleStartTime;
    this._outAckVal = ti._outAckVal;
  } catch (ClassCastException e) {
    // ignore ... if t is not a TupleImpl type .. faster than checking and then casting
  }
}

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

public byte[] serialize(Tuple tuple) {
  try {
    _kryoOut.clear();
    _kryoOut.writeInt(tuple.getSourceTask(), true);
    _kryoOut.writeInt(_ids.getStreamId(tuple.getSourceComponent(), tuple.getSourceStreamId()), true);
    tuple.getMessageId().serialize(_kryoOut);
    _kryo.serializeInto(tuple.getValues(), _kryoOut);
    return _kryoOut.toBytes();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

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

private BoltMsg createBoltMessage(Tuple input, String genId) {
  BoltMsg boltMsg = new BoltMsg();
  boltMsg.setId(genId);
  boltMsg.setComp(input.getSourceComponent());
  boltMsg.setStream(input.getSourceStreamId());
  boltMsg.setTask(input.getSourceTask());
  boltMsg.setTuple(input.getValues());
  return boltMsg;
}

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

@Test
public void testTestTuple() throws Exception {
  Tuple tuple = Testing.testTuple(new Values("james", "bond"));
  assertThat(tuple.getValues(), is(new Values("james", "bond")));
  assertThat(tuple.getSourceStreamId(), is(Utils.DEFAULT_STREAM_ID));
  assertThat(tuple.getFields().toList(), is(Arrays.asList("field1", "field2")));
  assertThat(tuple.getSourceComponent(), is("component"));
}

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

@Override
public void ack(Tuple input) {
  if (!ackingEnabled) {
    return;
  }
  long ackValue = ((TupleImpl) input).getAckVal();
  Map<Long, Long> anchorsToIds = input.getMessageId().getAnchorsToIds();
  for (Map.Entry<Long, Long> entry : anchorsToIds.entrySet()) {
    task.sendUnanchored(Acker.ACKER_ACK_STREAM_ID,
              new Values(entry.getKey(), Utils.bitXor(entry.getValue(), ackValue)),
              executor.getExecutorTransfer(), executor.getPendingEmits());
  }
  long delta = tupleTimeDelta((TupleImpl) input);
  if (isDebug) {
    LOG.info("BOLT ack TASK: {} TIME: {} TUPLE: {}", taskId, delta, input);
  }
  if (!task.getUserContext().getHooks().isEmpty()) {
    BoltAckInfo boltAckInfo = new BoltAckInfo(input, taskId, delta);
    boltAckInfo.applyOn(task.getUserContext());
  }
  if (delta >= 0) {
    executor.getStats().boltAckedTuple(input.getSourceComponent(), input.getSourceStreamId(), delta,
                      task.getTaskMetrics().getAcked(input.getSourceStreamId()));
  }
}

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

Pair<Object, String> getValueAndStream(Tuple input) {
  Object value;
  String stream;
  // if tuple arrives from a spout, it can be passed as is
  // otherwise the value is in the first field of the tuple
  if (input.getSourceComponent().startsWith("spout")) {
    value = input;
    stream = input.getSourceGlobalStreamId().get_componentId() + input.getSourceGlobalStreamId().get_streamId();
  } else if (isPair(input)) {
    value = Pair.of(input.getValue(0), input.getValue(1));
    stream = input.getSourceStreamId();
  } else {
    value = input.getValue(0);
    stream = input.getSourceStreamId();
  }
  return Pair.of(value, stream);
}

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

@Test
public void testTestTupleWithMkTupleParam() throws Exception {
  MkTupleParam mkTupleParam = new MkTupleParam();
  mkTupleParam.setStream("test-stream");
  mkTupleParam.setComponent("test-component");
  mkTupleParam.setFields("fname", "lname");
  Tuple tuple = Testing.testTuple(new Values("james", "bond"), mkTupleParam);
  assertThat(tuple.getValues(), is(new Values("james", "bond")));
  assertThat(tuple.getSourceStreamId(), is("test-stream"));
  assertThat(tuple.getFields().toList(), is(Arrays.asList("fname", "lname")));
  assertThat(tuple.getSourceComponent(), is("test-component"));
}

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

@Override
public void fail(Tuple input) {
  if (!ackingEnabled) {
    return;
  }
  Set<Long> roots = input.getMessageId().getAnchors();
  for (Long root : roots) {
    task.sendUnanchored(Acker.ACKER_FAIL_STREAM_ID,
              new Values(root), executor.getExecutorTransfer(), executor.getPendingEmits());
  }
  long delta = tupleTimeDelta((TupleImpl) input);
  if (isDebug) {
    LOG.info("BOLT fail TASK: {} TIME: {} TUPLE: {}", taskId, delta, input);
  }
  BoltFailInfo boltFailInfo = new BoltFailInfo(input, taskId, delta);
  boltFailInfo.applyOn(task.getUserContext());
  if (delta >= 0) {
    executor.getStats().boltFailedTuple(input.getSourceComponent(), input.getSourceStreamId(), delta,
                      task.getTaskMetrics().getFailed(input.getSourceStreamId()));
  }
}

相关文章