@Override public void onResponse(Call call, Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { delegate.onComplete(); } else { delegate.onError(new IllegalStateException("response failed: " + response)); } } }
@Override public void onFailure(Call call, IOException e) { delegate.onError(e); }
/** Asynchronously sends the spans as a POST to {@link #endpoint()}. */ @Override public void sendSpans(List<byte[]> encodedSpans, Callback callback) { if (closeCalled) throw new IllegalStateException("closed"); try { Request request = newRequest(encoder().encode(encodedSpans)); client().newCall(request).enqueue(new CallbackAdapter(callback)); } catch (Throwable e) { callback.onError(e); if (e instanceof Error) throw (Error) e; } }
@Override public void sendSpans(List<byte[]> encodedSpans, Callback callback) { if (closeCalled) throw new IllegalStateException("closed"); try { if (get().log(encodedSpans)) { callback.onComplete(); } else { callback.onError(new IllegalStateException("try later")); } } catch (Throwable e) { callback.onError(e); if (e instanceof Error) throw (Error) e; } }
@Override public Void apply() { try { if (closeCalled) throw new IllegalStateException("closed"); client.apply(makeRequest(spans)).respond(new AbstractFunction1<Try<Rep>, BoxedUnit>() { @Override public BoxedUnit apply(Try<Rep> result) { if (result.isReturn()) { callback.onComplete(); } else { callback.onError(result.throwable()); } return BoxedUnit.UNIT; } }); } catch (Throwable e) { callback.onError(e); if (e instanceof Error) throw (Error) e; } return null; } });
/** Asynchronously sends the spans as a POST to {@link #endpoint()}. */ @Override public void sendSpans(List<byte[]> encodedSpans, Callback callback) { if (closeCalled) throw new IllegalStateException("close"); try { byte[] message = encoder().encode(encodedSpans); send(message, mediaType()); callback.onComplete(); } catch (Throwable e) { callback.onError(e); if (e instanceof Error) throw (Error) e; } }
void flush(BufferNextMessage bundler) { if (closed.get()) throw new IllegalStateException("closed"); pending.drainTo(bundler, bundler.remainingNanos()); // record after flushing reduces the amount of gauge events vs on doing this on report metrics.updateQueuedSpans(pending.count); metrics.updateQueuedBytes(pending.sizeInBytes); // loop around if we are running, and the bundle isn't full // if we are closed, try to send what's pending if (!bundler.isReady() && !closed.get()) return; // Signal that we are about to send a message of a known size in bytes metrics.incrementMessages(); metrics.incrementMessageBytes(bundler.sizeInBytes()); List<byte[]> nextMessage = bundler.drain(); // In failure case, we increment messages and spans dropped. Callback failureCallback = sendSpansCallback(nextMessage.size()); try { sender.sendSpans(nextMessage, failureCallback); } catch (RuntimeException e) { failureCallback.onError(e); // Raise in case the sender was closed out-of-band. if (e instanceof IllegalStateException) throw e; } }
/** * This sends all of the spans as a single message. * * <p>NOTE: this blocks until the metadata server is available. */ @SuppressWarnings("FutureReturnValueIgnored") // callbacks are used instead @Override public void sendSpans(List encodedSpans, Callback callback) { if (closeCalled) throw new IllegalStateException("closed"); try { final byte[] message = encoder().encode(encodedSpans); get().send(new ProducerRecord<>(topic(), message), (metadata, exception) -> { if (exception == null) { callback.onComplete(); } else { callback.onError(exception); } }); } catch (Throwable e) { callback.onError(e); if (e instanceof Error) throw (Error) e; } }
/** * This sends all of the spans as a single message. * * <p>NOTE: this blocks until the metadata server is available. */ @SuppressWarnings("FutureReturnValueIgnored") // callbacks are used instead @Override public void sendSpans(List encodedSpans, Callback callback) { if (closeCalled) throw new IllegalStateException("closed"); try { final byte[] message = encoder().encode(encodedSpans); get().send(new ProducerRecord<>(topic(), message), (metadata, exception) -> { if (exception == null) { callback.onComplete(); } else { callback.onError(exception); } }); } catch (Throwable e) { callback.onError(e); if (e instanceof Error) throw (Error) e; } }