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

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

There is a newer version: 5.3.0
Show newest version
/*
 * BulkGetCommand.java
 *
 * Created on September 19, 2006, 6:55 PM
 *
 * Copyright 2005 Alachisoft, Inc. All rights reserved.
 * ALACHISOFT PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

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

import Alachisoft.NCache.Common.BitSet;
import Alachisoft.NCache.Common.BitSetConstants;
import com.alachisoft.ncache.common.protobuf.BulkDeleteCommandProtocol;
import com.alachisoft.ncache.common.protobuf.CommandProtocol;
import com.alachisoft.ncache.runtime.exceptions.CommandException;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;


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

    private final int _methodOverload;
    private String[] keys;
    private BitSet flagMap;
    private int onDsItemsRemovedId;
    protected com.alachisoft.ncache.common.protobuf.BulkDeleteCommandProtocol.BulkDeleteCommand _commandInstance;

    //+ Asad:20110330
    private String providerName;
    //- Asad:20110330

    /**
     * Creates a new instance of BulkGetCommand
     */
    public BulkDeleteCommand(String[] keys, BitSet flagMap, String providerName, short onDsItemRemovedId , int methodOverload) {
        super.name = "BulkDeleteCommand";
        this.keys = keys;
        this.flagMap = flagMap;
        this.providerName = providerName;
        this.onDsItemsRemovedId = onDsItemRemovedId;
        this._methodOverload = methodOverload;

        super.setBulkKeys(keys);
    }

    protected void createCommand() throws CommandException {
        if (keys == null)
            throw new NullPointerException("Value cannot be null.\nParameter name: keys");
        if (keys.length == 0)
            throw new IllegalArgumentException(
                    "There is no key present in keys array");

        BulkDeleteCommandProtocol.BulkDeleteCommand.Builder builder =
                BulkDeleteCommandProtocol.BulkDeleteCommand.newBuilder();

        ArrayList list = new ArrayList();

        for (int i = 0; i < keys.length; i++) {
            if (keys[i] != null)
                list.add(keys[i]);

        }


        builder = builder.addAllKeys(list)
                .setDatasourceItemRemovedCallbackId(onDsItemsRemovedId)
                .setRequestId(super.getRequestId())
                .setFlag(BitSetConstants.getBitSetData(this.flagMap));


        if (providerName != null) builder = builder.setProviderName(providerName);

        if(this.getIntendedRecipient() != null){
            builder.setIntendedRecipient(this.getIntendedRecipient());
        }
        builder.setRequestId(super.getRequestId())
                .setClientLastViewId(this.getClientLastViewId())
                .setMethodOverload(_methodOverload);
        _commandInstance =builder.build();

    }

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

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy