com.alachisoft.ncache.client.internal.command.LockCommand 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.
package com.alachisoft.ncache.client.internal.command;
import com.alachisoft.ncache.client.internal.caching.CacheImpl;
import com.alachisoft.ncache.common.protobuf.CommandProtocol;
import com.alachisoft.ncache.common.protobuf.LockCommandProtocol;
import com.alachisoft.ncache.runtime.exceptions.CommandException;
import com.alachisoft.ncache.runtime.util.TimeSpan;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
/**
* @author Administrator
*/
public class LockCommand extends Command {
private final long _threadId;
private TimeSpan _lockTimeout;
private int _methodOverload = 0;
protected com.alachisoft.ncache.common.protobuf.LockCommandProtocol.LockCommand _commandInstance;
public LockCommand(String key, TimeSpan lockTimeout , long threadId , int methodOverload) {
super.name = "LockCommand";
super.key = key;
this._lockTimeout = lockTimeout;
this._threadId = threadId;
this._methodOverload = methodOverload;
}
@Override
protected void createCommand() throws CommandException {
long ticks = 0;
if (this._lockTimeout != CacheImpl.NoLockingExpiration) {
//ticks = super.ticks(this._lockDate) - super.ticks(new Date());
ticks = this._lockTimeout.getTotalTicks();
}
LockCommandProtocol.LockCommand.Builder builder =
LockCommandProtocol.LockCommand.newBuilder();
builder = builder.setRequestId(this.getRequestId())
.setKey(key)
.setLockTimeout(ticks)
.setThreadId(Math.toIntExact(_threadId));
_commandInstance =builder
.setMethodOverload(_methodOverload)
.build();
}
public CommandType getCommandType() {
return CommandType.LOCK;
}
@Override
public RequestType getCommandRequestType() {
return RequestType.AtomicWrite;
}
@Override
public boolean getIsSafe()
{
return false;
}
@Override
protected void serializeCommandInternal(ByteArrayOutputStream stream) throws IOException
{
_commandInstance.writeTo(stream);
}
@Override
protected short getCommandHandle()
{
return (short)CommandProtocol.Command.Type.LOCK.getNumber();
}
}