/** * Sink implementation which forwards the items it receives to the Graphite. * Graphite's Pickle Protocol is used for communication between Jet and Graphite. * * @param host Graphite host * @param port Graphite port */ private static Sink<TimestampedEntry> buildGraphiteSink(String host, int port) { return sinkBuilder("graphite", instance -> new BufferedOutputStream(new Socket(host, port).getOutputStream())) .<TimestampedEntry>receiveFn((bos, entry) -> { GraphiteMetric metric = new GraphiteMetric(); metric.from(entry); PyString payload = cPickle.dumps(metric.getAsList(), 2); byte[] header = ByteBuffer.allocate(4).putInt(payload.__len__()).array(); bos.write(header); bos.write(payload.toBytes()); }) .flushFn(BufferedOutputStream::flush) .destroyFn(BufferedOutputStream::close) .build(); }
private static Sink<String> buildTopicSink() { return sinkBuilder("topicSink(" + TOPIC_NAME + ')', jet -> jet.jetInstance().getHazelcastInstance().<String>getTopic(TOPIC_NAME)) .<String>receiveFn((topic, message) -> topic.publish(message)) .build(); }
/** * A GUI Sink which will show the frames with the maximum classification scores. */ private static Sink<TimestampedItem<Tuple3<BufferedImage, String, Double>>> buildGUISink() { return sinkBuilder("GUI", (instance) -> createPanel()) .<TimestampedItem<Tuple3<BufferedImage, String, Double>>>receiveFn((panel, tsItem) -> { BufferedImage image = tsItem.item().f0(); Score score = new Score(); score.set(tsItem.item().f2(), 0); panel.addImage( image, new Timestamp(tsItem.timestamp()).toString(), singletonList(score), singletonList(tsItem.item().f1()) ); scrollToBottomAndRepaint(panel); }) .build(); }