com.alachisoft.ncache.client.internal.command.AddAttributeCommand 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.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.alachisoft.ncache.client.internal.command;
import Alachisoft.NCache.Common.Util.DependencyHelper;
import com.alachisoft.ncache.client.internal.caching.CacheImpl;
import com.alachisoft.ncache.common.protobuf.AddAttributeProtocol;
import com.alachisoft.ncache.common.protobuf.CommandProtocol;
import com.alachisoft.ncache.common.protobuf.DependencyProtocol;
import com.alachisoft.ncache.runtime.dependencies.CacheDependency;
import com.alachisoft.ncache.runtime.exceptions.CommandException;
import com.alachisoft.ncache.runtime.util.HelperFxn;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Date;
public class AddAttributeCommand extends Command {
protected Date _date;
protected DependencyProtocol.Dependency _dependency;
protected AddAttributeProtocol.AddAttributeCommand _commandInstance;
protected AddAttributeProtocol.AddAttributeCommand.Builder build;
public AddAttributeCommand(String key, Date date, DependencyProtocol.Dependency dependency) throws Exception {
this.name = "AddAttributeCommand";
this.key = key;
this._date = date;
_dependency = dependency;
buildCommand();
}
private void buildCommand() {
if (key == null || key.isEmpty()) {
throw new IllegalArgumentException("Value cannot be null or empty."+System.lineSeparator()+"Paramenter name: key");
}
build = AddAttributeProtocol.AddAttributeCommand.newBuilder();
build.setKey(key);
if (_date != CacheImpl.NoAbsoluteExpiration) {
build.setAbsExpiration(HelperFxn.getUTCTicks(_date));
}
}
@Override
public CommandType getCommandType() {
return CommandType.ADD_ATTRIBUTE;
}
@Override
public RequestType getCommandRequestType() {
return RequestType.AtomicWrite;
}
@Override
protected void createCommand() throws CommandException {
build.setRequestId(getRequestId());
_commandInstance =build.build();
}
@Override
protected void serializeCommandInternal(ByteArrayOutputStream stream) throws IOException
{
_commandInstance.writeTo(stream);
}
@Override
protected short getCommandHandle()
{
return (short)CommandProtocol.Command.Type.ADD_ATTRIBUTE.getNumber();
}
}