Search in sources :

Example 36 with ByteBuf

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

the class ObserveViaCasRequest method encode.

@Override
public ByteBuf encode(ByteBufAllocator alloc, int opaque, KeyValueChannelContext ctx) {
    ByteBuf key = null;
    ByteBuf content = null;
    try {
        key = encodedKeyWithCollection(alloc, ctx);
        int keyLength = key.readableBytes();
        content = alloc.buffer(keyLength + (Short.BYTES * 2));
        content.writeShort(partition());
        content.writeShort(keyLength);
        content.writeBytes(key);
        return request(alloc, MemcacheProtocol.Opcode.OBSERVE_CAS, noDatatype(), partition(), opaque, noCas(), noExtras(), noKey(), content);
    } finally {
        ReferenceCountUtil.release(key);
        ReferenceCountUtil.release(content);
    }
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)

Example 37 with ByteBuf

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

the class ObserveViaSeqnoRequest method decode.

@Override
public ObserveViaSeqnoResponse decode(final ByteBuf response, final KeyValueChannelContext ctx) {
    ResponseStatus status = decodeStatus(response);
    if (status.success()) {
        ByteBuf content = body(response).get();
        byte format = content.readByte();
        short vbucketId = content.readShort();
        long vbucketUUID = content.readLong();
        long lastPersistedSeqno = content.readLong();
        long currentSeqno = content.readLong();
        switch(format) {
            case 0:
                return new ObserveViaSeqnoResponse(status, active, vbucketId, vbucketUUID, lastPersistedSeqno, currentSeqno, Optional.empty(), Optional.empty());
            case 1:
                return new ObserveViaSeqnoResponse(status, active, vbucketId, vbucketUUID, lastPersistedSeqno, currentSeqno, Optional.of(content.readLong()), Optional.of(content.readLong()));
            default:
                throw new IllegalStateException("Unsupported format 0x" + Integer.toHexString(format));
        }
    } else {
        return new ObserveViaSeqnoResponse(status, active, (short) 0, 0L, 0L, 0L, Optional.empty(), Optional.empty());
    }
}
Also used : ResponseStatus(com.couchbase.client.core.msg.ResponseStatus) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)

Example 38 with ByteBuf

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

the class RemoveRequest method encode.

@Override
public ByteBuf encode(ByteBufAllocator alloc, int opaque, KeyValueChannelContext ctx) {
    ByteBuf key = null;
    ByteBuf flexibleExtras = mutationFlexibleExtras(this, ctx, alloc, syncReplicationType);
    try {
        key = encodedKeyWithCollection(alloc, ctx);
        return MemcacheProtocol.flexibleRequest(alloc, MemcacheProtocol.Opcode.DELETE, noDatatype(), partition(), opaque, cas, flexibleExtras, noExtras(), key, noBody());
    } finally {
        ReferenceCountUtil.release(key);
        ReferenceCountUtil.release(flexibleExtras);
    }
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)

Example 39 with ByteBuf

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

the class SearchRequest method encode.

@Override
public FullHttpRequest encode() {
    ByteBuf c = Unpooled.wrappedBuffer(content);
    String uri = "/api/index/" + indexName + "/query";
    FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uri, c);
    request.headers().set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON);
    request.headers().set(HttpHeaderNames.CONTENT_LENGTH, c.readableBytes());
    authenticator.authHttpRequest(serviceType(), request);
    return request;
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)

Example 40 with ByteBuf

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

the class ViewRequest method encode.

@Override
public FullHttpRequest encode() {
    StringBuilder path = new StringBuilder();
    path.append("/").append(bucket).append("/_design/");
    path.append(development ? "dev_" + design : design);
    path.append("/_view/");
    path.append(view);
    path.append("?").append(query);
    ByteBuf content = keysJson.isPresent() ? Unpooled.copiedBuffer(keysJson.get()) : Unpooled.EMPTY_BUFFER;
    HttpMethod method = keysJson.isPresent() ? HttpMethod.POST : HttpMethod.GET;
    FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, method, path.toString(), content);
    request.headers().set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON).set(HttpHeaderNames.CONTENT_LENGTH, content.readableBytes()).set(HttpHeaderNames.USER_AGENT, context().environment().userAgent().formattedLong());
    authenticator.authHttpRequest(serviceType(), request);
    return request;
}
Also used : FullHttpRequest(com.couchbase.client.core.deps.io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpRequest) DefaultFullHttpRequest(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpRequest) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) HttpMethod(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpMethod)

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