Search in sources :

Example 1 with ManagerRequest

use of com.couchbase.client.core.msg.manager.ManagerRequest in project couchbase-jvm-clients by couchbase.

the class ManagerMessageHandler method write.

@Override
@SuppressWarnings({ "unchecked" })
public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) {
    if (msg instanceof ManagerRequest) {
        if (currentRequest != null) {
            RetryOrchestrator.maybeRetry(coreContext, (ManagerRequest<Response>) msg, RetryReason.NOT_PIPELINED_REQUEST_IN_FLIGHT);
            if (endpoint != null) {
                endpoint.decrementOutstandingRequests();
            }
            return;
        }
        try {
            currentRequest = (ManagerRequest<Response>) msg;
            FullHttpRequest encoded = currentRequest.encode();
            encoded.headers().set(HttpHeaderNames.HOST, remoteHost);
            encoded.headers().set(HttpHeaderNames.USER_AGENT, endpoint.context().environment().userAgent().formattedLong());
            ctx.writeAndFlush(encoded);
        } catch (Throwable t) {
            currentRequest.response().completeExceptionally(t);
            if (endpoint != null) {
                endpoint.decrementOutstandingRequests();
            }
        }
        currentContent.clear();
    } else {
        if (endpoint != null) {
            endpoint.decrementOutstandingRequests();
        }
        eventBus.publish(new InvalidRequestDetectedEvent(ioContext, ServiceType.MANAGER, msg));
        ctx.channel().close().addListener(f -> eventBus.publish(new ChannelClosedProactivelyEvent(ioContext, ChannelClosedProactivelyEvent.Reason.INVALID_REQUEST_DETECTED)));
    }
}
Also used : BucketConfigStreamingResponse(com.couchbase.client.core.msg.manager.BucketConfigStreamingResponse) HttpResponse(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponse) Response(com.couchbase.client.core.msg.Response) ManagerRequest(com.couchbase.client.core.msg.manager.ManagerRequest) FullHttpRequest(com.couchbase.client.core.deps.io.netty.handler.codec.http.FullHttpRequest) ChannelClosedProactivelyEvent(com.couchbase.client.core.cnc.events.io.ChannelClosedProactivelyEvent) InvalidRequestDetectedEvent(com.couchbase.client.core.cnc.events.io.InvalidRequestDetectedEvent)

Aggregations

ChannelClosedProactivelyEvent (com.couchbase.client.core.cnc.events.io.ChannelClosedProactivelyEvent)1 InvalidRequestDetectedEvent (com.couchbase.client.core.cnc.events.io.InvalidRequestDetectedEvent)1 FullHttpRequest (com.couchbase.client.core.deps.io.netty.handler.codec.http.FullHttpRequest)1 HttpResponse (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponse)1 Response (com.couchbase.client.core.msg.Response)1 BucketConfigStreamingResponse (com.couchbase.client.core.msg.manager.BucketConfigStreamingResponse)1 ManagerRequest (com.couchbase.client.core.msg.manager.ManagerRequest)1