您好,登錄后才能下訂單哦!
本篇內容介紹了“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的作用是什么”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。