backtype.storm.tuple.Tuple.contains()方法的使用及代码示例

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

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

Tuple.contains介绍

[英]Returns true if this tuple contains the specified name of the field.
[中]如果此元组包含字段的指定名称,则返回true。

代码示例

代码示例来源:origin: calrissian/flowmix

@Override
public void execute(Tuple tuple) {
 if(tuple.contains(EVENT)) {
  synchronized (eventsReceived) {
   eventsReceived.add((Event) tuple.getValueByField(EVENT));
  }
 }
}

代码示例来源:origin: Symantec/hendrix

@Override
public void execute(Tuple tuple) {
  JsonObject obj = new JsonObject();
  obj.addProperty(Constants.FIELD_TIMESTAMP, tuple.getLongByField(Constants.FIELD_TIMESTAMP));
  obj.addProperty(Constants.FIELD_AGGREGATION_WINDOW,
      tuple.getIntegerByField(Constants.FIELD_AGGREGATION_WINDOW));
  obj.addProperty(Constants.FIELD_RULE_ACTION_ID, tuple.getStringByField(Constants.FIELD_RULE_ACTION_ID));
  obj.addProperty(Constants.FIELD_AGGREGATION_KEY, tuple.getStringByField(Constants.FIELD_AGGREGATION_KEY));
  if (tuple.contains(Constants.FIELD_STATE_TRACK)) {
    obj.addProperty(Constants.FIELD_STATE_TRACK, tuple.getBooleanByField(Constants.FIELD_STATE_TRACK));
  } else if (tuple.contains(Constants.FIELD_AGGREGATION_VALUE)) {
    obj.addProperty(Constants.FIELD_AGGREGATION_VALUE,
        tuple.getValueByField(Constants.FIELD_AGGREGATION_VALUE).toString());
  } else {
    // invalid event
    collector.fail(tuple);
    return;
  }
  collector.emit(tuple, new Values(tuple.getStringByField(Constants.FIELD_RULE_ACTION_ID) + "_"
      + tuple.getStringByField(Constants.FIELD_AGGREGATION_KEY), gson.toJson(obj)));
  collector.ack(tuple);
}

代码示例来源:origin: wurstmeister/storm-kafka-0.8-plus

@Override
public void execute(Tuple input) {
  K key = null;
  if (input.contains(BOLT_KEY)) {
    key = (K) input.getValueByField(BOLT_KEY);
  }
  V message = (V) input.getValueByField(BOLT_MESSAGE);
  try {
    producer.send(new KeyedMessage<K, V>(topic, key, message));
  } catch (Exception ex) {
    LOG.error("Could not send message with key '" + key + "' and value '" + message + "'", ex);
  } finally {
    collector.ack(input);
  }
}

代码示例来源:origin: Symantec/hendrix

@Test
public void testBasicSerialization() {
  AggregationSerializerBolt bolt = new AggregationSerializerBolt();
  Map<String, String> conf = new HashMap<>();
  bolt.prepare(conf, null, collector);
  when(tuple.getLongByField(Constants.FIELD_TIMESTAMP)).thenReturn(143322L);
  when(tuple.getStringByField(Constants.FIELD_RULE_ACTION_ID)).thenReturn("34_22");
  when(tuple.getStringByField(Constants.FIELD_AGGREGATION_KEY)).thenReturn("host1");
  when(tuple.getIntegerByField(Constants.FIELD_AGGREGATION_WINDOW)).thenReturn(100);
  when(tuple.getBooleanByField(Constants.FIELD_STATE_TRACK)).thenReturn(true);
  when(tuple.contains(Constants.FIELD_STATE_TRACK)).thenReturn(true);
  bolt.execute(tuple);
  verify(collector, times(1)).ack(tuple);
}

代码示例来源:origin: calrissian/flowmix

public FlowInfo(Tuple tuple) {
 flowId = tuple.getStringByField(FLOW_ID);
 event = (Event) tuple.getValueByField(EVENT);
 idx = tuple.getIntegerByField(FLOW_OP_IDX);
 idx++;
 streamName = tuple.getStringByField(STREAM_NAME);
 previousStream = tuple.getStringByField(LAST_STREAM);
 if(tuple.contains(PARTITION))
  partition = tuple.getStringByField(PARTITION);
}

代码示例来源:origin: Symantec/hendrix

@Override
public final void execute(Tuple tuple) {
  if (tuple.contains(Constants.FIELD_ALERT)) {
    Alert alert = (Alert) tuple.getValueByField(Constants.FIELD_ALERT);
    AlertTemplate template = templateMap.get(alert.getId());

代码示例来源:origin: Symantec/hendrix

@Test
public void testJSONSerialization() {
  AggregationSerializerBolt bolt = new AggregationSerializerBolt();
  Map<String, String> conf = new HashMap<>();
  final AtomicReference<Values> outputTuple = new AtomicReference<Values>(null);
  OutputCollector mockCollector = MockTupleHelpers.mockCollector(new Answer<Object>() {
    @Override
    public Object answer(InvocationOnMock invocation) throws Throwable {
      Object newEvent = invocation.getArguments()[1];
      outputTuple.set((Values) newEvent);
      return new ArrayList<>();
    }
  });
  bolt.prepare(conf, null, mockCollector);
  when(tuple.getLongByField(Constants.FIELD_TIMESTAMP)).thenReturn(143322L);
  when(tuple.getStringByField(Constants.FIELD_RULE_ACTION_ID)).thenReturn("34_22");
  when(tuple.getStringByField(Constants.FIELD_AGGREGATION_KEY)).thenReturn("host1");
  when(tuple.getIntegerByField(Constants.FIELD_AGGREGATION_WINDOW)).thenReturn(100);
  when(tuple.getBooleanByField(Constants.FIELD_STATE_TRACK)).thenReturn(true);
  when(tuple.contains(Constants.FIELD_STATE_TRACK)).thenReturn(true);
  bolt.execute(tuple);
  verify(mockCollector, times(1)).ack(tuple);
  assertEquals("34_22_host1", outputTuple.get().get(0));
  JsonObject obj = new Gson().fromJson(outputTuple.get().get(1).toString(), JsonObject.class);
  assertEquals(143322L, obj.get(Constants.FIELD_TIMESTAMP).getAsLong());
  assertEquals("34_22", obj.get(Constants.FIELD_RULE_ACTION_ID).getAsString());
  assertEquals("host1", obj.get(Constants.FIELD_AGGREGATION_KEY).getAsString());
  assertEquals(100, obj.get(Constants.FIELD_AGGREGATION_WINDOW).getAsInt());
  assertEquals(true, obj.get(Constants.FIELD_STATE_TRACK).getAsBoolean());
}

代码示例来源:origin: Symantec/hendrix

int j = 1;
for (i = 1; i < 5; i++) {
  when(input.contains(Constants.FIELD_ALERT)).thenReturn(true);
  bolt.execute(input);
  assertEquals(j % 3, bolt.getCounter().get(alert.getId()).getVal());
  verify(collector, times(j++)).ack(input);
  if (i % 2 == 0) {
    when(input.contains(Constants.FIELD_ALERT)).thenReturn(false);
    when(input.getSourceComponent()).thenReturn(backtype.storm.Constants.SYSTEM_COMPONENT_ID);
    when(input.getSourceStreamId()).thenReturn(backtype.storm.Constants.SYSTEM_TICK_STREAM_ID);

代码示例来源:origin: Symantec/hendrix

alert.setMedia("mail");
alert.setTimestamp(3253454235L);
when(input.contains(Constants.FIELD_ALERT)).thenReturn(true);
when(input.getValueByField(Constants.FIELD_ALERT)).thenReturn(alert);
bolt.execute(input);

代码示例来源:origin: Symantec/hendrix

alert.setBody("test");
alert.setTimestamp(3253454235L);
when(input.contains(Constants.FIELD_ALERT)).thenReturn(true);
when(input.getValueByField(Constants.FIELD_ALERT)).thenReturn(alert);
int i = 0;
assertEquals(i + 1, bolt.getCounter().get(alert.getId()).getVal());
verify(collector, times(i + 1)).ack(input);
when(input.contains(Constants.FIELD_ALERT)).thenReturn(false);
when(input.getSourceComponent()).thenReturn(backtype.storm.Constants.SYSTEM_COMPONENT_ID);
when(input.getSourceStreamId()).thenReturn(backtype.storm.Constants.SYSTEM_TICK_STREAM_ID);

代码示例来源:origin: Symantec/hendrix

when(tuple.getStringByField(Constants.FIELD_AGGREGATION_KEY)).thenReturn((String) values.get(4));
when(tuple.contains(Constants.FIELD_STATE_TRACK)).thenReturn(true);

相关文章