Dubbo service framework analysis (2)

Source: Internet
Author: User

This section describes Dubbo-common. Dubbo-common is a public logic module, including util classes and general models. It is the basis of other modules.

Scaling Mechanism


SPI

SPI is the annotation of extended points. In terms of types, all extended points must be labeled through SPI.

Conventions:

In the jar package of the extension class, place the extension Point configuration file: META-INF/Dubbo/interface full qualified name, content: configuration name = extension implementation class full qualified name, multiple implementation classes are separated by line breaks.

1) Wrapper class for automatic wrap extension points

Extensionloader loads the extension point (through the content in the extension Point configuration file). If the implementation has a copy constructor, it is determined to be the extension point Wrapper class.

2) Automatic injection of associated extension points

When an extension point is loaded, if the extension point implementation class member is of another extension point type, extensionloader automatically injects dependent extension points.

3) The default extension point is an adaptive instance.

If the extensionloader injection dependency extension point is an adaptive instance, it is not determined that the call is an extension point implementation until the extension point method is executed.

Adaptive

Adaptive Implementation of extension points, which can be labeled on the type and method. When extensionloader generates an extension adaptive instance, it provides extensionloader with extended point information.

Below is the Dubbo transporter extension code:

@ SPI ("netty ")

PublicinterfaceTransporter {

 

/**

* Bind a server.

*

*@ SeeCom. Alibaba. Dubbo. remoting. Transporters # BIND (URL, Handler er, channelhandler)

*@ ParamURL ServerURL

*@ ParamHandler

*@ ReturnServer

*@ ThrowsRemotingexception

*/

@ Adaptive ({constants.Server_key, Constants.Transporter_key})

Server Bind (URL, channelhandlerhandler)ThrowsRemotingexception;

 

/**

* Connect to a server.

*

*@ SeeCom. Alibaba. Dubbo. remoting. Transporters # connect (URL, receiver, channellistener)

*@ ParamURL ServerURL

*@ ParamHandler

*@ ReturnClient

*@ ThrowsRemotingexception

*/

@ Adaptive ({constants.Client_key, Constants.Transporter_key})

Client connect (URL, channelhandlerhandler)ThrowsRemotingexception;

 

}

For the bind method, the adaptive method first searches for the "server" key. If the key does not have a value, it searches for the "transport" key value to determine the actual extension point to which the proxy belongs.

Extensionfactory

Extensionfactory is also an SPI. The container that loads the extension points from different containers.


Adaptiveextensionfactory is marked as adaptive, which supports automatic activation of extension points. If there is no parameter as shown below, it is automatically activated unconditionally.

@ Adaptive

PublicclassAdaptiveextensionfactoryImplementsExtensionfactory

If there is a parameter, it is conditional activation.

Logger

Logger is also an extension. The loggeradapter adaptation interface is an SPI.


In Dubbo, multiple implementations of jcl, JDK, log4j, and slf4j are implemented. As shown in.


Threadpool

Threadpool is also an extended SPI. The service provider thread implements the policy. When the server receives a request, it needs to create a thread in the thread pool to execute the service logic of the service provider.

@ SPI ("fixed ")

PublicinterfaceThreadpool {

/**

* Thread Pool

*

*@ ParamURL thread parameters

*@ ReturnThread Pool

*/

@ Adaptive ({constants.Threadpool_key})

Executor getexecutor (URL );

 

}

The preceding SPI parameter is the default thread pool type. In the getexecutor method, the key of the threadpool is used for auto scaling.

Multiple thread pools fixed, cached, and limited are implemented in Dubbo.


Serialize

Serialize is the core interface here. Convert an object to a byte stream for network transmission and convert the byte stream into an object to restore the object after receiving the byte stream data. Is the interface defined in Dubbo.


Is an extension Implementation defined in Dubbo. They are:

  • Nativejavaserialization: Native Java serialization implementation.
  • Compactedjavaserialization: compresses Java serialization. It mainly writes and reads custom class descriptors based on native Java serialization. Write class descriptors of the object type only write class names, instead of the complete information of the class. This reduces the size after serialization when there are many object types.
  • Javaserialization: only the encapsulation of native Java serialization and compression Java serialization.
  • Jsonserialization: Native JSON serialization implementation.
  • Fastjsonserialization: Uses Alibaba's fastjson for serialization.
  • Hessian2serialization: serialization implemented using the IO mechanism of hessian2.
  • Dubboserialization: Dubbo custom serialization implementation.


Compiler

Compiler is an SPI, Java code compiler used to dynamically generate bytecode and accelerate calls.


Implements JDK and Javassist. The Javassist is an open-source class library for analyzing, editing, and creating Java bytecode. Javassist is a subproject of JBoss. It has the advantages of being simple and fast.


Dubbo service framework analysis (2)

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.