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

com.alachisoft.ncache.client.internal.command.SurrogateCommand 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.Net.Address;
import com.alachisoft.ncache.common.protobuf.CommandProtocol;
import com.alachisoft.ncache.common.protobuf.SurrogateCommandProtocol;
import com.alachisoft.ncache.runtime.exceptions.CommandException;
import com.google.protobuf.ByteString;

import java.io.IOException;

public class SurrogateCommand extends Command {
    private Address actualTargetNode;
    private Command wrappedCommand;
    private boolean requestInquireEnable;

    public SurrogateCommand(Command command, Address actualNode, boolean requestInquireEnable) {
        setWrappedCommand(command);
        setActualTargetNode(actualNode);
        this.requestInquireEnable = requestInquireEnable;
    }

    public Command getWrappedCommand() {
        return wrappedCommand;
    }

    public void setWrappedCommand(Command wrappedCommand) {
        this.wrappedCommand = wrappedCommand;
    }

    public Address getActualTargetNode() {
        return actualTargetNode;
    }

    public void setActualTargetNode(Address actualTargetNode) {
        this.actualTargetNode = actualTargetNode;
    }

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

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

    @Override
    protected void createCommand() throws CommandException {


        SurrogateCommandProtocol.SurrogateCommand.Builder builder = SurrogateCommandProtocol.SurrogateCommand.newBuilder();
        builder.setRequestId(getRequestId()).setTargetServer(getActualTargetNode().toString())
                .setRequestId(getWrappedCommand().getRequestId());

        CommandProtocol.Command.Builder commandBuilder = CommandProtocol.Command.newBuilder();

        commandBuilder = commandBuilder.setSurrogateCommand(builder.build())
                .setRequestID(getWrappedCommand().getRequestId())
                .setType(CommandProtocol.Command.Type.SURROGATE);
        super._command = commandBuilder.build();

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy