All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.hotrod.impl.multimap.operations.AbstractMultimapKeyValueOperation Maven / Gradle / Ivy

There is a newer version: 14.0.32.Final
Show newest version
package org.infinispan.hotrod.impl.multimap.operations;

import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import org.infinispan.api.common.CacheEntryExpiration;
import org.infinispan.api.common.CacheOptions;
import org.infinispan.api.common.CacheWriteOptions;
import org.infinispan.hotrod.impl.DataFormat;
import org.infinispan.hotrod.impl.operations.AbstractKeyValueOperation;
import org.infinispan.hotrod.impl.operations.OperationContext;
import org.infinispan.hotrod.impl.protocol.Codec;
import org.infinispan.hotrod.impl.transport.netty.ByteBufUtil;

public abstract class AbstractMultimapKeyValueOperation extends AbstractKeyValueOperation {

    protected final boolean supportsDuplicates;

    protected AbstractMultimapKeyValueOperation(OperationContext operationContext, short requestCode, short responseCode, K key, byte[] keyBytes,
                                                byte[] value,
                                                CacheOptions options,
                                                DataFormat dataFormat, boolean supportsDuplicates) {
        super(operationContext, requestCode, responseCode, key, keyBytes, value, options, dataFormat);
        this.supportsDuplicates = supportsDuplicates;
    }

    @Override
    protected void executeOperation(Channel channel) {
        scheduleRead(channel);
        sendKeyValueOperation(channel);
    }

    protected void sendKeyValueOperation(Channel channel) {
        Codec codec = operationContext.getCodec();
        CacheEntryExpiration.Impl expiration = (CacheEntryExpiration.Impl) ((CacheWriteOptions) options).expiration();
        ByteBuf buf = channel.alloc().buffer(codec.estimateHeaderSize(header) + keyBytes.length +
                codec.estimateExpirationSize(expiration) + value.length + codec.estimateSizeMultimapSupportsDuplicated());
        codec.writeHeader(buf, header);
        ByteBufUtil.writeArray(buf, keyBytes);
        codec.writeExpirationParams(buf, expiration);
        ByteBufUtil.writeArray(buf, value);
        codec.writeMultimapSupportDuplicates(buf, supportsDuplicates);
        channel.writeAndFlush(buf);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy