Search in sources :

Example 1 with IoContext

use of com.couchbase.client.core.io.IoContext in project couchbase-jvm-clients by couchbase.

the class ErrorMapLoadingHandler method channelActive.

@Override
public void channelActive(final ChannelHandlerContext ctx) {
    ioContext = new IoContext(endpointContext, ctx.channel().localAddress(), ctx.channel().remoteAddress(), endpointContext.bucket());
    ctx.executor().schedule(() -> {
        if (!interceptedConnectPromise.isDone()) {
            ConnectTimings.stop(ctx.channel(), this.getClass(), true);
            interceptedConnectPromise.tryFailure(new TimeoutException("KV Error Map loading timed out after " + timeout.toMillis() + "ms"));
        }
    }, timeout.toNanos(), TimeUnit.NANOSECONDS);
    ConnectTimings.start(ctx.channel(), this.getClass());
    ctx.writeAndFlush(buildErrorMapRequest(ctx));
    // Fire the channel active immediately so the upper handler in the pipeline gets a chance to
    // pipeline its request before the response of this one arrives. This helps speeding up the
    // bootstrap sequence.
    ctx.fireChannelActive();
}
Also used : IoContext(com.couchbase.client.core.io.IoContext) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with IoContext

use of com.couchbase.client.core.io.IoContext in project couchbase-jvm-clients by couchbase.

the class FeatureNegotiatingHandler method channelActive.

/**
 * As soon as the channel is active start sending the hello request but also schedule
 * a timeout properly.
 *
 * @param ctx the {@link ChannelHandlerContext} for which the channel active operation is made.
 */
@Override
public void channelActive(final ChannelHandlerContext ctx) {
    ioContext = new IoContext(endpointContext, ctx.channel().localAddress(), ctx.channel().remoteAddress(), endpointContext.bucket());
    ctx.executor().schedule(() -> {
        if (!interceptedConnectPromise.isDone()) {
            ConnectTimings.stop(ctx.channel(), this.getClass(), true);
            interceptedConnectPromise.tryFailure(new TimeoutException("KV Feature Negotiation timed out after " + timeout.toMillis() + "ms"));
        }
    }, timeout.toNanos(), TimeUnit.NANOSECONDS);
    ConnectTimings.start(ctx.channel(), this.getClass());
    ctx.writeAndFlush(buildHelloRequest(ctx));
    // Fire the channel active immediately so the upper handler in the pipeline gets a chance to
    // pipeline its request before the response of this one arrives. This helps speeding up the
    // bootstrap sequence.
    ctx.fireChannelActive();
}
Also used : IoContext(com.couchbase.client.core.io.IoContext) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with IoContext

use of com.couchbase.client.core.io.IoContext in project couchbase-jvm-clients by couchbase.

the class ChunkedMessageHandler method channelActive.

@Override
public void channelActive(final ChannelHandlerContext ctx) {
    remoteHost = endpoint.remoteHostname() + ":" + endpoint.remotePort();
    ioContext = new IoContext(endpointContext, ctx.channel().localAddress(), ctx.channel().remoteAddress(), endpointContext.bucket());
    ctx.fireChannelActive();
}
Also used : IoContext(com.couchbase.client.core.io.IoContext)

Example 4 with IoContext

use of com.couchbase.client.core.io.IoContext in project couchbase-jvm-clients by couchbase.

the class ManagerMessageHandler method channelActive.

@Override
public void channelActive(final ChannelHandlerContext ctx) {
    ioContext = new IoContext(coreContext, ctx.channel().localAddress(), ctx.channel().remoteAddress(), Optional.empty());
    remoteHost = endpoint.remoteHostname() + ":" + endpoint.remotePort();
    currentContent = ctx.alloc().buffer();
    ctx.fireChannelActive();
}
Also used : IoContext(com.couchbase.client.core.io.IoContext)

Example 5 with IoContext

use of com.couchbase.client.core.io.IoContext in project couchbase-jvm-clients by couchbase.

the class KeyValueMessageHandler method handleNotMyVbucket.

/**
 * Helper method to handle a "not my vbucket" response.
 *
 * @param request the request to retry.
 * @param response the response to extract the config from, potentially.
 */
private void handleNotMyVbucket(final KeyValueRequest<Response> request, final ByteBuf response) {
    request.indicateRejectedWithNotMyVbucket();
    eventBus.publish(new NotMyVbucketReceivedEvent(ioContext, request.partition()));
    final String origin = request.context().lastDispatchedTo() != null ? request.context().lastDispatchedTo().hostname() : null;
    RetryOrchestrator.maybeRetry(ioContext, request, RetryReason.KV_NOT_MY_VBUCKET);
    body(response).map(b -> b.toString(UTF_8).trim()).filter(c -> c.startsWith("{")).ifPresent(c -> ioContext.core().configurationProvider().proposeBucketConfig(new ProposedBucketConfigContext(request.bucket(), c, origin)));
}
Also used : IoContext(com.couchbase.client.core.io.IoContext) UnsignedLEB128(com.couchbase.client.core.util.UnsignedLEB128) HandlerUtils.closeChannelWithReason(com.couchbase.client.core.io.netty.HandlerUtils.closeChannelWithReason) ReferenceCountUtil(com.couchbase.client.core.deps.io.netty.util.ReferenceCountUtil) Request(com.couchbase.client.core.msg.Request) CompressionConfig(com.couchbase.client.core.env.CompressionConfig) RETRY_NOW(com.couchbase.client.core.io.netty.kv.ErrorMap.ErrorAttribute.RETRY_NOW) EventBus(com.couchbase.client.core.cnc.EventBus) TracingUtils.setCommonKVSpanAttributes(com.couchbase.client.core.io.netty.TracingUtils.setCommonKVSpanAttributes) ServiceType(com.couchbase.client.core.service.ServiceType) CoreContext(com.couchbase.client.core.CoreContext) Map(java.util.Map) TracingUtils.setCommonDispatchSpanAttributes(com.couchbase.client.core.io.netty.TracingUtils.setCommonDispatchSpanAttributes) EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) ITEM_LOCKED(com.couchbase.client.core.io.netty.kv.ErrorMap.ErrorAttribute.ITEM_LOCKED) RequestSpan(com.couchbase.client.core.cnc.RequestSpan) CbTracing(com.couchbase.client.core.cnc.CbTracing) RetryOrchestrator(com.couchbase.client.core.retry.RetryOrchestrator) ChannelHandlerContext(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext) TEMP(com.couchbase.client.core.io.netty.kv.ErrorMap.ErrorAttribute.TEMP) BaseEndpoint(com.couchbase.client.core.endpoint.BaseEndpoint) Set(java.util.Set) KeyValueRequest(com.couchbase.client.core.msg.kv.KeyValueRequest) Collectors(java.util.stream.Collectors) TracingUtils(com.couchbase.client.core.io.netty.TracingUtils) RetryReason(com.couchbase.client.core.retry.RetryReason) ResponseStatus(com.couchbase.client.core.msg.ResponseStatus) DecodingFailureException(com.couchbase.client.core.error.DecodingFailureException) Optional(java.util.Optional) ChannelPromise(com.couchbase.client.core.deps.io.netty.channel.ChannelPromise) Response(com.couchbase.client.core.msg.Response) TracingUtils.setNumericOperationId(com.couchbase.client.core.io.netty.TracingUtils.setNumericOperationId) CollectionNotFoundException(com.couchbase.client.core.error.CollectionNotFoundException) UnsupportedResponseTypeReceivedEvent(com.couchbase.client.core.cnc.events.io.UnsupportedResponseTypeReceivedEvent) HashMap(java.util.HashMap) KeyValueErrorMapCodeHandledEvent(com.couchbase.client.core.cnc.events.io.KeyValueErrorMapCodeHandledEvent) IntObjectMap(com.couchbase.client.core.deps.io.netty.util.collection.IntObjectMap) TracingIdentifiers(com.couchbase.client.core.cnc.TracingIdentifiers) RETRY_LATER(com.couchbase.client.core.io.netty.kv.ErrorMap.ErrorAttribute.RETRY_LATER) NotMyVbucketReceivedEvent(com.couchbase.client.core.cnc.events.io.NotMyVbucketReceivedEvent) MemcachedBucketConfig(com.couchbase.client.core.config.MemcachedBucketConfig) ProposedBucketConfigContext(com.couchbase.client.core.config.ProposedBucketConfigContext) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) ChannelDuplexHandler(com.couchbase.client.core.deps.io.netty.channel.ChannelDuplexHandler) CollectionOutdatedHandledEvent(com.couchbase.client.core.cnc.events.io.CollectionOutdatedHandledEvent) RequestTracer(com.couchbase.client.core.cnc.RequestTracer) InvalidRequestDetectedEvent(com.couchbase.client.core.cnc.events.io.InvalidRequestDetectedEvent) ConfigurationProvider(com.couchbase.client.core.config.ConfigurationProvider) UnknownResponseReceivedEvent(com.couchbase.client.core.cnc.events.io.UnknownResponseReceivedEvent) UTF_8(java.nio.charset.StandardCharsets.UTF_8) FeatureNotAvailableException(com.couchbase.client.core.error.FeatureNotAvailableException) UnlockRequest(com.couchbase.client.core.msg.kv.UnlockRequest) CollectionMap(com.couchbase.client.core.io.CollectionMap) ByteBufUtil(com.couchbase.client.core.deps.io.netty.buffer.ByteBufUtil) CONN_STATE_INVALIDATED(com.couchbase.client.core.io.netty.kv.ErrorMap.ErrorAttribute.CONN_STATE_INVALIDATED) UnknownResponseStatusReceivedEvent(com.couchbase.client.core.cnc.events.io.UnknownResponseStatusReceivedEvent) ChannelClosedProactivelyEvent(com.couchbase.client.core.cnc.events.io.ChannelClosedProactivelyEvent) IntObjectHashMap(com.couchbase.client.core.deps.io.netty.util.collection.IntObjectHashMap) AUTH(com.couchbase.client.core.io.netty.kv.ErrorMap.ErrorAttribute.AUTH) MemcacheProtocol.body(com.couchbase.client.core.io.netty.kv.MemcacheProtocol.body) NotMyVbucketReceivedEvent(com.couchbase.client.core.cnc.events.io.NotMyVbucketReceivedEvent) ProposedBucketConfigContext(com.couchbase.client.core.config.ProposedBucketConfigContext)

Aggregations

IoContext (com.couchbase.client.core.io.IoContext)12 TimeoutException (java.util.concurrent.TimeoutException)5 CoreContext (com.couchbase.client.core.CoreContext)1 CbTracing (com.couchbase.client.core.cnc.CbTracing)1 EventBus (com.couchbase.client.core.cnc.EventBus)1 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)1 RequestTracer (com.couchbase.client.core.cnc.RequestTracer)1 TracingIdentifiers (com.couchbase.client.core.cnc.TracingIdentifiers)1 ChannelClosedProactivelyEvent (com.couchbase.client.core.cnc.events.io.ChannelClosedProactivelyEvent)1 CollectionOutdatedHandledEvent (com.couchbase.client.core.cnc.events.io.CollectionOutdatedHandledEvent)1 InvalidPacketDetectedEvent (com.couchbase.client.core.cnc.events.io.InvalidPacketDetectedEvent)1 InvalidRequestDetectedEvent (com.couchbase.client.core.cnc.events.io.InvalidRequestDetectedEvent)1 KeyValueErrorMapCodeHandledEvent (com.couchbase.client.core.cnc.events.io.KeyValueErrorMapCodeHandledEvent)1 NotMyVbucketReceivedEvent (com.couchbase.client.core.cnc.events.io.NotMyVbucketReceivedEvent)1 UnknownResponseReceivedEvent (com.couchbase.client.core.cnc.events.io.UnknownResponseReceivedEvent)1 UnknownResponseStatusReceivedEvent (com.couchbase.client.core.cnc.events.io.UnknownResponseStatusReceivedEvent)1 UnsupportedResponseTypeReceivedEvent (com.couchbase.client.core.cnc.events.io.UnsupportedResponseTypeReceivedEvent)1 ConfigurationProvider (com.couchbase.client.core.config.ConfigurationProvider)1 MemcachedBucketConfig (com.couchbase.client.core.config.MemcachedBucketConfig)1 ProposedBucketConfigContext (com.couchbase.client.core.config.ProposedBucketConfigContext)1