com.alachisoft.ncache.client.internal.command.BulkGetCommand Maven / Gradle / Ivy
/*
* 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.BulkGetCommandProtocol;
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.Arrays;
/**
* @author Administrator
*/
public final class BulkGetCommand extends Command {
private final int _methodOverload;
private String[] keys;
private BitSet flagMap;
private String providerName;
protected com.alachisoft.ncache.common.protobuf.BulkGetCommandProtocol.BulkGetCommand _commandInstance;
/**
* Creates a new instance of BulkGetCommand
*/
public BulkGetCommand(String[] keys, BitSet flagMap, int methodOverload) {
super.name = "BulkGetCommand";
this.keys = keys;
this.flagMap = flagMap;
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");
}
BulkGetCommandProtocol.BulkGetCommand.Builder builder = BulkGetCommandProtocol.BulkGetCommand.newBuilder();
builder = builder.addAllKeys(Arrays.asList(keys))
.setRequestId(super.getRequestId())
.setFlag(BitSetConstants.getBitSetData(this.flagMap));
if (providerName != null) builder = builder.setProviderName(providerName);
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;
}
@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.getNumber();
}
}