Management implementation of Dubbo source code Analysis 6-telnet mode

Source: Internet
Author: User
Tags url example

Dubbo Source Analysis 1-reference Bean Creation Dubbo Source code Analysis 2-reference Bean initiating service method call Dubbo Source analysis 3-service Bean creation and publication Dubbo Source Analysis 4-Netty-based Dubbo protocol Server Dubbo Source Analysis 5-dubbo Extension point mechanism

Dubbo provides a way to telnet, directly with the command to view service information and so on. How to do it.

1. Codecs

Com.alibaba.dubbo.remoting.transport.netty.NettyCodecAdapter.InternalDecoder

Implements the Simplechannelupstreamhandler class

Then register to Channelpipeline.

It's all in the back with Netty.

2. URL class in Dubbo

Com.alibaba.dubbo.common.URL

This class acts like the context we normally use, and it describes some of the configuration information in the invocation process, in the following form:

dubbo://192.168.1.101:20880/org.simonme.dubbo.demo.provider.service.helloservice?anyhost=true&application= hello-world-app&channel.readonly.sent=true&codec=dubbo&dubbo=2.4.9&heartbeat=60000& interface=org.simonme.dubbo.demo.provider.service.helloservice&methods=sayhello&monitor=dubbo%3a%2f% 2f192.168.1.100%3a2174%2fcom.alibaba.dubbo.registry.registryservice%3fapplication%3dhello-world-app%26dubbo% 3d2.4.9%26pid%3d8976%26protocol%3dregistry%26refer%3ddubbo%253d2.4.9%2526interface% 253dcom.alibaba.dubbo.monitor.monitorservice%2526pid%253d8976%2526timestamp%253d1468370420113%26registry% 3dzookeeper%26timestamp%3d1468370419870&pid=8976&side=provider&timestamp=1468370419920

For example I need what codec, I will go to this URL to take

Com.alibaba.dubbo.remoting.transport.AbstractEndpoint.AbstractEndpoint (URL, Channelhandler)

This.codec = Extensionloader.getextensionloader (Codec.class). GetExtension (Url.getparameter (Constants.CODEC_KEY, " Telnet "));

We can find the Codec=dubbo in the URL example above

So I know this time using the Dubbo codec.

Slightly different from what we used to do in the context, the context prevents some of the more complex objects, such as placing a root form container.

With the URL of this form, combined with zookeeper use more convenient.

3. Dubbo's extension point implementation

Analysis com.alibaba.dubbo.common.extension.extensionloader<t>

In essence, the built-in instance is placed in the Cachedinstances attribute, which could have been given to spring, and the spring professional did the IOC's job. But Dubbo did it. One obvious benefit is that Dubbo can run without relying on any third-party framework. To put it simple: Dubbo himself made a simple IOC mechanism, which is called the SPI. The framework of the IOC is quite a lot, and Struts2 himself has done the IOC. Detailed analysis of the previous picture of a mind map

4. Telnet protocol Codec

Dubbocountcodec and Netty docking, dubbocountcodec associated with Dubbocodec. There is a telnetcodec on the Dubbocodec inheritance system. Telnetcodec completes the codec of the Telenet protocol and converts the InputStream instance into a message in the Decode method.

5. Decoded Action Link

Nettyhandler extends Simplechannelhandler This class will be registered to Netty,netty after decoding will trigger the following messagereceived logic.

Com.alibaba.dubbo.remoting.transport.netty.NettyHandler.messageReceived (Channelhandlercontext, messageevent)

This handler is associated with the handler,com.alibaba.dubbo.remoting.telnet.support.telnethandleradapter of real processing logic.

Telnethandleradapter triggers the Telnet method to invoke the true command processing logic

An instance of a specific command implementation class is obtained by the extension point mechanism based on the command received.

can be analyzed with Com.alibaba.dubbo.rpc.protocol.dubbo.telnet.ListTelnetHandler as an example.

The implementation of the command uses the @help annotation, which describes the help of the command.

6. After Telnet connection, press the UP or DOWN ARROW keys to echo the history command, how to achieve

Implemented in Com.alibaba.dubbo.remoting.telnet.codec.TelnetCodec.decode (Channel, InputStream, int, byte[]), The codec records the history command in the channel and then gets it based on the direction.

Boolean down = endsWith (message, down);         if (Up | | Down ) {            LinkedList<String> history = (linkedlist<string>) Channel.getattribute (history_list_key );             if Null | | History.size () = = 0)                {return  need_more_input;            }

--eof--

Management implementation of Dubbo source code Analysis 6-telnet mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.