Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the function of CommandExecutor in dubbo

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "what is the role of CommandExecutor in dubbo". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Order

This paper mainly studies the CommandExecutor of 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 defines the execute method, which passes in the CommandContext parameter

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 defines commandName, args, remote, isHttp, originRequest parameters

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

DefaultCommandExecutor implements the CommandExecutor interface, and its execute method loads the corresponding comamnd through ExtensionLoader according to commandName, and then executes the execute method of command

Summary

CommandExecutor defines the execute method, which passes in CommandContext parameters; CommandContext defines commandName, args, remote, isHttp, originRequest parameters; DefaultCommandExecutor implements the CommandExecutor interface, and its execute method loads the corresponding comamnd through ExtensionLoader according to commandName, and then executes the execute method of command

This is the end of the content of "what is the role of CommandExecutor in dubbo". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report