com.alachisoft.ncache.client.internal.command.GetTopicCommand 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 Alachisoft.NCache.Common.Enum.TopicOperationType;
import com.alachisoft.ncache.common.protobuf.CommandProtocol;
import com.alachisoft.ncache.common.protobuf.GetTopicCommandProtocol;
import com.alachisoft.ncache.runtime.exceptions.CommandException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class GetTopicCommand extends Command {
private final String topicName;
private final TopicOperationType type;
protected com.alachisoft.ncache.common.protobuf.GetTopicCommandProtocol.GetTopicCommand _commandInstance;
public GetTopicCommand(String topicName, TopicOperationType type) {
name = "GetTopicCommand";
this.topicName = topicName;
this.type = type;
}
@Override
public CommandType getCommandType() {
return CommandType.GET_TOPIC;
}
@Override
public RequestType getCommandRequestType() {
return RequestType.AtomicRead;
}
@Override
protected void createCommand() throws CommandException {
GetTopicCommandProtocol.GetTopicCommand.Builder builder = GetTopicCommandProtocol.GetTopicCommand.newBuilder();
builder.setRequestId(getRequestId())
.setTopicName(topicName)
.setType(type.getValue())
;
CommandProtocol.Command.Builder commandBuilder = CommandProtocol.Command.newBuilder();
if(this.getIntendedRecipient() != null){
builder.setIntendedRecipient(this.getIntendedRecipient());
}
_commandInstance =builder
.setClientLastViewId(getClientLastViewId())
.setVersion(VERSION)
.setCommandVersion(1)
.build();
}
@Override
protected void serializeCommandInternal(ByteArrayOutputStream stream) throws IOException
{
_commandInstance.writeTo(stream);
}
@Override
protected short getCommandHandle()
{
return (short)CommandProtocol.Command.Type.GET_TOPIC.getNumber();
}
}