com.alachisoft.ncache.client.internal.command.SubscribeTopicCommand Maven / Gradle / Ivy
/*
* 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.SubscribeTopicCommandProtocol;
import com.alachisoft.ncache.runtime.caching.SubscriptionPolicyType;
import com.alachisoft.ncache.runtime.exceptions.CommandException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class SubscribeTopicCommand extends Command {
private final String topicName;
private final SubscriptionType pubsubtype;
private final String subscriptionName;
private final SubscriptionPolicyType subscriptionPolicyType;
private final long creationTime;
private final long expirationTime;
protected com.alachisoft.ncache.common.protobuf.SubscribeTopicCommandProtocol.SubscribeTopicCommand _commandInstance;
public SubscribeTopicCommand(String topicName, String subscriptionName, SubscriptionType pubsubType, long creationTime, long expiration, SubscriptionPolicyType subscriptionPolicyType) {
name = "SubscribeTopicCommand";
this.topicName = topicName;
this.subscriptionName=subscriptionName;
this.pubsubtype = pubsubType;
this.subscriptionPolicyType =subscriptionPolicyType;
this.creationTime=creationTime;
this.expirationTime=expiration;
}
@Override
public CommandType getCommandType() {
return CommandType.SUBCRIBE;
}
@Override
public RequestType getCommandRequestType() {
return RequestType.AtomicRead;
}
@Override
protected void createCommand() throws CommandException {
SubscribeTopicCommandProtocol.SubscribeTopicCommand.Builder builder = SubscribeTopicCommandProtocol.SubscribeTopicCommand.newBuilder();
builder.setRequestId(getRequestId())
.setTopicName(topicName)
.setPubSubType(pubsubtype.getValue())
.setExpirationTime(expirationTime)
.setSubscriptionName(subscriptionName)
.setSubscriptionPolicy(subscriptionPolicyType.getValue())
.setCreationTime(creationTime);
CommandProtocol.Command.Builder commandBuilder = CommandProtocol.Command.newBuilder();
if(this.getIntendedRecipient() != null){
builder.setIntendedRecipient(this.getIntendedRecipient());
}
_commandInstance =builder
.setClientLastViewId(getClientLastViewId())
.setVersion(VERSION)
.build();
}
@Override
protected void serializeCommandInternal(ByteArrayOutputStream stream) throws IOException
{
_commandInstance.writeTo(stream);
}
@Override
protected short getCommandHandle()
{
return (short)CommandProtocol.Command.Type.SUBSCRIBE_TOPIC.getNumber();
}
}