sequence

This article focuses on Dubbo’s CommandExecutor

CommandExecutor

Dubbo – 2.7.2 / dubbo – the plugin/dubbo – qos/SRC/main/Java/org/apache/dubbo/qos/command/CommandExecutor. Java

public interface CommandExecutor {
    /**
     * Execute one command and return the execution result
     *
     * @param commandContext command context
     * @return command execution result
     * @throws NoSuchCommandException
     */
    String execute(CommandContext commandContext) throws NoSuchCommandException;
}
Copy the code
  • CommandExecutor defines the execute method, which passes in the CommandContext parameter

CommandContext

Dubbo – 2.7.2 / dubbo – the plugin/dubbo – qos/SRC/main/Java/org/apache/dubbo/qos/command/CommandContext. Java

public class CommandContext {

    private String commandName;
    private String[] args;
    private Channel remote;
    private boolean isHttp;
    private Object originRequest;

    public CommandContext(String commandName) {
        this.commandName = commandName;
    }

    public CommandContext(String commandName, String[] args, boolean isHttp) {
        this.commandName = commandName;
        this.args = args;
        this.isHttp = isHttp;
    }

    public String getCommandName() {
        return commandName;
    }

    public void setCommandName(String commandName) {
        this.commandName = commandName;
    }

    public String[] getArgs() {
        return args;
    }

    public void setArgs(String[] args) {
        this.args = args;
    }

    public Channel getRemote() {
        return remote;
    }

    public void setRemote(Channel remote) {
        this.remote = remote;
    }

    public boolean isHttp() {
        return isHttp;
    }

    public void setHttp(boolean http) {
        isHttp = http;
    }

    public Object getOriginRequest() {
        return originRequest;
    }

    public void setOriginRequest(Object originRequest) { this.originRequest = originRequest; }}Copy the code
  • CommandContext defines commandName, args, remote, isHttp, and originRequest parameters

DefaultCommandExecutor

Dubbo – 2.7.2 / dubbo – the plugin/dubbo – qos/SRC/main/Java/org/apache/dubbo/qos/command/DefaultCommandExecutor. Java

public class DefaultCommandExecutor implements CommandExecutor {
    @Override
    public String execute(CommandContext commandContext) throws NoSuchCommandException {
        BaseCommand command = null;
        try {
            command = ExtensionLoader.getExtensionLoader(BaseCommand.class).getExtension(commandContext.getCommandName());
        } catch (Throwable throwable) {
                //can't find command } if (command == null) { throw new NoSuchCommandException(commandContext.getCommandName()); } return command.execute(commandContext, commandContext.getArgs()); }}Copy the code
  • DefaultCommandExecutor implements the CommandExecutor interface, whose execute method loads the corresponding COMamnd through the ExtensionLoader based on commandName, and then executes the Execute method of command

summary

CommandExecutor defines the execute method, which takes in the CommandContext parameter; CommandContext defines commandName, args, remote, isHttp, and originRequest parameters. DefaultCommandExecutor implements the CommandExecutor interface, whose execute method loads the corresponding COMamnd through the ExtensionLoader based on commandName, and then executes the Execute method of command

doc

  • CommandExecutor