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

com.alachisoft.ncache.client.internal.command.UnSubscribeTopicCommand 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 Alachisoft.NCache.Common.Enum.SubscriptionType;
import com.alachisoft.ncache.common.protobuf.CommandProtocol;
import com.alachisoft.ncache.common.protobuf.UnSubscribeTopicCommandProtocol;
import com.alachisoft.ncache.runtime.caching.SubscriptionPolicyType;
import com.alachisoft.ncache.runtime.exceptions.CommandException;

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

/**
 * @author latif_saif
 */
public class UnSubscribeTopicCommand extends Command {

    private final String topicName;
    private final String recepientId;
    private final SubscriptionType type;
    private final SubscriptionPolicyType subscriptionPolicyType;
    private final boolean isDispose;
    protected com.alachisoft.ncache.common.protobuf.UnSubscribeTopicCommandProtocol.UnSubscribeTopicCommand _commandInstance;

    public UnSubscribeTopicCommand(String topicName, String recepientId, SubscriptionType pubSubType,SubscriptionPolicyType policyType,boolean isDispose) {
        name = "UnSubscribeTopicCommand";
        this.topicName = topicName;
        this.recepientId = recepientId;
        this.type = pubSubType;
        this.subscriptionPolicyType=policyType;
        this.isDispose=isDispose;
    }

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

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

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

        builder.setTopicName(topicName)
                .setRecepientId(recepientId)
                .setPubSubType(type.getValue())
                .setIsDispose(isDispose)
                .setSubscriptionPolicy(subscriptionPolicyType.getValue());

        CommandProtocol.Command.Builder commandBuilder = CommandProtocol.Command.newBuilder();
        if(this.getIntendedRecipient()!=null)
            builder.setIntendedRecipient(getIntendedRecipient());
        _commandInstance =builder.setRequestId(this.getRequestId())
                .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.UNSUBSCRIBE_TOPIC.getNumber();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy