Search in sources :

Example 61 with ByteBuf

use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.

the class GetMetaRequest method encode.

@Override
public ByteBuf encode(ByteBufAllocator alloc, int opaque, KeyValueChannelContext ctx) {
    ByteBuf key = null;
    ByteBuf extras = null;
    try {
        extras = alloc.buffer(Byte.BYTES);
        extras.writeByte(2);
        key = encodedKeyWithCollection(alloc, ctx);
        return MemcacheProtocol.request(alloc, MemcacheProtocol.Opcode.GET_META, noDatatype(), partition(), opaque, noCas(), extras, key, noBody());
    } finally {
        ReferenceCountUtil.release(key);
        ReferenceCountUtil.release(extras);
    }
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)

Example 62 with ByteBuf

use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.

the class DecrementRequest method encode.

@Override
public ByteBuf encode(ByteBufAllocator alloc, int opaque, KeyValueChannelContext ctx) {
    ByteBuf key = null;
    ByteBuf extras = null;
    ByteBuf flexibleExtras = mutationFlexibleExtras(this, ctx, alloc, syncReplicationType);
    try {
        key = encodedKeyWithCollection(alloc, ctx);
        extras = alloc.buffer((Long.BYTES * 2) + Integer.BYTES);
        extras.writeLong(delta);
        if (initial.isPresent()) {
            extras.writeLong(initial.get());
            extras.writeInt((int) expiry);
        } else {
            // no initial present, will lead to doc not found
            extras.writeLong(0);
            extras.writeInt(IncrementRequest.COUNTER_NOT_EXISTS_EXPIRY);
        }
        return MemcacheProtocol.flexibleRequest(alloc, MemcacheProtocol.Opcode.DECREMENT, noDatatype(), partition(), opaque, noCas(), flexibleExtras, extras, key, noBody());
    } finally {
        ReferenceCountUtil.release(key);
        ReferenceCountUtil.release(extras);
        ReferenceCountUtil.release(flexibleExtras);
    }
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)

Example 63 with ByteBuf

use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.

the class GetAndLockRequest method encode.

@Override
public ByteBuf encode(ByteBufAllocator alloc, int opaque, KeyValueChannelContext ctx) {
    ByteBuf key = null;
    ByteBuf extras = null;
    try {
        key = encodedKeyWithCollection(alloc, ctx);
        extras = alloc.buffer(Integer.BYTES).writeInt((int) lockFor.getSeconds());
        return MemcacheProtocol.request(alloc, Opcode.GET_AND_LOCK, noDatatype(), partition(), opaque, noCas(), extras, key, noBody());
    } finally {
        ReferenceCountUtil.release(key);
        ReferenceCountUtil.release(extras);
    }
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)

Example 64 with ByteBuf

use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.

the class GetAndTouchRequest method encode.

@Override
public ByteBuf encode(ByteBufAllocator alloc, int opaque, KeyValueChannelContext ctx) {
    ByteBuf key = null;
    ByteBuf extras = null;
    try {
        key = encodedKeyWithCollection(alloc, ctx);
        extras = alloc.buffer(Integer.BYTES).writeInt((int) expiration);
        return MemcacheProtocol.request(alloc, MemcacheProtocol.Opcode.GET_AND_TOUCH, noDatatype(), partition(), opaque, noCas(), extras, key, noBody());
    } finally {
        ReferenceCountUtil.release(key);
        ReferenceCountUtil.release(extras);
    }
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)

Example 65 with ByteBuf

use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.

the class ErrorMapLoadingHandler method buildErrorMapRequest.

/**
 * Helper method to build the error map fetch request.
 *
 * @param ctx the {@link ChannelHandlerContext} for which the channel active operation is made.
 * @return the created request as a {@link ByteBuf}.
 */
private ByteBuf buildErrorMapRequest(final ChannelHandlerContext ctx) {
    ByteBuf body = ctx.alloc().buffer(Short.BYTES).writeShort(MAP_VERSION);
    ByteBuf request = MemcacheProtocol.request(ctx.alloc(), MemcacheProtocol.Opcode.ERROR_MAP, noDatatype(), noPartition(), BaseKeyValueRequest.nextOpaque(), noCas(), noExtras(), noKey(), body);
    body.release();
    return request;
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)

Aggregations

ByteBuf (com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)107 Test (org.junit.jupiter.api.Test)54 InetSocketAddress (java.net.InetSocketAddress)17 EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)12 ChannelFuture (com.couchbase.client.core.deps.io.netty.channel.ChannelFuture)11 Duration (java.time.Duration)10 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)9 CoreContext (com.couchbase.client.core.CoreContext)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 CompressionConfig (com.couchbase.client.core.env.CompressionConfig)6 ResponseStatus (com.couchbase.client.core.msg.ResponseStatus)6 GetRequest (com.couchbase.client.core.msg.kv.GetRequest)6 ChannelHandlerContext (com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext)5 AuthenticationFailureException (com.couchbase.client.core.error.AuthenticationFailureException)5 ArrayList (java.util.ArrayList)5 DurabilityTimeoutCoercedEvent (com.couchbase.client.core.cnc.events.io.DurabilityTimeoutCoercedEvent)4 FeaturesNegotiatedEvent (com.couchbase.client.core.cnc.events.io.FeaturesNegotiatedEvent)4 CompositeByteBuf (com.couchbase.client.core.deps.io.netty.buffer.CompositeByteBuf)4 FullHttpRequest (com.couchbase.client.core.deps.io.netty.handler.codec.http.FullHttpRequest)4 BaseEndpoint (com.couchbase.client.core.endpoint.BaseEndpoint)4