com.alachisoft.ncache.client.internal.command.BulkRemoveCommand Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ncache-professional-client Show documentation
Show all versions of ncache-professional-client Show documentation
NCache Professional client for java.
/*
* 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.BulkRemoveCommandProtocol;
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 BulkRemoveCommand extends Command {
private final int _methodOverload;
private String[] keys;
private BitSet flagMap;
private int onDsItemsRemovedId;
private String providerName;
protected com.alachisoft.ncache.common.protobuf.BulkRemoveCommandProtocol.BulkRemoveCommand _commandInstance;
/**
* Creates a new instance of BulkGetCommand
*/
public BulkRemoveCommand(String[] keys, BitSet flagMap, String providerName, short onDsItemRemovedId , int methodOverLoad) {
super.name = "BulkRemoveCommand";
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("keys");
if (keys.length == 0)
throw new IllegalArgumentException(
"There is no key present in keys array");
BulkRemoveCommandProtocol.BulkRemoveCommand.Builder builder =
BulkRemoveCommandProtocol.BulkRemoveCommand.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.setClientLastViewId(this.getClientLastViewId())
.setCommandVersion(1)
.setMethodOverload(_methodOverload);
_commandInstance =builder.build();
}
@Override
public boolean getIsSafe() {
return false;
}
@Override
public CommandType getCommandType() {
return CommandType.REMOVE_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.REMOVE_BULK.getNumber();
}
}