Search in sources :

Example 1 with CompressionConfig

use of com.couchbase.client.core.env.CompressionConfig in project couchbase-jvm-clients by couchbase.

the class UpsertRequest method encode.

@Override
public ByteBuf encode(ByteBufAllocator alloc, int opaque, KeyValueChannelContext ctx) {
    ByteBuf key = null;
    ByteBuf content = null;
    ByteBuf extras = null;
    ByteBuf flexibleExtras = mutationFlexibleExtras(this, ctx, alloc, syncReplicationType, preserveExpiry);
    try {
        key = encodedKeyWithCollection(alloc, ctx);
        byte datatype = 0;
        CompressionConfig config = ctx.compressionConfig();
        if (config != null && config.enabled() && this.content.length >= config.minSize()) {
            ByteBuf maybeCompressed = MemcacheProtocol.tryCompression(this.content, config.minRatio());
            if (maybeCompressed != null) {
                datatype |= MemcacheProtocol.Datatype.SNAPPY.datatype();
                content = maybeCompressed;
            } else {
                content = Unpooled.wrappedBuffer(this.content);
            }
        } else {
            content = Unpooled.wrappedBuffer(this.content);
        }
        extras = alloc.buffer(Integer.BYTES * 2);
        extras.writeInt(flags);
        extras.writeInt((int) expiration);
        return MemcacheProtocol.flexibleRequest(alloc, MemcacheProtocol.Opcode.SET, datatype, partition(), opaque, noCas(), flexibleExtras, extras, key, content);
    } finally {
        ReferenceCountUtil.release(key);
        ReferenceCountUtil.release(extras);
        ReferenceCountUtil.release(flexibleExtras);
        ReferenceCountUtil.release(content);
    }
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) CompressionConfig(com.couchbase.client.core.env.CompressionConfig)

Example 2 with CompressionConfig

use of com.couchbase.client.core.env.CompressionConfig in project couchbase-jvm-clients by couchbase.

the class ReplaceRequest method encode.

@Override
public ByteBuf encode(ByteBufAllocator alloc, int opaque, KeyValueChannelContext ctx) {
    ByteBuf key = null;
    ByteBuf content = null;
    ByteBuf extras = null;
    ByteBuf flexibleExtras = mutationFlexibleExtras(this, ctx, alloc, syncReplicationType, preserveExpiry);
    try {
        key = encodedKeyWithCollection(alloc, ctx);
        byte datatype = 0;
        CompressionConfig config = ctx.compressionConfig();
        if (config != null && config.enabled() && this.content.length >= config.minSize()) {
            ByteBuf maybeCompressed = MemcacheProtocol.tryCompression(this.content, config.minRatio());
            if (maybeCompressed != null) {
                datatype |= MemcacheProtocol.Datatype.SNAPPY.datatype();
                content = maybeCompressed;
            } else {
                content = Unpooled.wrappedBuffer(this.content);
            }
        } else {
            content = Unpooled.wrappedBuffer(this.content);
        }
        extras = alloc.buffer(Integer.BYTES * 2);
        extras.writeInt(flags);
        extras.writeInt((int) expiration);
        return MemcacheProtocol.flexibleRequest(alloc, MemcacheProtocol.Opcode.REPLACE, datatype, partition(), opaque, cas, flexibleExtras, extras, key, content);
    } finally {
        ReferenceCountUtil.release(key);
        ReferenceCountUtil.release(extras);
        ReferenceCountUtil.release(flexibleExtras);
        ReferenceCountUtil.release(content);
    }
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) CompressionConfig(com.couchbase.client.core.env.CompressionConfig)

Example 3 with CompressionConfig

use of com.couchbase.client.core.env.CompressionConfig in project couchbase-jvm-clients by couchbase.

the class AppendRequest method encode.

@Override
public ByteBuf encode(ByteBufAllocator alloc, int opaque, KeyValueChannelContext ctx) {
    ByteBuf key = null;
    ByteBuf content = null;
    ByteBuf flexibleExtras = mutationFlexibleExtras(this, ctx, alloc, syncReplicationType);
    try {
        key = encodedKeyWithCollection(alloc, ctx);
        byte datatype = 0;
        CompressionConfig config = ctx.compressionConfig();
        if (config != null && config.enabled() && this.content.length >= config.minSize()) {
            ByteBuf maybeCompressed = MemcacheProtocol.tryCompression(this.content, config.minRatio());
            if (maybeCompressed != null) {
                datatype |= MemcacheProtocol.Datatype.SNAPPY.datatype();
                content = maybeCompressed;
            } else {
                content = Unpooled.wrappedBuffer(this.content);
            }
        } else {
            content = Unpooled.wrappedBuffer(this.content);
        }
        return MemcacheProtocol.flexibleRequest(alloc, MemcacheProtocol.Opcode.APPEND, datatype, partition(), opaque, cas, flexibleExtras, noExtras(), key, content);
    } finally {
        ReferenceCountUtil.release(key);
        ReferenceCountUtil.release(content);
        ReferenceCountUtil.release(flexibleExtras);
    }
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) CompressionConfig(com.couchbase.client.core.env.CompressionConfig)

Example 4 with CompressionConfig

use of com.couchbase.client.core.env.CompressionConfig in project couchbase-jvm-clients by couchbase.

the class InsertRequest method encode.

@Override
public ByteBuf encode(ByteBufAllocator alloc, int opaque, KeyValueChannelContext ctx) {
    ByteBuf key = null;
    ByteBuf content = null;
    ByteBuf extras = null;
    ByteBuf flexibleExtras = mutationFlexibleExtras(this, ctx, alloc, syncReplicationType);
    try {
        key = encodedKeyWithCollection(alloc, ctx);
        byte datatype = 0;
        CompressionConfig config = ctx.compressionConfig();
        if (config != null && config.enabled() && this.content.length >= config.minSize()) {
            ByteBuf maybeCompressed = MemcacheProtocol.tryCompression(this.content, config.minRatio());
            if (maybeCompressed != null) {
                datatype |= MemcacheProtocol.Datatype.SNAPPY.datatype();
                content = maybeCompressed;
            } else {
                content = Unpooled.wrappedBuffer(this.content);
            }
        } else {
            content = Unpooled.wrappedBuffer(this.content);
        }
        extras = alloc.buffer(Integer.BYTES * 2);
        extras.writeInt(flags);
        extras.writeInt((int) expiration);
        return MemcacheProtocol.flexibleRequest(alloc, MemcacheProtocol.Opcode.ADD, datatype, partition(), opaque, noCas(), flexibleExtras, extras, key, content);
    } finally {
        ReferenceCountUtil.release(key);
        ReferenceCountUtil.release(extras);
        ReferenceCountUtil.release(flexibleExtras);
        ReferenceCountUtil.release(content);
    }
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) CompressionConfig(com.couchbase.client.core.env.CompressionConfig)

Example 5 with CompressionConfig

use of com.couchbase.client.core.env.CompressionConfig in project couchbase-jvm-clients by couchbase.

the class PrependRequest method encode.

@Override
public ByteBuf encode(ByteBufAllocator alloc, int opaque, KeyValueChannelContext ctx) {
    ByteBuf key = null;
    ByteBuf content = null;
    ByteBuf flexibleExtras = mutationFlexibleExtras(this, ctx, alloc, syncReplicationType);
    try {
        key = encodedKeyWithCollection(alloc, ctx);
        byte datatype = 0;
        CompressionConfig config = ctx.compressionConfig();
        if (config != null && config.enabled() && this.content.length >= config.minSize()) {
            ByteBuf maybeCompressed = MemcacheProtocol.tryCompression(this.content, config.minRatio());
            if (maybeCompressed != null) {
                datatype |= MemcacheProtocol.Datatype.SNAPPY.datatype();
                content = maybeCompressed;
            } else {
                content = Unpooled.wrappedBuffer(this.content);
            }
        } else {
            content = Unpooled.wrappedBuffer(this.content);
        }
        return MemcacheProtocol.flexibleRequest(alloc, MemcacheProtocol.Opcode.PREPEND, datatype, partition(), opaque, cas, flexibleExtras, noExtras(), key, content);
    } finally {
        ReferenceCountUtil.release(key);
        ReferenceCountUtil.release(content);
        ReferenceCountUtil.release(flexibleExtras);
    }
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) CompressionConfig(com.couchbase.client.core.env.CompressionConfig)

Aggregations

ByteBuf (com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)5 CompressionConfig (com.couchbase.client.core.env.CompressionConfig)5