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"); } }
public static boolean isTick(Tuple tuple) { return tuple != null && Constants.SYSTEM_COMPONENT_ID.equals(tuple.getSourceComponent()) && Constants.SYSTEM_TICK_STREAM_ID.equals(tuple.getSourceStreamId()); }
public static boolean isTickTuple(Tuple tuple) { return tuple.getSourceComponent().equals(Constants.SYSTEM_COMPONENT_ID) && tuple.getSourceStreamId().equals(Constants.SYSTEM_TICK_STREAM_ID); } }
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); }
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); } }
@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); } }
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; } }
@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); } } }
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"); } }
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"); } }
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"); } }
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"); } } }
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 } }
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); } }
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; }
@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")); }
@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())); } }
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); }
@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")); }
@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())); } }