public static TimeData fromTuple(Tuple tuple) { return new TimeData(tuple.getIntegerByField(NUMBER_FIELD_NAME), new Date(tuple.getLongByField(TIMESTAMP_FIELD_NAME))); }
@Override public void execute(TupleWindow inputWindow) { for (Tuple tuple : inputWindow.get()) { sum += tuple.getIntegerByField("value"); } state.put("sum", sum); collector.emit(new Values(sum)); }
/** * This bolt consumes telemetry messages and determines if the message is needed * by any of the profiles. The message is then routed to one or more downstream * bolts that are responsible for building each profile * * <p>The outgoing tuples are timestamped so that Storm's window and event-time * processing functionality can recognize the time of each message. * * <p>The timestamp that is attached to each outgoing tuple is what decides if * the Profiler is operating on processing time or event time. * * @param input The tuple. */ @Override public void execute(Tuple input) { try { LOG.debug("Received message; topic={}, partition={}, offset={}, kafkaTimestamp={}", input.contains(TOPIC.getFieldName()) ? input.getStringByField(TOPIC.getFieldName()): "unknown", input.contains(PARTITION.getFieldName()) ? input.getIntegerByField(PARTITION.getFieldName()): "unknown", input.contains(OFFSET.getFieldName()) ? input.getLongByField(OFFSET.getFieldName()): "unknown", input.contains(TIMESTAMP.getFieldName()) ? input.getLongByField(TIMESTAMP.getFieldName()): "unknown"); doExecute(input); } catch (Throwable t) { LOG.error("Unexpected error", t); collector.reportError(t); } finally { collector.ack(input); } }