com.alachisoft.ncache.client.internal.command.DeleteCommand Maven / Gradle / Ivy
/*
* 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.DeleteCommandProtocol;
import com.alachisoft.ncache.runtime.exceptions.CommandException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.io.ByteArrayOutputStream;
/**
* @author Administrator
* @version 1.0
*/
public final class DeleteCommand extends Command {
private int _methodOverload;
private int flagMap;
private int dsItemRemoveCallbackId;
private String _lockId;
private LockAccessType _accessType;
private long _version;
protected com.alachisoft.ncache.common.protobuf.DeleteCommandProtocol.DeleteCommand _commandInstance;
//+ Asad:20110330
private String providerName;
//- Asad:20110330
/**
* Creates a new instance of RemoveCommand
*
* @param key
* @param isAsync
*/
public DeleteCommand(String key, BitSet flagMap,short itemRemoved,boolean isAsync, short onDsItemRemoved, String lockId, long version, LockAccessType accessType, String providerName , int methodOverload)
{
super.name = "DeleteCommand";
super.asyncCallbackSpecified = isAsync && itemRemoved != -1;
this.key = key;
this.flagMap = BitSetConstants.getBitSetData(flagMap);
super.asyncCallbackId = itemRemoved;
this.isAsync = isAsync;
this.dsItemRemoveCallbackId = onDsItemRemoved;
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");
DeleteCommandProtocol.DeleteCommand.Builder builder
= DeleteCommandProtocol.DeleteCommand.newBuilder();
builder = builder.setKey(key)
.setIsAsync(isAsync)
//.Net has super.getRequestId();
.setFlag(flagMap)
.setDatasourceItemRemovedCallbackId(dsItemRemoveCallbackId)
.setLockAccessType(this._accessType.getValue())
.setVersion(this._version)
.setRequestId(this.getRequestId())
.setMethodOverload(_methodOverload);
if (providerName != null) {
builder = builder.setProviderName(this.providerName);
}
if (this._lockId != null) {
builder = builder.setLockId(this._lockId);
}
_commandInstance =builder.build();
}
@Override
public CommandType getCommandType() {
return CommandType.DELETE;
}
@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.DELETE.getNumber();
}
}