@Override public void onEvents(PartitionContext context, Iterable<EventData> messages) throws ExecutionException, InterruptedException { // don't issue a write until we checkpoint or exit this callback List<Span> buffer = new ArrayList<>(); for (EventData data : messages) { byte[] bytes = data.getBytes(); BytesDecoder<Span> decoder = decoderForListMessage(bytes); List<Span> nextSpans = decoder.decodeList(bytes); buffer.addAll(nextSpans); if (maybeCheckpoint(context, data, nextSpans.size())) { collector.accept(buffer, NOOP); buffer.clear(); } } if (!buffer.isEmpty()) { collector.accept(buffer, NOOP); } }
try { Span span = SpanBytesDecoder.THRIFT.decodeOne(bytes); collector.accept(Collections.singletonList(span), NOOP); } catch (RuntimeException e) { metrics.incrementMessagesDropped();
@Override public void run() { ConsumerIterator<byte[], byte[]> messages = stream.iterator(); while (messages.hasNext()) { byte[] bytes = messages.next().message(); metrics.incrementMessages(); if (bytes.length < 2) { // need two bytes to check if protobuf metrics.incrementMessagesDropped(); continue; } // If we received legacy single-span encoding, decode it into a singleton list if (!protobuf3(bytes) && bytes[0] <= 16 && bytes[0] != 12 /* thrift, but not a list */) { try { metrics.incrementBytes(bytes.length); Span span = SpanBytesDecoder.THRIFT.decodeOne(bytes); collector.accept(Collections.singletonList(span), NOOP); } catch (RuntimeException e) { metrics.incrementMessagesDropped(); } } else { collector.acceptSpans(bytes, NOOP); } } }
collector.accept( spans, new Callback<Void>() {
public void acceptSpans( byte[] serializedSpans, BytesDecoder<Span> decoder, Callback<Void> callback) { metrics.incrementBytes(serializedSpans.length); List<Span> spans; try { spans = decodeList(decoder, serializedSpans); } catch (RuntimeException e) { callback.onError(errorReading(e)); return; } accept(spans, callback); }