com.alachisoft.ncache.client.internal.command.GetCommand 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.
/*
* GetCommand.java
*
* Created on September 11, 2006, 5:06 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.client.internal.caching.CacheImpl;
import com.alachisoft.ncache.common.protobuf.CommandProtocol;
import com.alachisoft.ncache.common.protobuf.GetCommandProtocol;
import com.alachisoft.ncache.common.protobuf.LockInfoProtocol;
import com.alachisoft.ncache.runtime.exceptions.CommandException;
import com.alachisoft.ncache.runtime.util.TimeSpan;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
/**
* @author Administrator
* @version 1.0
*/
public final class GetCommand extends Command {
private final long _threadId;
private final int _methodOveload;
private String group;
private String subGroup;
private int flagMap;
private LockAccessType _accessType;
private String _lockId;
private TimeSpan _lockTimeout;
private long _version;
//+ Asad:20110330
private String providerName;
protected com.alachisoft.ncache.common.protobuf.GetCommandProtocol.GetCommand _commandInstance;
/**
* Creates a new instance of GetCommand
*
* @param key
* @param group
* @param subGroup
*/
public GetCommand(String key, BitSet flagMap, String group,
LockAccessType accessType, String lockId, TimeSpan lockTimeout, long version,
long threadId,int methodOverload)
{
super.name = "GetCommand";
this.key = key;
this.flagMap = BitSetConstants.getBitSetData(flagMap);
this.group = group;
this._accessType = accessType;
this._lockId = lockId;
this._lockTimeout = lockTimeout;
this._version = version;
this.providerName = providerName;
this._threadId = threadId;
this._methodOveload = methodOverload;
}
/**
* @return
*/
protected void createCommand() throws CommandException {
if (key == null) {
throw new NullPointerException("Key");
}
if (key.equals("")) {
throw new IllegalArgumentException("key");
}
long ticks = 0;
if (this._lockTimeout != CacheImpl.NoLockingExpiration) {
//ticks = (this._lockTimeout.getTime() - new Date().getTime()) * 10;
ticks = this._lockTimeout.getTotalTicks();
if (ticks < 0) {
ticks = 0;
}
}
GetCommandProtocol.GetCommand.Builder builder =
GetCommandProtocol.GetCommand.newBuilder();
builder = builder
.setKey(key)
.setFlag(this.flagMap)
.setVersion(this._version)
.setRequestId(super.getRequestId())
.setThreadId((int)_threadId)
;
LockInfoProtocol.LockInfo.Builder lockInfoBuilder =
LockInfoProtocol.LockInfo.newBuilder();
if (this._lockId != null) {
lockInfoBuilder = lockInfoBuilder.setLockId(this._lockId);
}
lockInfoBuilder = lockInfoBuilder.setLockAccessType(this._accessType.getValue()).setLockTimeout(ticks);
builder = builder.setLockInfo(lockInfoBuilder);
if (group != null) {
builder = builder.setGroup(group);
if (subGroup != null) {
builder = builder.setSubGroup(subGroup);
}
}
if (providerName != null) {
builder = builder.setProviderName(providerName);
}
_commandInstance =builder.build();
}
@Override
public CommandType getCommandType() {
return CommandType.GET;
}
@Override
public RequestType getCommandRequestType() {
return RequestType.AtomicRead;
}
@Override
protected void serializeCommandInternal(ByteArrayOutputStream stream) throws IOException
{
_commandInstance.writeTo(stream);
}
@Override
protected short getCommandHandle()
{
return (short)CommandProtocol.Command.Type.GET.getNumber();
}
}