Search in sources :

Example 1 with EndpointWriteFailedEvent

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);
    }
}
Also used : RetryReason(com.couchbase.client.core.retry.RetryReason) EndpointDisconnectionFailedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointDisconnectionFailedEvent) EndpointConnectionAbortedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionAbortedEvent) EndpointConnectedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectedEvent) UnexpectedEndpointDisconnectedEvent(com.couchbase.client.core.cnc.events.endpoint.UnexpectedEndpointDisconnectedEvent) EndpointWriteFailedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointWriteFailedEvent) EndpointConnectionFailedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionFailedEvent) UnexpectedEndpointConnectionFailedEvent(com.couchbase.client.core.cnc.events.endpoint.UnexpectedEndpointConnectionFailedEvent) EndpointConnectionIgnoredEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionIgnoredEvent) Event(com.couchbase.client.core.cnc.Event) EndpointStateChangedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointStateChangedEvent) EndpointDisconnectedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointDisconnectedEvent) EndpointWriteFailedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointWriteFailedEvent)

Aggregations

Event (com.couchbase.client.core.cnc.Event)1 EndpointConnectedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointConnectedEvent)1 EndpointConnectionAbortedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionAbortedEvent)1 EndpointConnectionFailedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionFailedEvent)1 EndpointConnectionIgnoredEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionIgnoredEvent)1 EndpointDisconnectedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointDisconnectedEvent)1 EndpointDisconnectionFailedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointDisconnectionFailedEvent)1 EndpointStateChangedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointStateChangedEvent)1 EndpointWriteFailedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointWriteFailedEvent)1 UnexpectedEndpointConnectionFailedEvent (com.couchbase.client.core.cnc.events.endpoint.UnexpectedEndpointConnectionFailedEvent)1 UnexpectedEndpointDisconnectedEvent (com.couchbase.client.core.cnc.events.endpoint.UnexpectedEndpointDisconnectedEvent)1 RetryReason (com.couchbase.client.core.retry.RetryReason)1