重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
本篇内容介绍了“dubbo中CommandExecutor的作用是什么”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
公司主营业务:成都网站设计、做网站、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联建站是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联建站推出双江免费做网站回馈大家。
本文主要研究一下dubbo的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; }
CommandExecutor定义了execute方法,其方法传入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; } }
CommandContext定义了commandName、args、remote、isHttp、originRequest参数
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()); } }
DefaultCommandExecutor实现了CommandExecutor接口,其execute方法会根据commandName通过ExtensionLoader来加载对应的comamnd,然后执行command的execute方法
CommandExecutor定义了execute方法,其方法传入CommandContext参数;CommandContext定义了commandName、args、remote、isHttp、originRequest参数;DefaultCommandExecutor实现了CommandExecutor接口,其execute方法会根据commandName通过ExtensionLoader来加载对应的comamnd,然后执行command的execute方法
“dubbo中CommandExecutor的作用是什么”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!