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

com.alachisoft.ncache.client.internal.command.BulkGetCacheItemCommand Maven / Gradle / Ivy

package com.alachisoft.ncache.client.internal.command;

import Alachisoft.NCache.Common.BitSet;
import Alachisoft.NCache.Common.BitSetConstants;
import com.alachisoft.ncache.common.protobuf.BulkGetCacheItemCommandProtocol;
import com.alachisoft.ncache.common.protobuf.BulkGetCommandProtocol;
import com.alachisoft.ncache.common.protobuf.CommandProtocol;
import com.alachisoft.ncache.runtime.caching.ReadMode;
import com.alachisoft.ncache.runtime.caching.ReadThruOptions;
import com.alachisoft.ncache.runtime.exceptions.CommandException;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;


/**
 * @author Administrator
 */
public final class BulkGetCacheItemCommand extends Command {

    private ReadMode readMode;
    private  int _methodOverload;
    private String[] keys;
    private BitSet flagMap;
    private String providerName;
    protected com.alachisoft.ncache.common.protobuf.BulkGetCacheItemCommandProtocol.BulkGetCacheItemCommand _commandInstance;
    /**
     * Creates a new instance of BulkGetCommand
     */
    public BulkGetCacheItemCommand(String[] keys, BitSet flagMap, ReadThruOptions readThruOptions , int methodOverload) {
        super.name = "BulkGetCacheItemCommand";
        this.keys = keys;
        this.flagMap = flagMap;
        this.providerName = readThruOptions.getProviderName();
        this.readMode = readThruOptions.getReadMode();
        this._methodOverload = methodOverload;

        super.setBulkKeys(keys);
    }

    protected void createCommand() throws CommandException {
        if (keys == null) {
            throw new NullPointerException("keys");
        }
        if (keys.length == 0) {
            throw new IllegalArgumentException(
                    "There is no key present in keys array");
        }

        BulkGetCacheItemCommandProtocol.BulkGetCacheItemCommand.Builder builder =  BulkGetCacheItemCommandProtocol.BulkGetCacheItemCommand.newBuilder();

        builder.addAllKeys(Arrays.asList(keys))
                .setRequestId(super.getRequestId())
                .setFlag(BitSetConstants.getBitSetData(this.flagMap));

        if (providerName != null) builder.setProviderName(providerName);
        if (readMode != null) {
            builder.setReadMode(readMode.getValue());
        }
        if(this.getIntendedRecipient() != null){
            builder.setIntendedRecipient(this.getIntendedRecipient());
        }
        _commandInstance =builder
                .setClientLastViewId(this.getClientLastViewId())
                .setCommandVersion(1)
                .setMethodOverload(_methodOverload)
                .build();

    }


    public CommandType getCommandType() {
        return CommandType.GET_BULK_CACHEITEM;
    }

    @Override
    public RequestType getCommandRequestType() {
        return RequestType.KeyBulkRead;
    }

    @Override
    protected  void serializeCommandInternal(ByteArrayOutputStream stream) throws IOException
    {
        _commandInstance.writeTo(stream);
    }
    @Override
    protected short getCommandHandle()
    {
        return (short)CommandProtocol.Command.Type.GET_BULK_CACHEITEM.getNumber();
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy