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

com.alachisoft.ncache.client.internal.command.MesasgeAcknowledgmentCommand 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.KeyValueProtocol;
import com.alachisoft.ncache.common.protobuf.MesasgeAcknowledgmentCommandProtocol;
import com.alachisoft.ncache.common.protobuf.ValueWithTypeProtocol;
import com.alachisoft.ncache.runtime.exceptions.CommandException;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map.Entry;

public class MesasgeAcknowledgmentCommand extends Command {

    private final java.util.Map> topicWiseMessageIds;
    protected com.alachisoft.ncache.common.protobuf.MesasgeAcknowledgmentCommandProtocol.MesasgeAcknowledgmentCommand _commandInstance;

    public MesasgeAcknowledgmentCommand(java.util.Map> topicWiseMessageIds) {
        name = "MesasgeAcknowledgmentCommand";
        this.topicWiseMessageIds = topicWiseMessageIds;
    }

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

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

    @Override
    protected void createCommand() throws CommandException {


        MesasgeAcknowledgmentCommandProtocol.MesasgeAcknowledgmentCommand.Builder messageAckCommand = MesasgeAcknowledgmentCommandProtocol.MesasgeAcknowledgmentCommand.newBuilder();
        messageAckCommand.setRequestId(getRequestId());


        for (Entry> dataValue : topicWiseMessageIds.entrySet()) {
            KeyValueProtocol.KeyValue.Builder keyValPair = KeyValueProtocol.KeyValue.newBuilder();
            keyValPair = keyValPair.setKey(dataValue.getKey());
            for (String value : dataValue.getValue()) {
                keyValPair = keyValPair.addValue(
                        ValueWithTypeProtocol.ValueWithType.newBuilder()
                                .setValue(value)
                                .build());
            }
            messageAckCommand.addValues(keyValPair.build());
        }

        CommandProtocol.Command.Builder commandBuilder = CommandProtocol.Command.newBuilder();
        if(this.getIntendedRecipient() != null){
            messageAckCommand.setIntendedRecipient(this.getIntendedRecipient());
        }
        _commandInstance =messageAckCommand
                .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.MESSAGE_ACKNOWLEDGMENT.getNumber();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy