/** * 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(); }