Detailed analysis of sofa-rpc server source code (with flow chart)
This article brings you a detailed analysis of the sofa-rpc server source code (with flow chart attached). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
sofa-rpc is a high-performance RPC framework open sourced by Alibaba. This article is mainly a code reading of the sofa-rpc provider startup service process. The following is a basic relationship process that I simply drew. Figure
Below we will track and read the process based on the sofa-rpc code. We take BoltServer as an example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
We can see that sofa-rpc initializes the configuration information of the service provider Provider through the ProviderConfig class, and also provides export serves as the entry point for service startup.
1 2 3 4 5 6 |
|
1 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
DefaultProviderBootstrap and DubboProviderBootstrap both inherit from ProviderBootstrap.
DefaultProviderBootstrap is inherited by three classes: BoltProviderBootstrap, Http2ClearTextProviderBootstrap, and RestProviderBootstrap. This actually corresponds to the three server service methods in sofa-rpc.
Let’s take a look at the DefaultProviderBootstrap service startup source code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
In the code, the Server service object is built through serverConfig.buildIfAbsent(), and in buildIfAbsent() In the function, we can see that sever is obtained through the SeverFactory factory. In the getSever() of SeverFactory, the specific instance of Sever is obtained according to the configuration of SeverConfig, and Init() is executed for initialization.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
sofa-rpc provides three server types: BoltServer, RestServer and AbstractHttpServer
The bottom layer of communication in BoltServer is implemented through RemotingServer, which is developed based on Alibaba's sofa-bolt communication framework.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
AbstractHttpServer provides http service, and the underlying communication is implemented through the ServerTransport class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
ServerTransport is an abstract class. The specific implementation is AbstractHttp2ServerTransport
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
RestServer under the transport package to provide Rest services. The underlying communication implementation can be seen in SofaNettyJaxrsServer.
1 2 3 4 5 6 7 8 9 10 |
|
The specific code for service startup in SofaNettyJaxrsServer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
OK, the above is sofa -A basic process for rpc server startup. What we focus on here is only the simple service startup process, without in-depth analysis of code functions. On this basis, we can further explore the specific implementation of the code.
The above is the detailed content of Detailed analysis of sofa-rpc server source code (with flow chart). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.
