@Override public byte[] serialize(Tuple tuple) { StringBuilder sb = new StringBuilder(); for (Object obj : tuple.getValues()) { if (sb.length() != 0) { sb.append(delimiter); } sb.append(obj.toString()); } return sb.toString().getBytes(); }
private byte[] generateRecord(Tuple tuple) { StringBuilder buf = new StringBuilder(); for (Object o : tuple.getValues()) { buf.append(o); buf.append(","); } return buf.toString().getBytes(); }
@Override public void execute(Tuple tuple) { Long now = System.currentTimeMillis(); Long then = (Long) tuple.getValues().get(0); LOG.warn("Latency {} ", now - then); System.err.println(now - then); collector.ack(tuple); }
@Override public void execute(Tuple tuple, BasicOutputCollector collector) { System.out.println(tuple); LOG.debug("Got tuple {}", tuple); collector.emit(tuple.getValues()); }
@Override public void execute(Tuple input, BasicOutputCollector collector) { collector.emit(input.getValues()); }
public void execute(Tuple input) { String word = (String) input.getValues().get(0); int count = (Integer) input.getValues().get(1); _counts.put(word, count); int globalCount = 0; for (String w : _counts.keySet()) { globalCount += _counts.get(w); } _collector.emit(tuple(globalCount)); _collector.ack(input); }
public void execute(Tuple input, BasicOutputCollector collector) { total = total.add(new BigInteger(input.getValues().get(1).toString())); collector.emit(tuple(total.toString())); //prints the total with low probability. if(RANDOM.nextInt(1000) > 995) { LOG.info("Running total = " + total); } }
public void execute(Tuple input, BasicOutputCollector collector) { total = total.add(new BigInteger(input.getValues().get(1).toString())); collector.emit(tuple(total.toString())); //prints the total with low probability. if (RANDOM.nextInt(1000) > 995) { LOG.info("Running total = " + total); } }
@Override public void execute(Tuple input, BasicOutputCollector collector) { long id = Utils.secureRandomLong(); List<Object> toEmit = new ArrayList<Object>(); toEmit.add(id); toEmit.addAll(input.getValues()); collector.emit(toEmit); }
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 input, BasicOutputCollector collector) { collector.emit(tuple(input.getValues().get(0), 1)); }
@Override public void execute(TupleWindow inputWindow) { List<Tuple> tuplesInWindow = inputWindow.get(); List<Tuple> newTuples = inputWindow.getNew(); List<Tuple> expiredTuples = inputWindow.getExpired(); LOG.info("tuplesInWindow.size() = " + tuplesInWindow.size()); LOG.info("newTuples.size() = " + newTuples.size()); LOG.info("expiredTuples.size() = " + expiredTuples.size()); LOG.info(StringDecorator.decorate(componentId, "tuplesInWindow = " + tuplesInWindow.stream() .map(t -> t.getValues()) .collect(Collectors.toList()))); collector.emit(new Values("dummyValue")); }
@Override public void execute(Tuple tuple) { collector.emit(tuple, tuple.getValues()); collector.ack(tuple); }
@Override public void execute(Tuple tuple) { collector.emit(tuple, new Values(tuple.getValues())); collector.ack(tuple); }
@Override public void execute(Tuple input) { collector.emit(input, input.getValues()); collector.ack(input); }
@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 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")); }
@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")); }