Search in sources :

Example 6 with IoContext

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

the class SaslAuthenticationHandler 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 SASL Negotiation timed out after " + timeout.toMillis() + "ms"));
        }
    }, timeout.toNanos(), TimeUnit.NANOSECONDS);
    ConnectTimings.start(ctx.channel(), this.getClass());
    startAuthSequence(ctx, allowedMechanisms);
}
Also used : IoContext(com.couchbase.client.core.io.IoContext) TimeoutException(java.util.concurrent.TimeoutException)

Example 7 with IoContext

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

the class SelectBucketHandler 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 Select Bucket loading timed out after " + timeout.toMillis() + "ms"));
        }
    }, timeout.toNanos(), TimeUnit.NANOSECONDS);
    ConnectTimings.start(ctx.channel(), this.getClass());
    ctx.writeAndFlush(buildSelectBucketRequest(ctx));
}
Also used : IoContext(com.couchbase.client.core.io.IoContext) TimeoutException(java.util.concurrent.TimeoutException)

Example 8 with IoContext

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

the class MemcacheProtocolVerificationHandler method handleEventAndCloseChannel.

/**
 * Helper method to send the event into the event bus and then close the
 * channel.
 *
 * @param ctx the context to use.
 * @param msg the msg to export.
 */
private void handleEventAndCloseChannel(final ChannelHandlerContext ctx, final ByteBuf msg) {
    final IoContext ioContext = new IoContext(endpointContext, ctx.channel().localAddress(), ctx.channel().remoteAddress(), endpointContext.bucket());
    byte[] packet = ByteBufUtil.getBytes(msg);
    ReferenceCountUtil.release(msg);
    endpointContext.environment().eventBus().publish(new InvalidPacketDetectedEvent(ioContext, packet));
    ctx.close();
}
Also used : IoContext(com.couchbase.client.core.io.IoContext) InvalidPacketDetectedEvent(com.couchbase.client.core.cnc.events.io.InvalidPacketDetectedEvent)

Example 9 with IoContext

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

the class SaslListMechanismsHandler method channelActive.

/**
 * As soon as the channel is active start sending the 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("SASL Mechanism listing timed out after " + timeout.toMillis() + "ms"));
        }
    }, timeout.toNanos(), TimeUnit.NANOSECONDS);
    ConnectTimings.start(ctx.channel(), this.getClass());
    ctx.writeAndFlush(buildListMechanismsRequest(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 10 with IoContext

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

the class KeyValueMessageHandler method channelActive.

/**
 * Actions to be performed when the channel becomes active.
 *
 * <p>Since the opaque is incremented in the handler below during bootstrap but now is
 * only modified in this handler, cache the reference since the attribute lookup is
 * more costly.</p>
 *
 * @param ctx the channel context.
 */
@Override
public void channelActive(final ChannelHandlerContext ctx) {
    ioContext = new IoContext(endpointContext, ctx.channel().localAddress(), ctx.channel().remoteAddress(), endpointContext.bucket());
    errorMap = ctx.channel().attr(ChannelAttributes.ERROR_MAP_KEY).get();
    Set<ServerFeature> features = ctx.channel().attr(ChannelAttributes.SERVER_FEATURE_KEY).get();
    boolean compression = features != null && features.contains(ServerFeature.SNAPPY);
    boolean collections = features != null && features.contains(ServerFeature.COLLECTIONS);
    boolean mutationTokens = features != null && features.contains(ServerFeature.MUTATION_SEQNO);
    boolean syncReplication = features != null && features.contains(ServerFeature.SYNC_REPLICATION);
    boolean altRequest = features != null && features.contains(ServerFeature.ALT_REQUEST);
    boolean vattrEnabled = features != null && features.contains(ServerFeature.VATTR);
    boolean createAsDeleted = features != null && features.contains(ServerFeature.CREATE_AS_DELETED);
    boolean preserveTtl = features != null && features.contains(ServerFeature.PRESERVE_TTL);
    if (syncReplication && !altRequest) {
        throw new IllegalStateException("If Synchronous Replication is enabled, the server also " + "must negotiate Alternate Requests. This is a bug! - please report.");
    }
    channelContext = new KeyValueChannelContext(compression ? compressionConfig : null, collections, mutationTokens, bucketName, syncReplication, vattrEnabled, altRequest, ioContext.core().configurationProvider().collectionMap(), ctx.channel().id(), createAsDeleted, preserveTtl);
    ctx.fireChannelActive();
}
Also used : IoContext(com.couchbase.client.core.io.IoContext)

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