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

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

There is a newer version: 5.3.0
Show newest version
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.alachisoft.ncache.client.internal.command;

import com.alachisoft.ncache.common.protobuf.CommandProtocol;
import com.alachisoft.ncache.common.protobuf.RemoveTopicCommandProtocol;
import com.alachisoft.ncache.runtime.exceptions.CommandException;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class RemoveTopicCommand extends Command {

    private final String topicName;
    private final boolean forcefully;
    protected com.alachisoft.ncache.common.protobuf.RemoveTopicCommandProtocol.RemoveTopicCommand _commandInstance;

    public RemoveTopicCommand(String topicName, boolean forcefully) {
        name = "RemoveTopicCommand";

        this.topicName = topicName;
        this.forcefully = forcefully;
    }

    @Override
    public CommandType getCommandType() {
        return CommandType.REMOVE_TOPIC;
    }

    @Override
    public RequestType getCommandRequestType() {
        return RequestType.AtomicRead;
    }

    @Override
    protected void createCommand() throws CommandException {
        RemoveTopicCommandProtocol.RemoveTopicCommand.Builder builder = RemoveTopicCommandProtocol.RemoveTopicCommand.newBuilder();

        builder.setRequestId(getRequestId())
                .setTopicName(topicName)
                .setForcefully(forcefully);


        if(this.getIntendedRecipient()!=null)
            builder.setIntendedRecipient(getIntendedRecipient());
        _commandInstance =builder
                .setClientLastViewId(getClientLastViewId())
                .setCommandVersion(1)
                .setVersion(VERSION)
                .build();
    }

    @Override
    protected  void serializeCommandInternal(ByteArrayOutputStream stream) throws IOException
    {
        _commandInstance.writeTo(stream);
    }
    @Override
    protected short getCommandHandle()
    {
        return (short)CommandProtocol.Command.Type.REMOVE_TOPIC.getNumber();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy