@Override public void prepare(Map conf, TridentOperationContext context) { this.reporter = new KafkaReporter(config.reporterTopic, config.brokerList); }
@Override public Tuple2<String, String> map(Tuple2<String, String> value) throws Exception { KafkaReporter kafkaReporter = new KafkaReporter(config.reportTopic, config.brokerList); kafkaReporter.report(Long.parseLong(value.f0), System.currentTimeMillis()); return value; } });
@Override public State init() { this.reporter = new KafkaReporter(config.reporterTopic, config.brokerList); return new State(); }
@Override public Tuple2<String, String> map(Tuple2<String, String> value) throws Exception { KafkaReporter kafkaReporter = new KafkaReporter(config.reportTopic, config.brokerList); kafkaReporter.report(Long.parseLong(value.f0), System.currentTimeMillis()); return value; } });
@Override public void execute(Tuple tuple, BasicOutputCollector collector) { String word = tuple.getString(0); Integer count = counts.get(word); if (count == null) count = 0; count++; counts.put(word, count); LatencyReporter latencyReporter = new KafkaReporter(config.reporterTopic, config.brokerList); latencyReporter.report(tuple.getLong(1), System.currentTimeMillis()); }
@Override public Values execute(TridentTuple tridentTuple) { ImmutableMap<String, String> kv = (ImmutableMap<String, String>) tridentTuple.getValue(0); LatencyReporter reporter = new KafkaReporter(config.reporterTopic, config.brokerList); reporter.report(Long.parseLong(kv.keySet().iterator().next()), System.currentTimeMillis()); return new Values(kv); } }
@Override public void execute(TupleWindow inputWindow) { Map<String, Long[]> counts = new HashMap<String, Long[]>(); for (Tuple tuple : inputWindow.get()) { Long time = tuple.getLong(1); String ip = tuple.getString(0); Long[] timeAndCount = counts.get(ip); if (null == timeAndCount) { timeAndCount = new Long[2]; timeAndCount[0] = time; timeAndCount[1] = 0L; } timeAndCount[0] = Math.min(timeAndCount[0], time); timeAndCount[1]++; counts.put(ip, timeAndCount); } LatencyReporter latencyReporter = new KafkaReporter(config.reporterTopic, config.brokerList); for (Long[] timeAndCount : counts.values()) { for (int i = 0; i < timeAndCount[1]; i++) { latencyReporter.report(timeAndCount[0], System.currentTimeMillis()); } } }
@Override public void execute(Tuple tuple, BasicOutputCollector collector) { final LatencyReporter latencyReporter = new KafkaReporter(config.reporterTopic, config.brokerList); ImmutableMap<String, String> kv = (ImmutableMap<String, String>) tuple.getValue(0); collector.emit(new Values(kv)); latencyReporter.report(Long.parseLong(kv.keySet().iterator().next()), System.currentTimeMillis()); }