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