use of com.couchbase.client.core.cnc.events.endpoint.EndpointWriteFailedEvent in project couchbase-jvm-clients by couchbase.
the class BaseEndpoint method send.
@Override
public <R extends Request<? extends Response>> void send(final R request) {
if (request.timeoutElapsed()) {
request.cancel(CancellationReason.TIMEOUT);
}
if (request.completed()) {
return;
}
final EndpointContext ctx = endpointContext.get();
if (canWrite()) {
request.context().lastDispatchedFrom(ctx.localSocket().orElse(null)).lastDispatchedTo(ctx.remoteSocket()).lastChannelId(ctx.channelId().orElse(null));
if (!pipelined) {
outstandingRequests.incrementAndGet();
}
if (circuitBreakerEnabled) {
circuitBreaker.track();
request.response().whenComplete((response, throwable) -> {
if (circuitBreakerCallback.apply(response, throwable)) {
circuitBreaker.markSuccess();
} else {
circuitBreaker.markFailure();
}
});
}
channel.writeAndFlush(request).addListener(f -> {
if (!f.isSuccess()) {
EndpointContext context = endpointContext.get();
Event.Severity severity = disconnect.get() ? Event.Severity.DEBUG : Event.Severity.WARN;
context.environment().eventBus().publish(new EndpointWriteFailedEvent(severity, context, f.cause()));
RetryOrchestrator.maybeRetry(context, request, RetryReason.ENDPOINT_NOT_WRITABLE);
}
});
} else {
RetryReason retryReason = circuitBreaker.allowsRequest() ? RetryReason.ENDPOINT_NOT_WRITABLE : RetryReason.ENDPOINT_CIRCUIT_OPEN;
RetryOrchestrator.maybeRetry(endpointContext.get(), request, retryReason);
}
}
Aggregations