dubbo中CommandExecutor的作用是什么

发布时间:2021-07-05 17:45:53 作者:chen
来源:亿速云 阅读:301

本篇内容介绍了“dubbo中CommandExecutor的作用是什么”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

本文主要研究一下dubbo的CommandExecutor

CommandExecutor

dubbo-2.7.2/dubbo-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;
}

CommandContext

dubbo-2.7.2/dubbo-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;
    }
}

DefaultCommandExecutor

dubbo-2.7.2/dubbo-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());
    }
}

小结

CommandExecutor定义了execute方法,其方法传入CommandContext参数;CommandContext定义了commandName、args、remote、isHttp、originRequest参数;DefaultCommandExecutor实现了CommandExecutor接口,其execute方法会根据commandName通过ExtensionLoader来加载对应的comamnd,然后执行command的execute方法

“dubbo中CommandExecutor的作用是什么”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

推荐阅读:
  1. dubbo中ServiceBeanExportedEvent的作用是什么
  2. dubbo中ForkingClusterInvoker的作用是什么

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

dubbo

上一篇:Python中怎么实现一个透视表

下一篇:Kafka有哪些常用命令

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》