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)));
}
}
Aggregations