All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alachisoft.ncache.client.internal.command.GetTopicCommand Maven / Gradle / Ivy

There is a newer version: 5.3.0
Show newest version
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();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy