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

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

There is a newer version: 5.3.0
Show newest version
/*
 * RemoveCommand.java
 *
 * Created on September 11, 2006, 5:37 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 Alachisoft.NCache.Common.Locking.LockAccessType;
import com.alachisoft.ncache.common.protobuf.CommandProtocol;
import com.alachisoft.ncache.common.protobuf.RemoveCommandProtocol;
import com.alachisoft.ncache.runtime.exceptions.CommandException;

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

/**
 * @author Administrator
 * @version 1.0
 */
public final class RemoveCommand extends Command {

    private int _methodOverload= 0;
    private int flagMap;
    private int dsItemRemoveCallbackId;
    private String _lockId;
    private LockAccessType _accessType;
    private long _version;
    //+ Asad:20110330
    private String providerName;
    //- Asad:20110330
    protected com.alachisoft.ncache.common.protobuf.RemoveCommandProtocol.RemoveCommand _commandInstance;

    /**
     * Creates a new instance of RemoveCommand
     *
     * @param key
     * @param isAsync
     */
    public RemoveCommand(String key, BitSet flagMap, short itemRemoved , boolean isAsync , int dsItemRemoveCallbackId ,String lockId , long version, LockAccessType accessType, String providerName, int methodOverload)
    {
        super.name = "RemoveCommand";
        super.asyncCallbackSpecified = this.isAsync && itemRemoved != -1;

        this.key = key;
        this.flagMap = BitSetConstants.getBitSetData(flagMap);
        super.asyncCallbackId = itemRemoved;
        this.isAsync = isAsync;
        this.dsItemRemoveCallbackId = dsItemRemoveCallbackId;
        this._lockId = lockId;
        this._version = version;
        this._accessType = accessType;
        this.providerName = providerName;
        this._methodOverload = methodOverload;
    }

    protected void createCommand() throws CommandException {
        if (key == null)
            throw new IllegalArgumentException("Value cannot be null."+System.lineSeparator()+"Parameter name: key");
        if (key.equals(""))
            throw new IllegalArgumentException("Value cannot be empty.\nParameter name: key");

        RemoveCommandProtocol.RemoveCommand.Builder builder
                = RemoveCommandProtocol.RemoveCommand.newBuilder();

        builder = builder.setKey(key)
                .setIsAsync(isAsync)
                .setFlag(flagMap)
                .setDatasourceItemRemovedCallbackId(dsItemRemoveCallbackId)
                .setLockAccessType(this._accessType.getValue())
                .setVersion(this._version)
                .setRequestId(this.getRequestId());


        if (providerName != null) {
            builder = builder.setProviderName(this.providerName);
        }
        if (this._lockId != null) {
            builder = builder.setLockId(this._lockId);
        }

        _commandInstance =builder
                .setCommandID(getCommandID())
                .setMethodOverload(_methodOverload)
                .build();

    }

    /**
     * @return
     */

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

    public int AsycItemRemovedOpComplete() {
        return super.asyncCallbackId;
    }

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy