├── .gitignore
├── .idea
├── .gitignore
├── compiler.xml
├── encodings.xml
├── jarRepositories.xml
├── misc.xml
├── uiDesigner.xml
└── vcs.xml
├── LICENSE
├── README.md
├── pom.xml
├── qrpc-core
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── org
│ │ └── qrpc
│ │ ├── Banner.java
│ │ ├── ConfigEnvironment.java
│ │ ├── Environment.java
│ │ ├── EventCaster.java
│ │ ├── Factory.java
│ │ ├── Listener.java
│ │ ├── Meta.java
│ │ ├── PropertyKeys.java
│ │ ├── RpcStatus.java
│ │ ├── ThreadService.java
│ │ ├── client
│ │ ├── Channel
│ │ │ ├── QRpcChannel.java
│ │ │ ├── SimpleBlockQRpcChannel.java
│ │ │ └── SimpleQRpcChannel.java
│ │ ├── ConnectionConfig.java
│ │ ├── ConnectionFactory.java
│ │ ├── EncryptType.java
│ │ ├── Endpoint.java
│ │ ├── QRpcClientEndpoint.java
│ │ ├── RequestCache.java
│ │ ├── RequestFuture.java
│ │ └── ResponseHandler.java
│ │ ├── exception
│ │ ├── ClientChannelNotActive.java
│ │ ├── DuplicateServiceException.java
│ │ └── UnKnownResponseException.java
│ │ ├── net
│ │ ├── NettyClientEndpoint.java
│ │ ├── NettyClientInboundHandler.java
│ │ ├── NettyServerInboundHandler.java
│ │ ├── NettyServerSender.java
│ │ ├── NettyTCPServer.java
│ │ ├── Receiver.java
│ │ ├── Responsible.java
│ │ ├── Sender.java
│ │ └── Server.java
│ │ ├── server
│ │ ├── AbstractServer.java
│ │ ├── ListableServiceFactory.java
│ │ ├── MethodInfoHolder.java
│ │ ├── QRpcController.java
│ │ ├── RespondCallBack.java
│ │ ├── ServerBuilder.java
│ │ ├── ServiceExecutor.java
│ │ ├── ServiceFactory.java
│ │ ├── ServiceHolder.java
│ │ └── ServiceRunner.java
│ │ └── utils
│ │ └── ResponseManager.java
│ └── resources
│ └── meta.proto
├── qrpc-demo
├── pom.xml
└── src
│ └── main
│ ├── java
│ ├── Client.java
│ ├── Demo.java
│ ├── DemoServiceImpl.java
│ └── Server.java
│ └── resources
│ └── demo.proto
└── qrpc-project.iml
/.gitignore:
--------------------------------------------------------------------------------
1 | **/target/**
2 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
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 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | qRPC简介
2 | ------
3 |
4 | qRPC是一个基于TCP协议、基于Protobuf序列化和代码生成,跨语言的高效率轻量级RPC框架。
5 |
6 | 框架具有如下特点:
7 |
8 | * 基于TCP协议的非阻塞IO(NIO)实现底层网络通信,吞吐量高。
9 |
10 |
11 | * 基于Protobuf序列化,紧凑高效、高性能、跨语言、可拓展。
12 |
13 |
14 | * 通过IDL(Interface Define Language)进行接口定义并生成代码
15 |
16 |
17 | * 跨语言,支持Java、Go、C++、Python等多种语言
18 |
19 |
20 | 使用方法
21 | ----
22 |
23 | 需要了解RPC(Rmote Procedure Call),会用Protobuf([Proto3官方文档](https://protobuf.dev/programming-guides/proto3/ "Proto3官方文档")),如果你使用过Google gRPC,你将会非常容易上手。
24 |
25 | #### Java:
26 |
27 | * 引入Maven依赖
28 |
29 | ```
30 |
31 | io.github.barackyoung
32 | qrpc-core
33 | 1.0.0.SNAPSHOT
34 |
35 | ```
36 |
37 | * 定义数据结构和服务接口
38 |
39 | ```
40 | Syntax="proto3";
41 | Option Java_Multiple_Files=false;
42 | Option Java_Package="com.qrpc.demo";
43 | Option Java_Outer_Classname="Demo";
44 | Option Java_Generic_Services=true;
45 | Package qrpc.demo;
46 |
47 | Message request {
48 | string message=1;
49 | }
50 |
51 | Message response {
52 | string message=1;
53 | }
54 | Service DemoService{
55 | Rpc sendMessage (request) returns (response) {};
56 | }
57 | ```
58 |
59 | * 生成数据结构和接口定义
60 |
61 |
62 | ```
63 | Protoc -- java out=-- proto path=
64 | ```
65 |
66 | * 服务端实现接口
67 |
68 |
69 | ```
70 | Public class DemoServiceImpl extensions Demo.DemoService {
71 | @Overrides
72 | Public void sendMessage(RpcController controller, Demo.request request, RpcCallback done){
73 | System.out.println("received from client, message:"+request. getMessage ());
74 | Demo.response response = Demo.response.newBuilder().setMessage("hi client").build();
75 | Done.run(response);
76 | }
77 | }
78 | ```
79 |
80 | * 客户端调用服务接口
81 |
82 |
83 | ```
84 | Demo.requestrequest=Demo.request.newBuilder()
85 | .setMessage("hi, server!")
86 | .build();
87 |
88 | //Synchronous call
89 | UsageDemo.DemoService.BlockingInterface blockingStub=Demo.DemoService.newBlockingStub(SimpleBlockQRpcChannel.forAddress("127.0.0.1", 8888).build());
90 | Demo.response response = blockingStub.sendMessage(null, request);
91 | System.out.println("synchronous response:" + response.getMessage ());
92 |
93 | //Asynchronous call
94 | UsageDemo.DemoService.Stub stub = Demo.DemoService.newStub(SimpleQRpcChannel.forAddress("127.0.0.1", 8888).build());
95 | Stub.sendMessage(null, request, new RpcCallback() {
96 | @ Override
97 | Public void run(Demo.response parameter){
98 | System.out.println ("asynchronous response:"+response. getMessage ());
99 | }
100 | });
101 | ```
102 |
103 | #### Go: TODO
104 |
105 | #### C++: TODO
106 |
107 | 待开发点
108 | ----
109 |
110 | * spring-boot-starter,springboot自动配置,支持与springboot无缝结合
111 |
112 |
113 | * 服务治理(支持ectd、zookeeper等服务发现),负载均衡调用
114 |
115 |
116 | * 配置系统,比如线程数等参数可配置
117 |
118 |
119 | * 云原生相关支持
120 |
121 |
122 | * 测试用例
123 |
124 |
125 | 提示
126 | --
127 |
128 | 项目处于起步阶段,代码易读懂,欢迎广大社会程序员、学生一起加入,一起学习造轮子,把理论与实践相结合,一起提高!
129 |
130 |
131 |
132 | Introduction to qRPC
133 | ------
134 | QRPC is an efficient and lightweight RPC framework based on the TCP protocol, Protobuf serialization, and code generation, spanning multiple languages.
135 | The framework has the following characteristics:
136 | * Non blocking IO (NIO) based on TCP protocol enables low-level network communication with high throughput.
137 | * Based on Protobuf serialization, it is compact, efficient, high-performance, cross language, and scalable.
138 | * Define interfaces and generate code through IDL (Interface Definition Language)
139 | * Cross language support for multiple languages such as Java, Go, C++, Python, etc
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 | Usage
151 | ----
152 | Need to understand RPC (Rmote Procedure Call) and use Protobuf ([Proto3 official document]( https://protobuf.dev/programming-guides/proto3/ If you have used Google gRPC, it will be very easy for you to get started.
153 | ####Java:
154 | * Introducing Maven dependencies
155 | ```
156 |
157 | io.github.barackyoung
158 | qrpc-core
159 | 1.0.0.SNAPSHOT
160 |
161 | ```
162 | * Define data structures and service interfaces
163 | ```
164 | Syntax="proto3";
165 | Option Java_Multiple_Files=false;
166 | Option Java_Package="com.qrpc.demo";
167 | Option Java_Outer_Classname="Demo";
168 | Option Java_Generic_Services=true;
169 | Package qrpc.demo;
170 |
171 | Message request {
172 | string message=1;
173 | }
174 |
175 | Message response {
176 | string message=1;
177 | }
178 | Service DemoService{
179 | Rpc sendMessage (request) returns (response) {};
180 | }
181 | ```
182 | * Generate data structures and interface definitions
183 | ```
184 | Protoc -- java out=-- proto path=
185 | ```
186 | * Server implementation interface
187 | ```
188 | Public class DemoServiceImpl extensions Demo.DemoService {
189 | @Overrides
190 | Public void sendMessage(RpcController controller, Demo.request request, RpcCallback done){
191 | System.out.println("received from client, message:"+request. getMessage ());
192 | Demo.response response = Demo.response.newBuilder().setMessage("hi client").build();
193 | Done.run(response);
194 | }
195 | }
196 | ```
197 | * Client Call Service Interface
198 | ```
199 | Demo.requestrequest=Demo.request.newBuilder()
200 | .setMessage("hi, server!")
201 | .build();
202 |
203 | //Synchronous call
204 | UsageDemo.DemoService.BlockingInterface blockingStub=Demo.DemoService.newBlockingStub(SimpleBlockQRpcChannel.forAddress("127.0.0.1", 8888).build());
205 | Demo.response response = blockingStub.sendMessage(null, request);
206 | System.out.println("synchronous response:" + response.getMessage ());
207 |
208 | //Asynchronous call
209 | UsageDemo.DemoService.Stub stub = Demo.DemoService.newStub(SimpleQRpcChannel.forAddress("127.0.0.1", 8888).build());
210 | Stub.sendMessage(null, request, new RpcCallback() {
211 | @ Override
212 | Public void run(Demo.response parameter){
213 | System.out.println ("asynchronous response:"+response. getMessage ());
214 | }
215 | });
216 | ```
217 | #### Go: TODO
218 | #### C++: TODO
219 |
220 |
221 | Points to be developed
222 | ----
223 | * Spring boot starter, automatically configured for spring boot, supports seamless integration with spring boot
224 | * Service governance (supporting service discovery such as ectd and zookeeper), load balancing calls
225 | * Configure the system, such as configurable parameters such as thread count
226 | * Cloud native related support
227 | * Test Cases
228 |
229 | prompt
230 | --
231 | The project is in its early stages and the code is easy to read. We welcome programmers and students from all walks of life to join us and learn how to build wheels together. We will combine theory with practice to improve together!
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | io.github.barackyoung
8 | qrpc
9 | 1.0.0-SNAPSHOT
10 | pom
11 |
12 | qrpc-core
13 | qrpc-demo
14 |
15 |
16 | qrpc
17 | a light multi language RPC framework
18 | https://github.com/BarackYoung/qRPC
19 |
20 |
21 |
22 |
23 | The Apache Software License, Version 2.0
24 | http://www.apache.org/licenses/LICENSE-2.0.txt
25 | repo
26 | A business-friendly OSS license
27 |
28 |
29 |
30 |
31 | main
32 | https://github.com/BarackYoung/qRPC.git
33 | scm:https://github.com/BarackYoung/qRPC.git
34 | scm:git:git@github.com:BarackYoung/qRPC.git
35 |
36 |
37 |
38 |
39 | Lianhuan Yang
40 | 1330292703@qq.com
41 | https://github.com/BarackYoung/
42 |
43 |
44 |
45 |
46 |
47 | oss
48 | https://s01.oss.sonatype.org/content/repositories/snapshots
49 |
50 |
51 | oss
52 | https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/
53 |
54 |
55 |
56 |
57 |
58 |
59 | org.apache.maven.plugins
60 | maven-compiler-plugin
61 |
62 | 1.8
63 | 1.8
64 |
65 |
66 |
67 |
68 | org.apache.maven.plugins
69 | maven-source-plugin
70 | 2.2.1
71 |
72 |
73 | package
74 |
75 | jar-no-fork
76 |
77 |
78 |
79 |
80 |
81 |
82 | org.apache.maven.plugins
83 | maven-javadoc-plugin
84 | 2.10.4
85 |
86 |
87 | -Xdoclint:none
88 |
89 |
90 |
91 |
92 | package
93 |
94 | jar
95 |
96 |
97 |
98 |
99 |
100 |
101 | org.apache.maven.plugins
102 | maven-gpg-plugin
103 | 1.6
104 |
105 |
106 | --pinentry-mode
107 | loopback
108 |
109 |
110 |
111 |
112 | sign-artifacts
113 | verify
114 |
115 | sign
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
--------------------------------------------------------------------------------
/qrpc-core/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | io.github.barackyoung
8 | qrpc
9 | 1.0.0-SNAPSHOT
10 |
11 |
12 | qrpc-core
13 |
14 |
15 | 8
16 | 8
17 | UTF-8
18 | 4.1.106.Final
19 | 3.22.2
20 | 2.0.5
21 | 1.1.3
22 | 1.18.16
23 | 4.13.2
24 |
25 |
26 |
27 |
28 | io.netty
29 | netty-all
30 | ${netty.version}
31 |
32 |
33 | com.google.protobuf
34 | protobuf-java
35 | ${protobuf.java.version}
36 |
37 |
38 | org.slf4j
39 | slf4j-api
40 | 1.7.36
41 |
42 |
43 | org.slf4j
44 | slf4j-simple
45 | 1.7.36
46 |
47 |
48 | org.projectlombok
49 | lombok
50 | ${lombok.version}
51 | compile
52 |
53 |
54 | junit
55 | junit
56 | ${junit.version}
57 | test
58 |
59 |
60 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/Banner.java:
--------------------------------------------------------------------------------
1 | package org.qrpc;
2 |
3 | /**
4 | * @author Yang Lianhuan
5 | * @version 1.0.0
6 | * @since 2023/4/4
7 | **/
8 | public class Banner {
9 | public static void print() {
10 | System.out.println(
11 | " ---- ----- ----- -------| \n" +
12 | " / -- \\\\ / ---- \\\\ / \\\\ / /------| \n" +
13 | " | | | | | | | | | | | | | | \n" +
14 | " | | | | | | ---| | | |---/ / | | \n" +
15 | " | | | |\\\\ | |\\\\ \\\\ | | | |------| \n" +
16 | " \\ --// \\\\--\\\\ | | \\\\-\\\\ | | \\ \\----| \n");
17 | }
18 |
19 | public static void printStarted(int port) {
20 | System.out.println("qRPC Server started at port: " + port);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/ConfigEnvironment.java:
--------------------------------------------------------------------------------
1 | package org.qrpc;
2 |
3 | import java.util.Objects;
4 | import java.util.concurrent.ConcurrentHashMap;
5 |
6 | /**
7 | * @author Yang Lianhuan
8 | * @version 1.0.0
9 | * @since 2024/2/3
10 | **/
11 | public class ConfigEnvironment implements Environment {
12 |
13 | private ConfigEnvironment() {}
14 | private static Environment configEnvironment;
15 | private static final ConcurrentHashMap configs = new ConcurrentHashMap<>();
16 |
17 | static {
18 | configs.put(PropertyKeys.CLIENT_TIMEOUT, "300000");
19 | }
20 |
21 | @Override
22 | public Object getProperty(String key) {
23 | return configs.get(key);
24 | }
25 |
26 | public static Environment getInstance() {
27 | if (!Objects.isNull(configEnvironment)) {
28 | return configEnvironment;
29 | }
30 | synchronized (ConfigEnvironment.class) {
31 | if (!Objects.isNull(configEnvironment)) {
32 | return configEnvironment;
33 | }
34 | configEnvironment = new ConfigEnvironment();
35 | return configEnvironment;
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/Environment.java:
--------------------------------------------------------------------------------
1 | package org.qrpc;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * @author Yang Lianhuan
7 | * @version 1.0.0
8 | * @since 2023/3/26
9 | **/
10 | public interface Environment {
11 | Object getProperty(String key);
12 | }
13 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/EventCaster.java:
--------------------------------------------------------------------------------
1 | package org.qrpc;
2 |
3 | /**
4 | * 事件分发器
5 | *
6 | * @author Yang Lianhuan
7 | * @version 1.0.0
8 | * @since 2024/1/26
9 | **/
10 | public class EventCaster {
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/Factory.java:
--------------------------------------------------------------------------------
1 | package org.qrpc;
2 |
3 | import com.google.protobuf.Service;
4 |
5 | /**
6 | * @author Yang Lianhuan
7 | * @version 1.0.0
8 | * @since 2023/3/26
9 | **/
10 | public interface Factory {
11 | void register(String key, T value);
12 |
13 | boolean contains(String key);
14 |
15 | T get(String key);
16 |
17 | void remove(String key);
18 | }
19 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/Listener.java:
--------------------------------------------------------------------------------
1 | package org.qrpc;
2 |
3 | /**
4 | * @author Yang Lianhuan
5 | * @version 1.0.0
6 | * @since 2024/1/26
7 | **/
8 | public interface Listener {
9 |
10 | /**
11 | * 启动监听器
12 | */
13 | void run();
14 | }
15 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/Meta.java:
--------------------------------------------------------------------------------
1 | // Generated by the protocol buffer compiler. DO NOT EDIT!
2 | // source: meta.proto
3 |
4 | package org.qrpc;
5 |
6 | public final class Meta {
7 | private Meta() {}
8 | public static void registerAllExtensions(
9 | com.google.protobuf.ExtensionRegistryLite registry) {
10 | }
11 |
12 | public static void registerAllExtensions(
13 | com.google.protobuf.ExtensionRegistry registry) {
14 | registerAllExtensions(
15 | (com.google.protobuf.ExtensionRegistryLite) registry);
16 | }
17 | /**
18 | * Protobuf enum {@code qrpc.meta.Status}
19 | */
20 | public enum Status
21 | implements com.google.protobuf.ProtocolMessageEnum {
22 | /**
23 | * SUCCESS = 0;
24 | */
25 | SUCCESS(0),
26 | /**
27 | * TIME_OUT = 2;
28 | */
29 | TIME_OUT(2),
30 | /**
31 | * SERVICE_NOT_FOUND = 3;
32 | */
33 | SERVICE_NOT_FOUND(3),
34 | /**
35 | * SYSTEM_ERROR = 4;
36 | */
37 | SYSTEM_ERROR(4),
38 | UNRECOGNIZED(-1),
39 | ;
40 |
41 | /**
42 | * SUCCESS = 0;
43 | */
44 | public static final int SUCCESS_VALUE = 0;
45 | /**
46 | * TIME_OUT = 2;
47 | */
48 | public static final int TIME_OUT_VALUE = 2;
49 | /**
50 | * SERVICE_NOT_FOUND = 3;
51 | */
52 | public static final int SERVICE_NOT_FOUND_VALUE = 3;
53 | /**
54 | * SYSTEM_ERROR = 4;
55 | */
56 | public static final int SYSTEM_ERROR_VALUE = 4;
57 |
58 |
59 | public final int getNumber() {
60 | if (this == UNRECOGNIZED) {
61 | throw new java.lang.IllegalArgumentException(
62 | "Can't get the number of an unknown enum value.");
63 | }
64 | return value;
65 | }
66 |
67 | /**
68 | * @param value The numeric wire value of the corresponding enum entry.
69 | * @return The enum associated with the given numeric wire value.
70 | * @deprecated Use {@link #forNumber(int)} instead.
71 | */
72 | @java.lang.Deprecated
73 | public static Status valueOf(int value) {
74 | return forNumber(value);
75 | }
76 |
77 | /**
78 | * @param value The numeric wire value of the corresponding enum entry.
79 | * @return The enum associated with the given numeric wire value.
80 | */
81 | public static Status forNumber(int value) {
82 | switch (value) {
83 | case 0: return SUCCESS;
84 | case 2: return TIME_OUT;
85 | case 3: return SERVICE_NOT_FOUND;
86 | case 4: return SYSTEM_ERROR;
87 | default: return null;
88 | }
89 | }
90 |
91 | public static com.google.protobuf.Internal.EnumLiteMap
92 | internalGetValueMap() {
93 | return internalValueMap;
94 | }
95 | private static final com.google.protobuf.Internal.EnumLiteMap<
96 | Status> internalValueMap =
97 | new com.google.protobuf.Internal.EnumLiteMap() {
98 | public Status findValueByNumber(int number) {
99 | return Status.forNumber(number);
100 | }
101 | };
102 |
103 | public final com.google.protobuf.Descriptors.EnumValueDescriptor
104 | getValueDescriptor() {
105 | if (this == UNRECOGNIZED) {
106 | throw new java.lang.IllegalStateException(
107 | "Can't get the descriptor of an unrecognized enum value.");
108 | }
109 | return getDescriptor().getValues().get(ordinal());
110 | }
111 | public final com.google.protobuf.Descriptors.EnumDescriptor
112 | getDescriptorForType() {
113 | return getDescriptor();
114 | }
115 | public static final com.google.protobuf.Descriptors.EnumDescriptor
116 | getDescriptor() {
117 | return org.qrpc.Meta.getDescriptor().getEnumTypes().get(0);
118 | }
119 |
120 | private static final Status[] VALUES = values();
121 |
122 | public static Status valueOf(
123 | com.google.protobuf.Descriptors.EnumValueDescriptor desc) {
124 | if (desc.getType() != getDescriptor()) {
125 | throw new java.lang.IllegalArgumentException(
126 | "EnumValueDescriptor is not for this type.");
127 | }
128 | if (desc.getIndex() == -1) {
129 | return UNRECOGNIZED;
130 | }
131 | return VALUES[desc.getIndex()];
132 | }
133 |
134 | private final int value;
135 |
136 | private Status(int value) {
137 | this.value = value;
138 | }
139 |
140 | // @@protoc_insertion_point(enum_scope:qrpc.meta.Status)
141 | }
142 |
143 | /**
144 | * Protobuf enum {@code qrpc.meta.Type}
145 | */
146 | public enum Type
147 | implements com.google.protobuf.ProtocolMessageEnum {
148 | /**
149 | * REQUEST = 0;
150 | */
151 | REQUEST(0),
152 | /**
153 | * RESPOND = 1;
154 | */
155 | RESPOND(1),
156 | /**
157 | * PEER = 2;
158 | */
159 | PEER(2),
160 | UNRECOGNIZED(-1),
161 | ;
162 |
163 | /**
164 | * REQUEST = 0;
165 | */
166 | public static final int REQUEST_VALUE = 0;
167 | /**
168 | * RESPOND = 1;
169 | */
170 | public static final int RESPOND_VALUE = 1;
171 | /**
172 | * PEER = 2;
173 | */
174 | public static final int PEER_VALUE = 2;
175 |
176 |
177 | public final int getNumber() {
178 | if (this == UNRECOGNIZED) {
179 | throw new java.lang.IllegalArgumentException(
180 | "Can't get the number of an unknown enum value.");
181 | }
182 | return value;
183 | }
184 |
185 | /**
186 | * @param value The numeric wire value of the corresponding enum entry.
187 | * @return The enum associated with the given numeric wire value.
188 | * @deprecated Use {@link #forNumber(int)} instead.
189 | */
190 | @java.lang.Deprecated
191 | public static Type valueOf(int value) {
192 | return forNumber(value);
193 | }
194 |
195 | /**
196 | * @param value The numeric wire value of the corresponding enum entry.
197 | * @return The enum associated with the given numeric wire value.
198 | */
199 | public static Type forNumber(int value) {
200 | switch (value) {
201 | case 0: return REQUEST;
202 | case 1: return RESPOND;
203 | case 2: return PEER;
204 | default: return null;
205 | }
206 | }
207 |
208 | public static com.google.protobuf.Internal.EnumLiteMap
209 | internalGetValueMap() {
210 | return internalValueMap;
211 | }
212 | private static final com.google.protobuf.Internal.EnumLiteMap<
213 | Type> internalValueMap =
214 | new com.google.protobuf.Internal.EnumLiteMap() {
215 | public Type findValueByNumber(int number) {
216 | return Type.forNumber(number);
217 | }
218 | };
219 |
220 | public final com.google.protobuf.Descriptors.EnumValueDescriptor
221 | getValueDescriptor() {
222 | if (this == UNRECOGNIZED) {
223 | throw new java.lang.IllegalStateException(
224 | "Can't get the descriptor of an unrecognized enum value.");
225 | }
226 | return getDescriptor().getValues().get(ordinal());
227 | }
228 | public final com.google.protobuf.Descriptors.EnumDescriptor
229 | getDescriptorForType() {
230 | return getDescriptor();
231 | }
232 | public static final com.google.protobuf.Descriptors.EnumDescriptor
233 | getDescriptor() {
234 | return org.qrpc.Meta.getDescriptor().getEnumTypes().get(1);
235 | }
236 |
237 | private static final Type[] VALUES = values();
238 |
239 | public static Type valueOf(
240 | com.google.protobuf.Descriptors.EnumValueDescriptor desc) {
241 | if (desc.getType() != getDescriptor()) {
242 | throw new java.lang.IllegalArgumentException(
243 | "EnumValueDescriptor is not for this type.");
244 | }
245 | if (desc.getIndex() == -1) {
246 | return UNRECOGNIZED;
247 | }
248 | return VALUES[desc.getIndex()];
249 | }
250 |
251 | private final int value;
252 |
253 | private Type(int value) {
254 | this.value = value;
255 | }
256 |
257 | // @@protoc_insertion_point(enum_scope:qrpc.meta.Type)
258 | }
259 |
260 | public interface RpcMetaDataOrBuilder extends
261 | // @@protoc_insertion_point(interface_extends:qrpc.meta.RpcMetaData)
262 | com.google.protobuf.MessageOrBuilder {
263 |
264 | /**
265 | * string service_name = 1;
266 | * @return The serviceName.
267 | */
268 | java.lang.String getServiceName();
269 | /**
270 | * string service_name = 1;
271 | * @return The bytes for serviceName.
272 | */
273 | com.google.protobuf.ByteString
274 | getServiceNameBytes();
275 |
276 | /**
277 | * int32 method_id = 2;
278 | * @return The methodId.
279 | */
280 | int getMethodId();
281 |
282 | /**
283 | * bytes content = 3;
284 | * @return The content.
285 | */
286 | com.google.protobuf.ByteString getContent();
287 |
288 | /**
289 | * .qrpc.meta.Status status = 4;
290 | * @return The enum numeric value on the wire for status.
291 | */
292 | int getStatusValue();
293 | /**
294 | * .qrpc.meta.Status status = 4;
295 | * @return The status.
296 | */
297 | org.qrpc.Meta.Status getStatus();
298 |
299 | /**
300 | * .qrpc.meta.Type type = 5;
301 | * @return The enum numeric value on the wire for type.
302 | */
303 | int getTypeValue();
304 | /**
305 | * .qrpc.meta.Type type = 5;
306 | * @return The type.
307 | */
308 | org.qrpc.Meta.Type getType();
309 |
310 | /**
311 | * string request_id = 6;
312 | * @return The requestId.
313 | */
314 | java.lang.String getRequestId();
315 | /**
316 | * string request_id = 6;
317 | * @return The bytes for requestId.
318 | */
319 | com.google.protobuf.ByteString
320 | getRequestIdBytes();
321 | }
322 | /**
323 | * Protobuf type {@code qrpc.meta.RpcMetaData}
324 | */
325 | public static final class RpcMetaData extends
326 | com.google.protobuf.GeneratedMessageV3 implements
327 | // @@protoc_insertion_point(message_implements:qrpc.meta.RpcMetaData)
328 | RpcMetaDataOrBuilder {
329 | private static final long serialVersionUID = 0L;
330 | // Use RpcMetaData.newBuilder() to construct.
331 | private RpcMetaData(com.google.protobuf.GeneratedMessageV3.Builder> builder) {
332 | super(builder);
333 | }
334 | private RpcMetaData() {
335 | serviceName_ = "";
336 | content_ = com.google.protobuf.ByteString.EMPTY;
337 | status_ = 0;
338 | type_ = 0;
339 | requestId_ = "";
340 | }
341 |
342 | @java.lang.Override
343 | @SuppressWarnings({"unused"})
344 | protected java.lang.Object newInstance(
345 | UnusedPrivateParameter unused) {
346 | return new RpcMetaData();
347 | }
348 |
349 | public static final com.google.protobuf.Descriptors.Descriptor
350 | getDescriptor() {
351 | return org.qrpc.Meta.internal_static_qrpc_meta_RpcMetaData_descriptor;
352 | }
353 |
354 | @java.lang.Override
355 | protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
356 | internalGetFieldAccessorTable() {
357 | return org.qrpc.Meta.internal_static_qrpc_meta_RpcMetaData_fieldAccessorTable
358 | .ensureFieldAccessorsInitialized(
359 | org.qrpc.Meta.RpcMetaData.class, org.qrpc.Meta.RpcMetaData.Builder.class);
360 | }
361 |
362 | public static final int SERVICE_NAME_FIELD_NUMBER = 1;
363 | @SuppressWarnings("serial")
364 | private volatile java.lang.Object serviceName_ = "";
365 | /**
366 | * string service_name = 1;
367 | * @return The serviceName.
368 | */
369 | @java.lang.Override
370 | public java.lang.String getServiceName() {
371 | java.lang.Object ref = serviceName_;
372 | if (ref instanceof java.lang.String) {
373 | return (java.lang.String) ref;
374 | } else {
375 | com.google.protobuf.ByteString bs =
376 | (com.google.protobuf.ByteString) ref;
377 | java.lang.String s = bs.toStringUtf8();
378 | serviceName_ = s;
379 | return s;
380 | }
381 | }
382 | /**
383 | * string service_name = 1;
384 | * @return The bytes for serviceName.
385 | */
386 | @java.lang.Override
387 | public com.google.protobuf.ByteString
388 | getServiceNameBytes() {
389 | java.lang.Object ref = serviceName_;
390 | if (ref instanceof java.lang.String) {
391 | com.google.protobuf.ByteString b =
392 | com.google.protobuf.ByteString.copyFromUtf8(
393 | (java.lang.String) ref);
394 | serviceName_ = b;
395 | return b;
396 | } else {
397 | return (com.google.protobuf.ByteString) ref;
398 | }
399 | }
400 |
401 | public static final int METHOD_ID_FIELD_NUMBER = 2;
402 | private int methodId_ = 0;
403 | /**
404 | * int32 method_id = 2;
405 | * @return The methodId.
406 | */
407 | @java.lang.Override
408 | public int getMethodId() {
409 | return methodId_;
410 | }
411 |
412 | public static final int CONTENT_FIELD_NUMBER = 3;
413 | private com.google.protobuf.ByteString content_ = com.google.protobuf.ByteString.EMPTY;
414 | /**
415 | * bytes content = 3;
416 | * @return The content.
417 | */
418 | @java.lang.Override
419 | public com.google.protobuf.ByteString getContent() {
420 | return content_;
421 | }
422 |
423 | public static final int STATUS_FIELD_NUMBER = 4;
424 | private int status_ = 0;
425 | /**
426 | * .qrpc.meta.Status status = 4;
427 | * @return The enum numeric value on the wire for status.
428 | */
429 | @java.lang.Override public int getStatusValue() {
430 | return status_;
431 | }
432 | /**
433 | * .qrpc.meta.Status status = 4;
434 | * @return The status.
435 | */
436 | @java.lang.Override public org.qrpc.Meta.Status getStatus() {
437 | org.qrpc.Meta.Status result = org.qrpc.Meta.Status.forNumber(status_);
438 | return result == null ? org.qrpc.Meta.Status.UNRECOGNIZED : result;
439 | }
440 |
441 | public static final int TYPE_FIELD_NUMBER = 5;
442 | private int type_ = 0;
443 | /**
444 | * .qrpc.meta.Type type = 5;
445 | * @return The enum numeric value on the wire for type.
446 | */
447 | @java.lang.Override public int getTypeValue() {
448 | return type_;
449 | }
450 | /**
451 | * .qrpc.meta.Type type = 5;
452 | * @return The type.
453 | */
454 | @java.lang.Override public org.qrpc.Meta.Type getType() {
455 | org.qrpc.Meta.Type result = org.qrpc.Meta.Type.forNumber(type_);
456 | return result == null ? org.qrpc.Meta.Type.UNRECOGNIZED : result;
457 | }
458 |
459 | public static final int REQUEST_ID_FIELD_NUMBER = 6;
460 | @SuppressWarnings("serial")
461 | private volatile java.lang.Object requestId_ = "";
462 | /**
463 | * string request_id = 6;
464 | * @return The requestId.
465 | */
466 | @java.lang.Override
467 | public java.lang.String getRequestId() {
468 | java.lang.Object ref = requestId_;
469 | if (ref instanceof java.lang.String) {
470 | return (java.lang.String) ref;
471 | } else {
472 | com.google.protobuf.ByteString bs =
473 | (com.google.protobuf.ByteString) ref;
474 | java.lang.String s = bs.toStringUtf8();
475 | requestId_ = s;
476 | return s;
477 | }
478 | }
479 | /**
480 | * string request_id = 6;
481 | * @return The bytes for requestId.
482 | */
483 | @java.lang.Override
484 | public com.google.protobuf.ByteString
485 | getRequestIdBytes() {
486 | java.lang.Object ref = requestId_;
487 | if (ref instanceof java.lang.String) {
488 | com.google.protobuf.ByteString b =
489 | com.google.protobuf.ByteString.copyFromUtf8(
490 | (java.lang.String) ref);
491 | requestId_ = b;
492 | return b;
493 | } else {
494 | return (com.google.protobuf.ByteString) ref;
495 | }
496 | }
497 |
498 | private byte memoizedIsInitialized = -1;
499 | @java.lang.Override
500 | public final boolean isInitialized() {
501 | byte isInitialized = memoizedIsInitialized;
502 | if (isInitialized == 1) return true;
503 | if (isInitialized == 0) return false;
504 |
505 | memoizedIsInitialized = 1;
506 | return true;
507 | }
508 |
509 | @java.lang.Override
510 | public void writeTo(com.google.protobuf.CodedOutputStream output)
511 | throws java.io.IOException {
512 | if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(serviceName_)) {
513 | com.google.protobuf.GeneratedMessageV3.writeString(output, 1, serviceName_);
514 | }
515 | if (methodId_ != 0) {
516 | output.writeInt32(2, methodId_);
517 | }
518 | if (!content_.isEmpty()) {
519 | output.writeBytes(3, content_);
520 | }
521 | if (status_ != org.qrpc.Meta.Status.SUCCESS.getNumber()) {
522 | output.writeEnum(4, status_);
523 | }
524 | if (type_ != org.qrpc.Meta.Type.REQUEST.getNumber()) {
525 | output.writeEnum(5, type_);
526 | }
527 | if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(requestId_)) {
528 | com.google.protobuf.GeneratedMessageV3.writeString(output, 6, requestId_);
529 | }
530 | getUnknownFields().writeTo(output);
531 | }
532 |
533 | @java.lang.Override
534 | public int getSerializedSize() {
535 | int size = memoizedSize;
536 | if (size != -1) return size;
537 |
538 | size = 0;
539 | if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(serviceName_)) {
540 | size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, serviceName_);
541 | }
542 | if (methodId_ != 0) {
543 | size += com.google.protobuf.CodedOutputStream
544 | .computeInt32Size(2, methodId_);
545 | }
546 | if (!content_.isEmpty()) {
547 | size += com.google.protobuf.CodedOutputStream
548 | .computeBytesSize(3, content_);
549 | }
550 | if (status_ != org.qrpc.Meta.Status.SUCCESS.getNumber()) {
551 | size += com.google.protobuf.CodedOutputStream
552 | .computeEnumSize(4, status_);
553 | }
554 | if (type_ != org.qrpc.Meta.Type.REQUEST.getNumber()) {
555 | size += com.google.protobuf.CodedOutputStream
556 | .computeEnumSize(5, type_);
557 | }
558 | if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(requestId_)) {
559 | size += com.google.protobuf.GeneratedMessageV3.computeStringSize(6, requestId_);
560 | }
561 | size += getUnknownFields().getSerializedSize();
562 | memoizedSize = size;
563 | return size;
564 | }
565 |
566 | @java.lang.Override
567 | public boolean equals(final java.lang.Object obj) {
568 | if (obj == this) {
569 | return true;
570 | }
571 | if (!(obj instanceof org.qrpc.Meta.RpcMetaData)) {
572 | return super.equals(obj);
573 | }
574 | org.qrpc.Meta.RpcMetaData other = (org.qrpc.Meta.RpcMetaData) obj;
575 |
576 | if (!getServiceName()
577 | .equals(other.getServiceName())) return false;
578 | if (getMethodId()
579 | != other.getMethodId()) return false;
580 | if (!getContent()
581 | .equals(other.getContent())) return false;
582 | if (status_ != other.status_) return false;
583 | if (type_ != other.type_) return false;
584 | if (!getRequestId()
585 | .equals(other.getRequestId())) return false;
586 | if (!getUnknownFields().equals(other.getUnknownFields())) return false;
587 | return true;
588 | }
589 |
590 | @java.lang.Override
591 | public int hashCode() {
592 | if (memoizedHashCode != 0) {
593 | return memoizedHashCode;
594 | }
595 | int hash = 41;
596 | hash = (19 * hash) + getDescriptor().hashCode();
597 | hash = (37 * hash) + SERVICE_NAME_FIELD_NUMBER;
598 | hash = (53 * hash) + getServiceName().hashCode();
599 | hash = (37 * hash) + METHOD_ID_FIELD_NUMBER;
600 | hash = (53 * hash) + getMethodId();
601 | hash = (37 * hash) + CONTENT_FIELD_NUMBER;
602 | hash = (53 * hash) + getContent().hashCode();
603 | hash = (37 * hash) + STATUS_FIELD_NUMBER;
604 | hash = (53 * hash) + status_;
605 | hash = (37 * hash) + TYPE_FIELD_NUMBER;
606 | hash = (53 * hash) + type_;
607 | hash = (37 * hash) + REQUEST_ID_FIELD_NUMBER;
608 | hash = (53 * hash) + getRequestId().hashCode();
609 | hash = (29 * hash) + getUnknownFields().hashCode();
610 | memoizedHashCode = hash;
611 | return hash;
612 | }
613 |
614 | public static org.qrpc.Meta.RpcMetaData parseFrom(
615 | java.nio.ByteBuffer data)
616 | throws com.google.protobuf.InvalidProtocolBufferException {
617 | return PARSER.parseFrom(data);
618 | }
619 | public static org.qrpc.Meta.RpcMetaData parseFrom(
620 | java.nio.ByteBuffer data,
621 | com.google.protobuf.ExtensionRegistryLite extensionRegistry)
622 | throws com.google.protobuf.InvalidProtocolBufferException {
623 | return PARSER.parseFrom(data, extensionRegistry);
624 | }
625 | public static org.qrpc.Meta.RpcMetaData parseFrom(
626 | com.google.protobuf.ByteString data)
627 | throws com.google.protobuf.InvalidProtocolBufferException {
628 | return PARSER.parseFrom(data);
629 | }
630 | public static org.qrpc.Meta.RpcMetaData parseFrom(
631 | com.google.protobuf.ByteString data,
632 | com.google.protobuf.ExtensionRegistryLite extensionRegistry)
633 | throws com.google.protobuf.InvalidProtocolBufferException {
634 | return PARSER.parseFrom(data, extensionRegistry);
635 | }
636 | public static org.qrpc.Meta.RpcMetaData parseFrom(byte[] data)
637 | throws com.google.protobuf.InvalidProtocolBufferException {
638 | return PARSER.parseFrom(data);
639 | }
640 | public static org.qrpc.Meta.RpcMetaData parseFrom(
641 | byte[] data,
642 | com.google.protobuf.ExtensionRegistryLite extensionRegistry)
643 | throws com.google.protobuf.InvalidProtocolBufferException {
644 | return PARSER.parseFrom(data, extensionRegistry);
645 | }
646 | public static org.qrpc.Meta.RpcMetaData parseFrom(java.io.InputStream input)
647 | throws java.io.IOException {
648 | return com.google.protobuf.GeneratedMessageV3
649 | .parseWithIOException(PARSER, input);
650 | }
651 | public static org.qrpc.Meta.RpcMetaData parseFrom(
652 | java.io.InputStream input,
653 | com.google.protobuf.ExtensionRegistryLite extensionRegistry)
654 | throws java.io.IOException {
655 | return com.google.protobuf.GeneratedMessageV3
656 | .parseWithIOException(PARSER, input, extensionRegistry);
657 | }
658 |
659 | public static org.qrpc.Meta.RpcMetaData parseDelimitedFrom(java.io.InputStream input)
660 | throws java.io.IOException {
661 | return com.google.protobuf.GeneratedMessageV3
662 | .parseDelimitedWithIOException(PARSER, input);
663 | }
664 |
665 | public static org.qrpc.Meta.RpcMetaData parseDelimitedFrom(
666 | java.io.InputStream input,
667 | com.google.protobuf.ExtensionRegistryLite extensionRegistry)
668 | throws java.io.IOException {
669 | return com.google.protobuf.GeneratedMessageV3
670 | .parseDelimitedWithIOException(PARSER, input, extensionRegistry);
671 | }
672 | public static org.qrpc.Meta.RpcMetaData parseFrom(
673 | com.google.protobuf.CodedInputStream input)
674 | throws java.io.IOException {
675 | return com.google.protobuf.GeneratedMessageV3
676 | .parseWithIOException(PARSER, input);
677 | }
678 | public static org.qrpc.Meta.RpcMetaData parseFrom(
679 | com.google.protobuf.CodedInputStream input,
680 | com.google.protobuf.ExtensionRegistryLite extensionRegistry)
681 | throws java.io.IOException {
682 | return com.google.protobuf.GeneratedMessageV3
683 | .parseWithIOException(PARSER, input, extensionRegistry);
684 | }
685 |
686 | @java.lang.Override
687 | public Builder newBuilderForType() { return newBuilder(); }
688 | public static Builder newBuilder() {
689 | return DEFAULT_INSTANCE.toBuilder();
690 | }
691 | public static Builder newBuilder(org.qrpc.Meta.RpcMetaData prototype) {
692 | return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
693 | }
694 | @java.lang.Override
695 | public Builder toBuilder() {
696 | return this == DEFAULT_INSTANCE
697 | ? new Builder() : new Builder().mergeFrom(this);
698 | }
699 |
700 | @java.lang.Override
701 | protected Builder newBuilderForType(
702 | com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
703 | Builder builder = new Builder(parent);
704 | return builder;
705 | }
706 | /**
707 | * Protobuf type {@code qrpc.meta.RpcMetaData}
708 | */
709 | public static final class Builder extends
710 | com.google.protobuf.GeneratedMessageV3.Builder implements
711 | // @@protoc_insertion_point(builder_implements:qrpc.meta.RpcMetaData)
712 | org.qrpc.Meta.RpcMetaDataOrBuilder {
713 | public static final com.google.protobuf.Descriptors.Descriptor
714 | getDescriptor() {
715 | return org.qrpc.Meta.internal_static_qrpc_meta_RpcMetaData_descriptor;
716 | }
717 |
718 | @java.lang.Override
719 | protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
720 | internalGetFieldAccessorTable() {
721 | return org.qrpc.Meta.internal_static_qrpc_meta_RpcMetaData_fieldAccessorTable
722 | .ensureFieldAccessorsInitialized(
723 | org.qrpc.Meta.RpcMetaData.class, org.qrpc.Meta.RpcMetaData.Builder.class);
724 | }
725 |
726 | // Construct using org.qrpc.Meta.RpcMetaData.newBuilder()
727 | private Builder() {
728 |
729 | }
730 |
731 | private Builder(
732 | com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
733 | super(parent);
734 |
735 | }
736 | @java.lang.Override
737 | public Builder clear() {
738 | super.clear();
739 | bitField0_ = 0;
740 | serviceName_ = "";
741 | methodId_ = 0;
742 | content_ = com.google.protobuf.ByteString.EMPTY;
743 | status_ = 0;
744 | type_ = 0;
745 | requestId_ = "";
746 | return this;
747 | }
748 |
749 | @java.lang.Override
750 | public com.google.protobuf.Descriptors.Descriptor
751 | getDescriptorForType() {
752 | return org.qrpc.Meta.internal_static_qrpc_meta_RpcMetaData_descriptor;
753 | }
754 |
755 | @java.lang.Override
756 | public org.qrpc.Meta.RpcMetaData getDefaultInstanceForType() {
757 | return org.qrpc.Meta.RpcMetaData.getDefaultInstance();
758 | }
759 |
760 | @java.lang.Override
761 | public org.qrpc.Meta.RpcMetaData build() {
762 | org.qrpc.Meta.RpcMetaData result = buildPartial();
763 | if (!result.isInitialized()) {
764 | throw newUninitializedMessageException(result);
765 | }
766 | return result;
767 | }
768 |
769 | @java.lang.Override
770 | public org.qrpc.Meta.RpcMetaData buildPartial() {
771 | org.qrpc.Meta.RpcMetaData result = new org.qrpc.Meta.RpcMetaData(this);
772 | if (bitField0_ != 0) { buildPartial0(result); }
773 | onBuilt();
774 | return result;
775 | }
776 |
777 | private void buildPartial0(org.qrpc.Meta.RpcMetaData result) {
778 | int from_bitField0_ = bitField0_;
779 | if (((from_bitField0_ & 0x00000001) != 0)) {
780 | result.serviceName_ = serviceName_;
781 | }
782 | if (((from_bitField0_ & 0x00000002) != 0)) {
783 | result.methodId_ = methodId_;
784 | }
785 | if (((from_bitField0_ & 0x00000004) != 0)) {
786 | result.content_ = content_;
787 | }
788 | if (((from_bitField0_ & 0x00000008) != 0)) {
789 | result.status_ = status_;
790 | }
791 | if (((from_bitField0_ & 0x00000010) != 0)) {
792 | result.type_ = type_;
793 | }
794 | if (((from_bitField0_ & 0x00000020) != 0)) {
795 | result.requestId_ = requestId_;
796 | }
797 | }
798 |
799 | @java.lang.Override
800 | public Builder mergeFrom(com.google.protobuf.Message other) {
801 | if (other instanceof org.qrpc.Meta.RpcMetaData) {
802 | return mergeFrom((org.qrpc.Meta.RpcMetaData)other);
803 | } else {
804 | super.mergeFrom(other);
805 | return this;
806 | }
807 | }
808 |
809 | public Builder mergeFrom(org.qrpc.Meta.RpcMetaData other) {
810 | if (other == org.qrpc.Meta.RpcMetaData.getDefaultInstance()) return this;
811 | if (!other.getServiceName().isEmpty()) {
812 | serviceName_ = other.serviceName_;
813 | bitField0_ |= 0x00000001;
814 | onChanged();
815 | }
816 | if (other.getMethodId() != 0) {
817 | setMethodId(other.getMethodId());
818 | }
819 | if (other.getContent() != com.google.protobuf.ByteString.EMPTY) {
820 | setContent(other.getContent());
821 | }
822 | if (other.status_ != 0) {
823 | setStatusValue(other.getStatusValue());
824 | }
825 | if (other.type_ != 0) {
826 | setTypeValue(other.getTypeValue());
827 | }
828 | if (!other.getRequestId().isEmpty()) {
829 | requestId_ = other.requestId_;
830 | bitField0_ |= 0x00000020;
831 | onChanged();
832 | }
833 | this.mergeUnknownFields(other.getUnknownFields());
834 | onChanged();
835 | return this;
836 | }
837 |
838 | @java.lang.Override
839 | public final boolean isInitialized() {
840 | return true;
841 | }
842 |
843 | @java.lang.Override
844 | public Builder mergeFrom(
845 | com.google.protobuf.CodedInputStream input,
846 | com.google.protobuf.ExtensionRegistryLite extensionRegistry)
847 | throws java.io.IOException {
848 | if (extensionRegistry == null) {
849 | throw new java.lang.NullPointerException();
850 | }
851 | try {
852 | boolean done = false;
853 | while (!done) {
854 | int tag = input.readTag();
855 | switch (tag) {
856 | case 0:
857 | done = true;
858 | break;
859 | case 10: {
860 | serviceName_ = input.readStringRequireUtf8();
861 | bitField0_ |= 0x00000001;
862 | break;
863 | } // case 10
864 | case 16: {
865 | methodId_ = input.readInt32();
866 | bitField0_ |= 0x00000002;
867 | break;
868 | } // case 16
869 | case 26: {
870 | content_ = input.readBytes();
871 | bitField0_ |= 0x00000004;
872 | break;
873 | } // case 26
874 | case 32: {
875 | status_ = input.readEnum();
876 | bitField0_ |= 0x00000008;
877 | break;
878 | } // case 32
879 | case 40: {
880 | type_ = input.readEnum();
881 | bitField0_ |= 0x00000010;
882 | break;
883 | } // case 40
884 | case 50: {
885 | requestId_ = input.readStringRequireUtf8();
886 | bitField0_ |= 0x00000020;
887 | break;
888 | } // case 50
889 | default: {
890 | if (!super.parseUnknownField(input, extensionRegistry, tag)) {
891 | done = true; // was an endgroup tag
892 | }
893 | break;
894 | } // default:
895 | } // switch (tag)
896 | } // while (!done)
897 | } catch (com.google.protobuf.InvalidProtocolBufferException e) {
898 | throw e.unwrapIOException();
899 | } finally {
900 | onChanged();
901 | } // finally
902 | return this;
903 | }
904 | private int bitField0_;
905 |
906 | private java.lang.Object serviceName_ = "";
907 | /**
908 | * string service_name = 1;
909 | * @return The serviceName.
910 | */
911 | public java.lang.String getServiceName() {
912 | java.lang.Object ref = serviceName_;
913 | if (!(ref instanceof java.lang.String)) {
914 | com.google.protobuf.ByteString bs =
915 | (com.google.protobuf.ByteString) ref;
916 | java.lang.String s = bs.toStringUtf8();
917 | serviceName_ = s;
918 | return s;
919 | } else {
920 | return (java.lang.String) ref;
921 | }
922 | }
923 | /**
924 | * string service_name = 1;
925 | * @return The bytes for serviceName.
926 | */
927 | public com.google.protobuf.ByteString
928 | getServiceNameBytes() {
929 | java.lang.Object ref = serviceName_;
930 | if (ref instanceof String) {
931 | com.google.protobuf.ByteString b =
932 | com.google.protobuf.ByteString.copyFromUtf8(
933 | (java.lang.String) ref);
934 | serviceName_ = b;
935 | return b;
936 | } else {
937 | return (com.google.protobuf.ByteString) ref;
938 | }
939 | }
940 | /**
941 | * string service_name = 1;
942 | * @param value The serviceName to set.
943 | * @return This builder for chaining.
944 | */
945 | public Builder setServiceName(
946 | java.lang.String value) {
947 | if (value == null) { throw new NullPointerException(); }
948 | serviceName_ = value;
949 | bitField0_ |= 0x00000001;
950 | onChanged();
951 | return this;
952 | }
953 | /**
954 | * string service_name = 1;
955 | * @return This builder for chaining.
956 | */
957 | public Builder clearServiceName() {
958 | serviceName_ = getDefaultInstance().getServiceName();
959 | bitField0_ = (bitField0_ & ~0x00000001);
960 | onChanged();
961 | return this;
962 | }
963 | /**
964 | * string service_name = 1;
965 | * @param value The bytes for serviceName to set.
966 | * @return This builder for chaining.
967 | */
968 | public Builder setServiceNameBytes(
969 | com.google.protobuf.ByteString value) {
970 | if (value == null) { throw new NullPointerException(); }
971 | checkByteStringIsUtf8(value);
972 | serviceName_ = value;
973 | bitField0_ |= 0x00000001;
974 | onChanged();
975 | return this;
976 | }
977 |
978 | private int methodId_ ;
979 | /**
980 | * int32 method_id = 2;
981 | * @return The methodId.
982 | */
983 | @java.lang.Override
984 | public int getMethodId() {
985 | return methodId_;
986 | }
987 | /**
988 | * int32 method_id = 2;
989 | * @param value The methodId to set.
990 | * @return This builder for chaining.
991 | */
992 | public Builder setMethodId(int value) {
993 |
994 | methodId_ = value;
995 | bitField0_ |= 0x00000002;
996 | onChanged();
997 | return this;
998 | }
999 | /**
1000 | * int32 method_id = 2;
1001 | * @return This builder for chaining.
1002 | */
1003 | public Builder clearMethodId() {
1004 | bitField0_ = (bitField0_ & ~0x00000002);
1005 | methodId_ = 0;
1006 | onChanged();
1007 | return this;
1008 | }
1009 |
1010 | private com.google.protobuf.ByteString content_ = com.google.protobuf.ByteString.EMPTY;
1011 | /**
1012 | * bytes content = 3;
1013 | * @return The content.
1014 | */
1015 | @java.lang.Override
1016 | public com.google.protobuf.ByteString getContent() {
1017 | return content_;
1018 | }
1019 | /**
1020 | * bytes content = 3;
1021 | * @param value The content to set.
1022 | * @return This builder for chaining.
1023 | */
1024 | public Builder setContent(com.google.protobuf.ByteString value) {
1025 | if (value == null) { throw new NullPointerException(); }
1026 | content_ = value;
1027 | bitField0_ |= 0x00000004;
1028 | onChanged();
1029 | return this;
1030 | }
1031 | /**
1032 | * bytes content = 3;
1033 | * @return This builder for chaining.
1034 | */
1035 | public Builder clearContent() {
1036 | bitField0_ = (bitField0_ & ~0x00000004);
1037 | content_ = getDefaultInstance().getContent();
1038 | onChanged();
1039 | return this;
1040 | }
1041 |
1042 | private int status_ = 0;
1043 | /**
1044 | * .qrpc.meta.Status status = 4;
1045 | * @return The enum numeric value on the wire for status.
1046 | */
1047 | @java.lang.Override public int getStatusValue() {
1048 | return status_;
1049 | }
1050 | /**
1051 | * .qrpc.meta.Status status = 4;
1052 | * @param value The enum numeric value on the wire for status to set.
1053 | * @return This builder for chaining.
1054 | */
1055 | public Builder setStatusValue(int value) {
1056 | status_ = value;
1057 | bitField0_ |= 0x00000008;
1058 | onChanged();
1059 | return this;
1060 | }
1061 | /**
1062 | * .qrpc.meta.Status status = 4;
1063 | * @return The status.
1064 | */
1065 | @java.lang.Override
1066 | public org.qrpc.Meta.Status getStatus() {
1067 | org.qrpc.Meta.Status result = org.qrpc.Meta.Status.forNumber(status_);
1068 | return result == null ? org.qrpc.Meta.Status.UNRECOGNIZED : result;
1069 | }
1070 | /**
1071 | * .qrpc.meta.Status status = 4;
1072 | * @param value The status to set.
1073 | * @return This builder for chaining.
1074 | */
1075 | public Builder setStatus(org.qrpc.Meta.Status value) {
1076 | if (value == null) {
1077 | throw new NullPointerException();
1078 | }
1079 | bitField0_ |= 0x00000008;
1080 | status_ = value.getNumber();
1081 | onChanged();
1082 | return this;
1083 | }
1084 | /**
1085 | * .qrpc.meta.Status status = 4;
1086 | * @return This builder for chaining.
1087 | */
1088 | public Builder clearStatus() {
1089 | bitField0_ = (bitField0_ & ~0x00000008);
1090 | status_ = 0;
1091 | onChanged();
1092 | return this;
1093 | }
1094 |
1095 | private int type_ = 0;
1096 | /**
1097 | * .qrpc.meta.Type type = 5;
1098 | * @return The enum numeric value on the wire for type.
1099 | */
1100 | @java.lang.Override public int getTypeValue() {
1101 | return type_;
1102 | }
1103 | /**
1104 | * .qrpc.meta.Type type = 5;
1105 | * @param value The enum numeric value on the wire for type to set.
1106 | * @return This builder for chaining.
1107 | */
1108 | public Builder setTypeValue(int value) {
1109 | type_ = value;
1110 | bitField0_ |= 0x00000010;
1111 | onChanged();
1112 | return this;
1113 | }
1114 | /**
1115 | * .qrpc.meta.Type type = 5;
1116 | * @return The type.
1117 | */
1118 | @java.lang.Override
1119 | public org.qrpc.Meta.Type getType() {
1120 | org.qrpc.Meta.Type result = org.qrpc.Meta.Type.forNumber(type_);
1121 | return result == null ? org.qrpc.Meta.Type.UNRECOGNIZED : result;
1122 | }
1123 | /**
1124 | * .qrpc.meta.Type type = 5;
1125 | * @param value The type to set.
1126 | * @return This builder for chaining.
1127 | */
1128 | public Builder setType(org.qrpc.Meta.Type value) {
1129 | if (value == null) {
1130 | throw new NullPointerException();
1131 | }
1132 | bitField0_ |= 0x00000010;
1133 | type_ = value.getNumber();
1134 | onChanged();
1135 | return this;
1136 | }
1137 | /**
1138 | * .qrpc.meta.Type type = 5;
1139 | * @return This builder for chaining.
1140 | */
1141 | public Builder clearType() {
1142 | bitField0_ = (bitField0_ & ~0x00000010);
1143 | type_ = 0;
1144 | onChanged();
1145 | return this;
1146 | }
1147 |
1148 | private java.lang.Object requestId_ = "";
1149 | /**
1150 | * string request_id = 6;
1151 | * @return The requestId.
1152 | */
1153 | public java.lang.String getRequestId() {
1154 | java.lang.Object ref = requestId_;
1155 | if (!(ref instanceof java.lang.String)) {
1156 | com.google.protobuf.ByteString bs =
1157 | (com.google.protobuf.ByteString) ref;
1158 | java.lang.String s = bs.toStringUtf8();
1159 | requestId_ = s;
1160 | return s;
1161 | } else {
1162 | return (java.lang.String) ref;
1163 | }
1164 | }
1165 | /**
1166 | * string request_id = 6;
1167 | * @return The bytes for requestId.
1168 | */
1169 | public com.google.protobuf.ByteString
1170 | getRequestIdBytes() {
1171 | java.lang.Object ref = requestId_;
1172 | if (ref instanceof String) {
1173 | com.google.protobuf.ByteString b =
1174 | com.google.protobuf.ByteString.copyFromUtf8(
1175 | (java.lang.String) ref);
1176 | requestId_ = b;
1177 | return b;
1178 | } else {
1179 | return (com.google.protobuf.ByteString) ref;
1180 | }
1181 | }
1182 | /**
1183 | * string request_id = 6;
1184 | * @param value The requestId to set.
1185 | * @return This builder for chaining.
1186 | */
1187 | public Builder setRequestId(
1188 | java.lang.String value) {
1189 | if (value == null) { throw new NullPointerException(); }
1190 | requestId_ = value;
1191 | bitField0_ |= 0x00000020;
1192 | onChanged();
1193 | return this;
1194 | }
1195 | /**
1196 | * string request_id = 6;
1197 | * @return This builder for chaining.
1198 | */
1199 | public Builder clearRequestId() {
1200 | requestId_ = getDefaultInstance().getRequestId();
1201 | bitField0_ = (bitField0_ & ~0x00000020);
1202 | onChanged();
1203 | return this;
1204 | }
1205 | /**
1206 | * string request_id = 6;
1207 | * @param value The bytes for requestId to set.
1208 | * @return This builder for chaining.
1209 | */
1210 | public Builder setRequestIdBytes(
1211 | com.google.protobuf.ByteString value) {
1212 | if (value == null) { throw new NullPointerException(); }
1213 | checkByteStringIsUtf8(value);
1214 | requestId_ = value;
1215 | bitField0_ |= 0x00000020;
1216 | onChanged();
1217 | return this;
1218 | }
1219 | @java.lang.Override
1220 | public final Builder setUnknownFields(
1221 | final com.google.protobuf.UnknownFieldSet unknownFields) {
1222 | return super.setUnknownFields(unknownFields);
1223 | }
1224 |
1225 | @java.lang.Override
1226 | public final Builder mergeUnknownFields(
1227 | final com.google.protobuf.UnknownFieldSet unknownFields) {
1228 | return super.mergeUnknownFields(unknownFields);
1229 | }
1230 |
1231 |
1232 | // @@protoc_insertion_point(builder_scope:qrpc.meta.RpcMetaData)
1233 | }
1234 |
1235 | // @@protoc_insertion_point(class_scope:qrpc.meta.RpcMetaData)
1236 | private static final org.qrpc.Meta.RpcMetaData DEFAULT_INSTANCE;
1237 | static {
1238 | DEFAULT_INSTANCE = new org.qrpc.Meta.RpcMetaData();
1239 | }
1240 |
1241 | public static org.qrpc.Meta.RpcMetaData getDefaultInstance() {
1242 | return DEFAULT_INSTANCE;
1243 | }
1244 |
1245 | private static final com.google.protobuf.Parser
1246 | PARSER = new com.google.protobuf.AbstractParser() {
1247 | @java.lang.Override
1248 | public RpcMetaData parsePartialFrom(
1249 | com.google.protobuf.CodedInputStream input,
1250 | com.google.protobuf.ExtensionRegistryLite extensionRegistry)
1251 | throws com.google.protobuf.InvalidProtocolBufferException {
1252 | Builder builder = newBuilder();
1253 | try {
1254 | builder.mergeFrom(input, extensionRegistry);
1255 | } catch (com.google.protobuf.InvalidProtocolBufferException e) {
1256 | throw e.setUnfinishedMessage(builder.buildPartial());
1257 | } catch (com.google.protobuf.UninitializedMessageException e) {
1258 | throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial());
1259 | } catch (java.io.IOException e) {
1260 | throw new com.google.protobuf.InvalidProtocolBufferException(e)
1261 | .setUnfinishedMessage(builder.buildPartial());
1262 | }
1263 | return builder.buildPartial();
1264 | }
1265 | };
1266 |
1267 | public static com.google.protobuf.Parser parser() {
1268 | return PARSER;
1269 | }
1270 |
1271 | @java.lang.Override
1272 | public com.google.protobuf.Parser getParserForType() {
1273 | return PARSER;
1274 | }
1275 |
1276 | @java.lang.Override
1277 | public org.qrpc.Meta.RpcMetaData getDefaultInstanceForType() {
1278 | return DEFAULT_INSTANCE;
1279 | }
1280 |
1281 | }
1282 |
1283 | private static final com.google.protobuf.Descriptors.Descriptor
1284 | internal_static_qrpc_meta_RpcMetaData_descriptor;
1285 | private static final
1286 | com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
1287 | internal_static_qrpc_meta_RpcMetaData_fieldAccessorTable;
1288 |
1289 | public static com.google.protobuf.Descriptors.FileDescriptor
1290 | getDescriptor() {
1291 | return descriptor;
1292 | }
1293 | private static com.google.protobuf.Descriptors.FileDescriptor
1294 | descriptor;
1295 | static {
1296 | java.lang.String[] descriptorData = {
1297 | "\n\nmeta.proto\022\tqrpc.meta\"\235\001\n\013RpcMetaData\022" +
1298 | "\024\n\014service_name\030\001 \001(\t\022\021\n\tmethod_id\030\002 \001(\005" +
1299 | "\022\017\n\007content\030\003 \001(\014\022!\n\006status\030\004 \001(\0162\021.qrpc" +
1300 | ".meta.Status\022\035\n\004type\030\005 \001(\0162\017.qrpc.meta.T" +
1301 | "ype\022\022\n\nrequest_id\030\006 \001(\t*L\n\006Status\022\013\n\007SUC" +
1302 | "CESS\020\000\022\014\n\010TIME_OUT\020\002\022\025\n\021SERVICE_NOT_FOUN" +
1303 | "D\020\003\022\020\n\014SYSTEM_ERROR\020\004**\n\004Type\022\013\n\007REQUEST" +
1304 | "\020\000\022\013\n\007RESPOND\020\001\022\010\n\004PEER\020\002B\022\n\010org.qrpcB\004M" +
1305 | "etaP\000b\006proto3"
1306 | };
1307 | descriptor = com.google.protobuf.Descriptors.FileDescriptor
1308 | .internalBuildGeneratedFileFrom(descriptorData,
1309 | new com.google.protobuf.Descriptors.FileDescriptor[] {
1310 | });
1311 | internal_static_qrpc_meta_RpcMetaData_descriptor =
1312 | getDescriptor().getMessageTypes().get(0);
1313 | internal_static_qrpc_meta_RpcMetaData_fieldAccessorTable = new
1314 | com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
1315 | internal_static_qrpc_meta_RpcMetaData_descriptor,
1316 | new java.lang.String[] { "ServiceName", "MethodId", "Content", "Status", "Type", "RequestId", });
1317 | }
1318 |
1319 | // @@protoc_insertion_point(outer_class_scope)
1320 | }
1321 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/PropertyKeys.java:
--------------------------------------------------------------------------------
1 | package org.qrpc;
2 |
3 | /**
4 | * @author Yang Lianhuan
5 | * @version 1.0.0
6 | * @since 2023/4/4
7 | **/
8 | public class PropertyKeys {
9 | public static final String EVENT_LOOP_BOSS_THREAD = "qrpc.event_loop_boos_thread";
10 | public static final String EVENT_LOOP_WORK_THREAD = "qrpc.event_loop_work_thread";
11 | public static final String SERVER_PORT = "qrpc.server.port";
12 | public static final String CLIENT_TIMEOUT = "qrpc.client.timeout";
13 | }
14 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/RpcStatus.java:
--------------------------------------------------------------------------------
1 | package org.qrpc;
2 |
3 | /**
4 | * @author Yang Lianhuan
5 | * @version 1.0.0
6 | * @since 2024/1/27
7 | **/
8 | public enum RpcStatus {
9 | /**
10 | * 初始化
11 | */
12 | INIT,
13 |
14 | /**
15 | * 成功
16 | */
17 | SUCCESS,
18 |
19 | /**
20 | * 失败
21 | */
22 | FAILED,
23 |
24 | /**
25 | * 取消中
26 | */
27 | CANCELING,
28 |
29 | /**
30 | * 已取消
31 | */
32 | CANCELED
33 | }
34 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/ThreadService.java:
--------------------------------------------------------------------------------
1 | package org.qrpc;
2 |
3 | import io.netty.channel.EventLoopGroup;
4 | import io.netty.channel.nio.NioEventLoopGroup;
5 |
6 | import java.util.concurrent.*;
7 |
8 | /**
9 | * @author Yang Lianhuan
10 | * @version 1.0.0
11 | * @since 2023/4/6
12 | **/
13 | public class ThreadService {
14 | private volatile static EventLoopGroup serverWorkEventLoopGroup;
15 | private volatile static EventLoopGroup clientEventLoopGroup;
16 | private volatile static EventLoopGroup serverBossEventLoopGroup;
17 | private volatile static ExecutorService businessExecutor;
18 | private static final int processors;
19 | private static final int clientThreadNum;
20 | private static final int serverBossThreadNum;
21 | private static final int serverWorkThreadNum;
22 | private static final int coreThread;
23 | private static final int maxThread;
24 | private static final BlockingQueue workQueue;
25 |
26 | static {
27 | processors = Runtime.getRuntime().availableProcessors();
28 | clientThreadNum = Math.min(Math.max(1, processors/4), 4);
29 | serverBossThreadNum = Math.max(processors/4, 1);
30 | serverWorkThreadNum = Math.max(6, processors * 3);
31 | coreThread = processors * 3;
32 | maxThread = processors * 10;
33 | workQueue = new LinkedBlockingQueue<>();
34 | }
35 |
36 | /**
37 | * 获取Reactor线程组
38 | *
39 | * @return BossEventLoopGroup
40 | */
41 | public static EventLoopGroup getServerBossEventLoopGroup() {
42 | if (serverBossEventLoopGroup != null && !serverBossEventLoopGroup.isShutdown()
43 | && !serverBossEventLoopGroup.isTerminated()) {
44 | return serverBossEventLoopGroup;
45 | }
46 | synchronized (ThreadService.class) {
47 | if (serverBossEventLoopGroup != null && !serverBossEventLoopGroup.isShutdown()
48 | && !serverBossEventLoopGroup.isTerminated()) {
49 | return serverBossEventLoopGroup;
50 | }
51 | serverBossEventLoopGroup = new NioEventLoopGroup(serverBossThreadNum);
52 | return serverBossEventLoopGroup;
53 | }
54 | }
55 |
56 | /**
57 | * 获取工作IO线程组
58 | *
59 | * @return ServerWorkEventLoopGroup
60 | */
61 | public static EventLoopGroup getServerWorkEventLoopGroup() {
62 | if (serverWorkEventLoopGroup != null && !serverWorkEventLoopGroup.isTerminated()
63 | && !serverWorkEventLoopGroup.isShutdown()) {
64 | return serverWorkEventLoopGroup;
65 | }
66 | synchronized (ThreadService.class) {
67 | if (serverWorkEventLoopGroup != null && !serverWorkEventLoopGroup.isTerminated()
68 | && !serverWorkEventLoopGroup.isShutdown()) {
69 | return serverWorkEventLoopGroup;
70 | }
71 | serverWorkEventLoopGroup = new NioEventLoopGroup(serverWorkThreadNum);
72 | return serverWorkEventLoopGroup;
73 | }
74 | }
75 |
76 | /**
77 | * 获取客户端线程组
78 | *
79 | * @return ClientEventLoopGroup
80 | */
81 | public static EventLoopGroup getClientEventLoopGroup() {
82 | if (clientEventLoopGroup != null && !clientEventLoopGroup.isShutdown()
83 | && !clientEventLoopGroup.isTerminated()) {
84 | return clientEventLoopGroup;
85 | }
86 | synchronized (ThreadService.class) {
87 | if (clientEventLoopGroup != null && !clientEventLoopGroup.isShutdown()
88 | && !clientEventLoopGroup.isTerminated()) {
89 | return clientEventLoopGroup;
90 | }
91 | clientEventLoopGroup = new NioEventLoopGroup(clientThreadNum);
92 | return clientEventLoopGroup;
93 | }
94 | }
95 |
96 | /**
97 | * 获取业务线程池
98 | *
99 | * @return BusinessExecutor
100 | */
101 | public static ExecutorService getBusinessExecutor () {
102 | if (businessExecutor != null && !businessExecutor.isShutdown() && !businessExecutor.isTerminated()) {
103 | return businessExecutor;
104 | }
105 | synchronized (ThreadService.class) {
106 | if (businessExecutor != null && !businessExecutor.isShutdown() && !businessExecutor.isTerminated()) {
107 | return businessExecutor;
108 | }
109 | businessExecutor = new ThreadPoolExecutor(coreThread, maxThread, 30, TimeUnit.SECONDS, workQueue);
110 | return businessExecutor;
111 | }
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/client/Channel/QRpcChannel.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.client.Channel;
2 |
3 | import com.google.protobuf.*;
4 | import org.qrpc.server.MethodInfoHolder;
5 | import org.qrpc.client.ConnectionConfig;
6 | import org.qrpc.client.EncryptType;
7 |
8 | /**
9 | * @author Yang Lianhuan
10 | * @version 1.0.0
11 | * @since 2023/7/6
12 | **/
13 | public abstract class QRpcChannel {
14 | protected String ip;
15 | protected int port;
16 | protected EncryptType encryptType;
17 |
18 | public QRpcChannel(Builder builder) {
19 | this.ip = builder.ip;
20 | this.port = builder.port;
21 | this.encryptType = builder.encryptType;
22 | }
23 |
24 | protected ConnectionConfig getConnectionConfig() {
25 | return new ConnectionConfig(this.ip, this.port, this.encryptType);
26 | }
27 |
28 | protected MethodInfoHolder getMethodInfo(Descriptors.MethodDescriptor method, RpcController controller
29 | , Message request, Message responsePrototype, RpcCallback done) {
30 | return MethodInfoHolder.builder()
31 | .method(method)
32 | .controller(controller)
33 | .request(request)
34 | .responsePrototype(responsePrototype)
35 | .callback(done)
36 | .build();
37 | }
38 |
39 | public static class Builder {
40 | protected String ip;
41 | protected int port;
42 | protected EncryptType encryptType;
43 |
44 | public Builder ip(String ip) {
45 | this.ip = ip;
46 | return this;
47 | }
48 |
49 | public Builder port(int port) {
50 | this.port = port;
51 | return this;
52 | }
53 |
54 | public Builder(String ip, int port) {
55 | this.ip = ip;
56 | this.port = port;
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/client/Channel/SimpleBlockQRpcChannel.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.client.Channel;
2 |
3 | import com.google.protobuf.*;
4 | import org.qrpc.client.ConnectionFactory;
5 | import org.qrpc.client.EncryptType;
6 | import org.qrpc.client.QRpcClientEndpoint;
7 |
8 | /**
9 | * @author Yang Lianhuan
10 | * @version 1.0.0
11 | * @since 2023/7/10
12 | **/
13 | public class SimpleBlockQRpcChannel extends QRpcChannel implements BlockingRpcChannel {
14 | private final QRpcClientEndpoint endpoint;
15 |
16 | private SimpleBlockQRpcChannel(Builder builder) {
17 | super(builder);
18 | this.endpoint = ConnectionFactory.getInstance().getEndpoint(getConnectionConfig());
19 | }
20 |
21 | @Override
22 | public Message callBlockingMethod(Descriptors.MethodDescriptor method, RpcController controller, Message request, Message responsePrototype) {
23 | return endpoint.blockSend(getMethodInfo(method, controller, request, responsePrototype, null));
24 | }
25 |
26 | public static BlockingQRpcChannelBuilder forAddress(String ip, int port) {
27 | return new BlockingQRpcChannelBuilder(ip, port);
28 | }
29 |
30 | public static class BlockingQRpcChannelBuilder extends Builder {
31 | public BlockingQRpcChannelBuilder(String ip, int port) {
32 | super(ip, port);
33 | }
34 | public BlockingQRpcChannelBuilder userPlaintext() {
35 | this.encryptType = EncryptType.PLAIN_TEXT;
36 | return this;
37 | }
38 | public SimpleBlockQRpcChannel build() {
39 | return new SimpleBlockQRpcChannel(this);
40 | }
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/client/Channel/SimpleQRpcChannel.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.client.Channel;
2 |
3 | import com.google.protobuf.*;
4 | import org.qrpc.server.MethodInfoHolder;
5 | import org.qrpc.client.ConnectionFactory;
6 | import org.qrpc.client.EncryptType;
7 | import org.qrpc.client.QRpcClientEndpoint;
8 |
9 | /**
10 | * @author Yang Lianhuan
11 | * @version 1.0.0
12 | * @since 2023/7/8
13 | **/
14 | public class SimpleQRpcChannel extends QRpcChannel implements RpcChannel {
15 | private final QRpcClientEndpoint endpoint;
16 |
17 | @Override
18 | public void callMethod(Descriptors.MethodDescriptor method, RpcController controller, Message request, Message responsePrototype, RpcCallback done) {
19 | MethodInfoHolder methodInfo = getMethodInfo(method, controller, request, responsePrototype, done);
20 | endpoint.send(methodInfo);
21 | }
22 |
23 | private SimpleQRpcChannel(Builder builder) {
24 | super(builder);
25 | this.endpoint = ConnectionFactory.getInstance().getEndpoint(getConnectionConfig());
26 | }
27 |
28 | public static SimpleQRpcChannelBuilder forAddress(String ip, int port) {
29 | return new SimpleQRpcChannelBuilder(ip, port);
30 | }
31 |
32 | public static class SimpleQRpcChannelBuilder extends Builder {
33 |
34 | public SimpleQRpcChannelBuilder(String ip, int port) {
35 | super(ip, port);
36 | }
37 |
38 | public SimpleQRpcChannelBuilder userPlaintext() {
39 | this.encryptType = EncryptType.PLAIN_TEXT;
40 | return this;
41 | }
42 |
43 | public SimpleQRpcChannel build() {
44 | return new SimpleQRpcChannel(this);
45 | }
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/client/ConnectionConfig.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.client;
2 |
3 | import lombok.Getter;
4 |
5 | /**
6 | * @author Yang Lianhuan
7 | * @version 1.0.0
8 | * @since 2023/7/10
9 | **/
10 | @Getter
11 | public class ConnectionConfig {
12 | private final String ip;
13 | private final int port;
14 | private final EncryptType encryptType;
15 |
16 | public ConnectionConfig(String ip, int port, EncryptType encryptType) {
17 | this.ip = ip;
18 | this.port = port;
19 | this.encryptType = encryptType;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/client/ConnectionFactory.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.client;
2 |
3 | import org.qrpc.Factory;
4 | import org.qrpc.net.NettyClientEndpoint;
5 |
6 | import java.util.*;
7 | import java.util.concurrent.ConcurrentHashMap;
8 |
9 | /**
10 | * @author Yang Lianhuan
11 | * @version 1.0.0
12 | * @since 2023/7/10
13 | **/
14 | public class ConnectionFactory implements Factory {
15 | private static final String COLON = ":";
16 | private static ConnectionFactory connectionFactory;
17 | private static final Map connectionMap = new ConcurrentHashMap<>();
18 | private final List endpointHandlers = new ArrayList<>();
19 |
20 | public static ConnectionFactory getInstance() {
21 | if (connectionFactory != null) {
22 | return connectionFactory;
23 | }
24 | synchronized (ConnectionFactory.class) {
25 | if (connectionFactory != null) {
26 | return connectionFactory;
27 | }
28 | connectionFactory = new ConnectionFactory();
29 | return connectionFactory;
30 | }
31 | }
32 |
33 | private ConnectionFactory() {
34 | this.endpointHandlers.add(new PlainTextEndpointHandler());
35 | this.endpointHandlers.sort(Comparator.comparingInt(EndpointHandler::getOrder));
36 | };
37 |
38 | public QRpcClientEndpoint getEndpoint(ConnectionConfig connectionConfig) {
39 | String ip = connectionConfig.getIp();
40 | int port = connectionConfig.getPort();
41 | String key = ip + COLON + port;
42 | QRpcClientEndpoint endpoint = get(key);
43 | if (endpoint != null && endpoint.available()) {
44 | return endpoint;
45 | }
46 | remove(key);
47 | endpoint = getNewEndpoint(connectionConfig);
48 | register(key, endpoint);
49 | return endpoint;
50 | }
51 |
52 | private QRpcClientEndpoint getNewEndpoint(ConnectionConfig config) {
53 | for (EndpointHandler handler : this.endpointHandlers) {
54 | QRpcClientEndpoint endpoint = handler.process(config);
55 | if (endpoint != null) {
56 | return endpoint;
57 | }
58 | }
59 | return null;
60 | }
61 |
62 | @Override
63 | public void register(String key, QRpcClientEndpoint value) {
64 | connectionMap.put(key, value);
65 | }
66 |
67 | @Override
68 | public boolean contains(String key) {
69 | return connectionMap.containsKey(key);
70 | }
71 |
72 | @Override
73 | public QRpcClientEndpoint get(String key) {
74 | return connectionMap.get(key);
75 | }
76 |
77 | @Override
78 | public void remove(String key) {
79 | connectionMap.remove(key);
80 | }
81 |
82 | interface EndpointHandler {
83 | int getOrder();
84 |
85 | QRpcClientEndpoint process(ConnectionConfig config);
86 | }
87 |
88 | static class PlainTextEndpointHandler implements EndpointHandler {
89 |
90 | private static final int ORDER = 0;
91 |
92 | @Override
93 | public int getOrder() {
94 | return ORDER;
95 | }
96 |
97 | @Override
98 | public QRpcClientEndpoint process(ConnectionConfig config) {
99 | if (config.getEncryptType() == EncryptType.PLAIN_TEXT
100 | || config.getEncryptType() == null) {
101 | return new NettyClientEndpoint(config.getIp(), config.getPort());
102 | }
103 | return null;
104 | }
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/client/EncryptType.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.client;
2 |
3 | /**
4 | * @author Yang Lianhuan
5 | * @version 1.0.0
6 | * @since 2023/7/8
7 | **/
8 | public enum EncryptType {
9 | SSL,
10 | PLAIN_TEXT
11 | }
12 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/client/Endpoint.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.client;
2 |
3 | import com.google.protobuf.Descriptors;
4 | import com.google.protobuf.Message;
5 | import org.qrpc.ConfigEnvironment;
6 | import org.qrpc.Environment;
7 | import org.qrpc.Meta;
8 | import org.qrpc.PropertyKeys;
9 | import org.qrpc.net.Receiver;
10 | import org.qrpc.net.Sender;
11 | import org.qrpc.server.MethodInfoHolder;
12 | import lombok.Getter;
13 | import lombok.Setter;
14 |
15 | import java.util.UUID;
16 | import java.util.concurrent.CompletableFuture;
17 | import java.util.concurrent.ExecutionException;
18 | import java.util.concurrent.TimeUnit;
19 | import java.util.concurrent.TimeoutException;
20 |
21 | /**
22 | * 子类必须调用setSender方法设置消息发送器,接收消息则回调onMessage()方法
23 | *
24 | * @author Yang Lianhuan
25 | * @version 1.0.0
26 | * @since 2024/2/3
27 | **/
28 | public abstract class Endpoint implements QRpcClientEndpoint, Receiver, Sender {
29 | protected final RequestFuture requestFuture;
30 | protected final RequestCache requestCache;
31 |
32 | @Getter
33 | protected final ResponseHandler responseHandler;
34 | protected final Environment environment = ConfigEnvironment.getInstance();
35 |
36 | @Setter
37 | protected boolean ready = false;
38 |
39 | public Endpoint() {
40 | this.requestCache = new RequestCache();
41 | this.requestFuture = new RequestFuture();
42 | this.responseHandler = new ResponseHandler(requestCache ,requestFuture);
43 | }
44 |
45 | @Override
46 | public void send(MethodInfoHolder methodInfo) {
47 | Meta.RpcMetaData metaData = getMetaData(methodInfo);
48 | requestCache.register(metaData.getRequestId(), methodInfo);
49 | send(metaData);
50 | }
51 |
52 | @Override
53 | public Message blockSend(MethodInfoHolder methodInfo) {
54 | Meta.RpcMetaData metaData = getMetaData(methodInfo);
55 | CompletableFuture responseFuture = new CompletableFuture<>();
56 | requestCache.register(metaData.getRequestId(), methodInfo);
57 | requestFuture.register(metaData.getRequestId(), responseFuture);
58 | send(metaData);
59 | try {
60 | return responseFuture.get(Long.parseLong(environment.getProperty(PropertyKeys.CLIENT_TIMEOUT).toString()), TimeUnit.MILLISECONDS);
61 | } catch (InterruptedException | ExecutionException | TimeoutException e) {
62 | e.printStackTrace();
63 | }
64 | return null;
65 | }
66 |
67 | @Override
68 | public boolean available() {
69 | return ready;
70 | }
71 |
72 | @Override
73 | public void onMessage(Object o) {
74 | getResponseHandler().onMessage(o);
75 | }
76 |
77 | private Meta.RpcMetaData getMetaData(MethodInfoHolder methodInfo) {
78 | Descriptors.MethodDescriptor mDescriptor = methodInfo.getMethod();
79 | return Meta.RpcMetaData.newBuilder()
80 | .setRequestId(UUID.randomUUID().toString())
81 | .setServiceName(mDescriptor.getService().getFullName())
82 | .setMethodId(mDescriptor.getIndex())
83 | .setType(Meta.Type.REQUEST)
84 | .setContent(methodInfo.getRequest().toByteString())
85 | .build();
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/client/QRpcClientEndpoint.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.client;
2 |
3 | import com.google.protobuf.Message;
4 | import org.qrpc.server.MethodInfoHolder;
5 |
6 | /**
7 | * send a message to ip:port, responseCallback invoked when respond
8 | *
9 | * @author Yang Lianhuan
10 | * @version 1.0.0
11 | * @since 2023/7/6
12 | **/
13 | public interface QRpcClientEndpoint {
14 | void send(MethodInfoHolder methodInfo);
15 |
16 | Message blockSend(MethodInfoHolder methodInfo);
17 |
18 | boolean available();
19 | }
20 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/client/RequestCache.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.client;
2 |
3 | import org.qrpc.Factory;
4 | import org.qrpc.server.MethodInfoHolder;
5 |
6 | import java.util.Map;
7 | import java.util.concurrent.ConcurrentHashMap;
8 |
9 | /**
10 | * @author Yang Lianhuan
11 | * @version 1.0.0
12 | * @since 2023/7/8
13 | **/
14 | public class RequestCache implements Factory {
15 |
16 | private final Map requestMap = new ConcurrentHashMap<>();
17 |
18 | @Override
19 | public void register(String name, MethodInfoHolder bean) {
20 | if (requestMap.containsKey(name)) {
21 | return;
22 | }
23 | requestMap.put(name, bean);
24 | }
25 |
26 | @Override
27 | public boolean contains(String name) {
28 | return requestMap.containsKey(name);
29 | }
30 |
31 | @Override
32 | public MethodInfoHolder get(String name) {
33 | return requestMap.get(name);
34 | }
35 |
36 | @Override
37 | public void remove(String key) {
38 | requestMap.remove(key);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/client/RequestFuture.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.client;
2 |
3 | import com.google.protobuf.Message;
4 | import org.qrpc.Factory;
5 |
6 | import java.util.Map;
7 | import java.util.concurrent.CompletableFuture;
8 | import java.util.concurrent.ConcurrentHashMap;
9 |
10 | /**
11 | * @author Yang Lianhuan
12 | * @version 1.0.0
13 | * @since 2023/7/10
14 | **/
15 | public class RequestFuture implements Factory> {
16 |
17 | private final Map> futureMap = new ConcurrentHashMap<>();
18 |
19 | @Override
20 | public void register(String key, CompletableFuture value) {
21 | if (!futureMap.containsKey(key)) {
22 | futureMap.put(key, value);
23 | }
24 | }
25 |
26 | @Override
27 | public boolean contains(String key) {
28 | return futureMap.containsKey(key);
29 | }
30 |
31 | @Override
32 | public CompletableFuture get(String key) {
33 | return futureMap.get(key);
34 | }
35 |
36 | @Override
37 | public void remove(String key) {
38 | futureMap.remove(key);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/client/ResponseHandler.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.client;
2 |
3 | import com.google.protobuf.InvalidProtocolBufferException;
4 | import com.google.protobuf.Message;
5 | import org.qrpc.Meta;
6 | import org.qrpc.exception.UnKnownResponseException;
7 | import org.qrpc.net.Receiver;
8 | import org.qrpc.server.MethodInfoHolder;
9 | import lombok.Getter;
10 |
11 | /**
12 | * 返回体处理
13 | *
14 | * @author Yang Lianhuan
15 | * @version 1.0.0
16 | * @since 2024/2/3
17 | **/
18 | @Getter
19 | public class ResponseHandler implements Receiver {
20 |
21 | private final RequestCache requestCache;
22 | private final RequestFuture requestFuture;
23 |
24 | public ResponseHandler(RequestCache requestCache, RequestFuture requestFuture) {
25 | this.requestCache = requestCache;
26 | this.requestFuture = requestFuture;
27 | }
28 |
29 | @Override
30 | public void onMessage(Object object) {
31 | Meta.RpcMetaData metaData = (Meta.RpcMetaData) object;
32 | String requestId = metaData.getRequestId();
33 | if (!requestCache.contains(requestId)) {
34 | throw new UnKnownResponseException();
35 | }
36 | MethodInfoHolder methodInfo = requestCache.get(requestId);
37 | Message response;
38 | try {
39 | response = methodInfo.getResponsePrototype().getParserForType().parseFrom(metaData.getContent());
40 | } catch (InvalidProtocolBufferException e) {
41 | methodInfo.getController().setFailed("response content can not parse to type");
42 | e.printStackTrace();
43 | return;
44 | }
45 | if (requestFuture.contains(requestId)) {
46 | requestFuture.get(requestId).complete(response);
47 | requestFuture.remove(requestId);
48 | return;
49 | }
50 | methodInfo.getCallback().run(response);
51 | requestCache.remove(requestId);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/exception/ClientChannelNotActive.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.exception;
2 |
3 | /**
4 | * @author Yang Lianhuan
5 | * @version 1.0.0
6 | * @since 2024/2/3
7 | **/
8 | public class ClientChannelNotActive extends RuntimeException{
9 | public ClientChannelNotActive() {
10 | super("client channel is not active");
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/exception/DuplicateServiceException.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.exception;
2 |
3 | /**
4 | * @author Yang Lianhuan
5 | * @version 1.0.0
6 | * @since 2023/7/3
7 | **/
8 | public class DuplicateServiceException extends RuntimeException {
9 | public DuplicateServiceException(String message) {
10 | super(message);
11 | }
12 |
13 | public DuplicateServiceException() {
14 | super("Service already exist.");
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/exception/UnKnownResponseException.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.exception;
2 |
3 | /**
4 | * @author Yang Lianhuan
5 | * @version 1.0.0
6 | * @since 2023/7/9
7 | **/
8 | public class UnKnownResponseException extends RuntimeException {
9 | public UnKnownResponseException(String message) {
10 | super(message);
11 | }
12 |
13 | public UnKnownResponseException() {
14 | super("response unknown requestId");
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/net/NettyClientEndpoint.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.net;
2 |
3 | import org.qrpc.Meta;
4 | import org.qrpc.ThreadService;
5 | import org.qrpc.client.Endpoint;
6 | import io.netty.bootstrap.Bootstrap;
7 | import io.netty.channel.*;
8 | import io.netty.channel.socket.SocketChannel;
9 | import io.netty.channel.socket.nio.NioSocketChannel;
10 | import io.netty.handler.codec.protobuf.ProtobufDecoder;
11 | import io.netty.handler.codec.protobuf.ProtobufEncoder;
12 | import io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder;
13 | import io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender;
14 | import io.netty.util.concurrent.GenericFutureListener;
15 | import lombok.extern.slf4j.Slf4j;
16 |
17 | /**
18 | * @author Yang Lianhuan
19 | * @version 1.0.0
20 | * @since 2023/7/6
21 | **/
22 | @Slf4j
23 | public class NettyClientEndpoint extends Endpoint {
24 | private final String ip;
25 | private final int port;
26 | private final EventLoopGroup eventLoopGroup;
27 | private ChannelFuture future;
28 | private final ChannelInboundHandler inboundHandler;
29 |
30 |
31 | public NettyClientEndpoint(String ip, int port) {
32 | super();
33 | this.ip = ip;
34 | this.port = port;
35 | this.eventLoopGroup = ThreadService.getClientEventLoopGroup();
36 | this.inboundHandler = new NettyClientInboundHandler(this);
37 | init();
38 | }
39 |
40 | private void init() {
41 | Bootstrap bootstrap = new Bootstrap();
42 | bootstrap.group(eventLoopGroup)
43 | .channel(NioSocketChannel.class)
44 | .option(ChannelOption.TCP_NODELAY, true)
45 | .option(ChannelOption.SO_KEEPALIVE, true)
46 | .handler(new ChannelInitializer() {
47 | @Override
48 | protected void initChannel(SocketChannel ch) throws Exception {
49 | ch.pipeline()
50 | .addLast(new ProtobufVarint32FrameDecoder())
51 | .addLast(new ProtobufDecoder(Meta.RpcMetaData.getDefaultInstance()))
52 | .addLast(new ProtobufVarint32LengthFieldPrepender())
53 | .addLast(new ProtobufEncoder())
54 | .addLast(inboundHandler);
55 | }
56 | });
57 | try {
58 | future = bootstrap.connect(ip, port).sync();
59 | future.addListener((GenericFutureListener) future1 -> {
60 | if (!future1.isSuccess()) {
61 | log.error("connect to {}:{} failed retrying", ip, port);
62 | init();
63 | return;
64 | }
65 | log.info("connected to {}:{}", ip, port);
66 | setReady(true);
67 | });
68 | } catch (InterruptedException e) {
69 | Thread.currentThread().interrupt();
70 | e.printStackTrace();
71 | }
72 | }
73 |
74 | @Override
75 | public void send(Object o) {
76 | future.channel().writeAndFlush(o);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/net/NettyClientInboundHandler.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.net;
2 |
3 | import org.qrpc.Meta;
4 | import org.qrpc.client.ResponseHandler;
5 | import io.netty.channel.ChannelHandler;
6 | import io.netty.channel.ChannelHandlerContext;
7 | import io.netty.channel.SimpleChannelInboundHandler;
8 |
9 | /**
10 | * Client method receive message from server, all client stub share the same inboundHandler here,
11 | * when channelRead() invoked, we get a @Mata.MetaData, from which we can get serviceName and methodId.
12 | * we find specific callback function RpcController and RpcCallback and invoke them.
13 | *
14 | * @author Yang Lianhuan
15 | * @version 1.0.0
16 | * @since 2023/7/8
17 | **/
18 | @ChannelHandler.Sharable
19 | public class NettyClientInboundHandler extends SimpleChannelInboundHandler {
20 |
21 | private final Receiver receiver;
22 |
23 | public NettyClientInboundHandler(Receiver receiver) {
24 | this.receiver = receiver;
25 | }
26 |
27 | @Override
28 | protected void channelRead0(ChannelHandlerContext channelHandlerContext, Meta.RpcMetaData metaData) {
29 | receiver.onMessage(metaData);
30 | }
31 |
32 | @Override
33 | public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
34 | cause.printStackTrace();
35 | ctx.close();
36 | }
37 |
38 | @Override
39 | public void channelActive(ChannelHandlerContext ctx) {
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/net/NettyServerInboundHandler.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.net;
2 |
3 | import org.qrpc.Meta;
4 | import io.netty.channel.ChannelHandlerContext;
5 | import io.netty.channel.SimpleChannelInboundHandler;
6 | import lombok.extern.slf4j.Slf4j;
7 | import org.qrpc.server.ServiceExecutor;
8 |
9 | /**
10 | * @author Yang Lianhuan
11 | * @version 1.0.0
12 | * @since 2023/7/4
13 | **/
14 | @Slf4j
15 | public class NettyServerInboundHandler extends SimpleChannelInboundHandler {
16 |
17 | private final Responsible responsible;
18 |
19 | public NettyServerInboundHandler(Responsible responsible) {
20 | this.responsible = responsible;
21 | }
22 |
23 | @Override
24 | protected void channelRead0(ChannelHandlerContext channelHandlerContext, Meta.RpcMetaData metaData) {
25 | Sender nettySeder = new NettyServerSender(channelHandlerContext);
26 | responsible.onMessage(metaData, nettySeder);
27 | }
28 |
29 | @Override
30 | public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
31 | log.error(cause.getMessage());
32 | ctx.fireExceptionCaught(cause);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/net/NettyServerSender.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.net;
2 |
3 | import io.netty.channel.ChannelHandlerContext;
4 |
5 | /**
6 | * @author Yang Lianhuan
7 | * @version 1.0.0
8 | * @since 2024/2/3
9 | **/
10 | public class NettyServerSender implements Sender {
11 | private final ChannelHandlerContext channelHandlerContext;
12 |
13 | public NettyServerSender(ChannelHandlerContext channelHandlerContext) {
14 | this.channelHandlerContext = channelHandlerContext;
15 | }
16 |
17 | @Override
18 | public void send(Object o) {
19 | channelHandlerContext.writeAndFlush(o);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/net/NettyTCPServer.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.net;
2 |
3 | import org.qrpc.Banner;
4 | import org.qrpc.Meta;
5 | import org.qrpc.ThreadService;
6 | import org.qrpc.server.AbstractServer;
7 | import org.qrpc.server.ServerBuilder;
8 | import io.netty.bootstrap.ServerBootstrap;
9 | import io.netty.channel.*;
10 | import io.netty.channel.socket.SocketChannel;
11 | import io.netty.channel.socket.nio.NioServerSocketChannel;
12 | import io.netty.handler.codec.protobuf.ProtobufDecoder;
13 | import io.netty.handler.codec.protobuf.ProtobufEncoder;
14 | import io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder;
15 | import io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender;
16 | import lombok.extern.slf4j.Slf4j;
17 |
18 | import java.net.InetSocketAddress;
19 |
20 | /**
21 | * @author Yang Lianhuan
22 | * @version 1.0.0
23 | * @since 2023/7/1
24 | **/
25 | @Slf4j
26 | public class NettyTCPServer extends AbstractServer {
27 |
28 | private final int port;
29 |
30 | public NettyTCPServer(int port) {
31 | this.port = port;
32 | }
33 |
34 | public NettyTCPServer(ServerBuilder builder) {
35 | this.port = builder.getPort();
36 | }
37 |
38 | @Override
39 | public void start() {
40 | EventLoopGroup bossGroup = ThreadService.getServerBossEventLoopGroup();
41 | EventLoopGroup workerGroup = ThreadService.getServerWorkEventLoopGroup();
42 | try {
43 | ServerBootstrap bootstrap = new ServerBootstrap();
44 | bootstrap.group(bossGroup, workerGroup)
45 | .channel(NioServerSocketChannel.class)
46 | .option(ChannelOption.SO_BACKLOG, 128)
47 | .localAddress(new InetSocketAddress(port))
48 | .childOption(ChannelOption.SO_KEEPALIVE, true)
49 | .childHandler(new ChannelInitializer() {
50 | @Override
51 | protected void initChannel(SocketChannel ch) {
52 | ch.pipeline()
53 | .addLast(new ProtobufVarint32FrameDecoder())
54 | .addLast(new ProtobufDecoder(Meta.RpcMetaData.getDefaultInstance()))
55 | .addLast(new ProtobufVarint32LengthFieldPrepender())
56 | .addLast(new ProtobufEncoder())
57 | .addLast(new NettyServerInboundHandler(NettyTCPServer.this));
58 | }
59 | });
60 | Banner.print();
61 | try {
62 | ChannelFuture future = bootstrap.bind().sync();
63 | future.addListener((ChannelFutureListener) channelFuture -> Banner.printStarted(port));
64 | future.channel().closeFuture().sync();
65 | } catch (InterruptedException e) {
66 | e.printStackTrace();
67 | }
68 | } finally {
69 | bossGroup.shutdownGracefully();
70 | workerGroup.shutdownGracefully();
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/net/Receiver.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.net;
2 |
3 | /**
4 | * 消息接收器,底层网络框架实现此接口接收消息
5 | *
6 | * @author Yang Lianhuan
7 | * @version 1.0.0
8 | * @since 2024/2/3
9 | **/
10 | public interface Receiver {
11 | void onMessage(Object object);
12 | }
13 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/net/Responsible.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.net;
2 |
3 | /**
4 | * @author Yang Lianhuan
5 | * @version 1.0.0
6 | * @since 2024/2/4
7 | **/
8 | public interface Responsible {
9 | void onMessage(Object o, Sender responder);
10 | }
11 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/net/Sender.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.net;
2 |
3 | /**
4 | * 此为发送消息实现类,底层通信框架实现此接口发送消息
5 | *
6 | * @author Yang Lianhuan
7 | * @version 1.0.0
8 | * @since 2024/2/3
9 | **/
10 | public interface Sender {
11 | void send(Object o);
12 | }
13 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/net/Server.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.net;
2 |
3 | /**
4 | * 服务器,底层通信框架实现此接口启动服务
5 | *
6 | * @author Yang Lianhuan
7 | * @version 1.0.0
8 | * @since 2023/7/1
9 | **/
10 | public interface Server extends Responsible {
11 | void start();
12 | }
13 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/server/AbstractServer.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.server;
2 |
3 | import lombok.Getter;
4 | import org.qrpc.net.Receiver;
5 | import org.qrpc.net.Responsible;
6 | import org.qrpc.net.Sender;
7 | import org.qrpc.net.Server;
8 |
9 | /**
10 | * 需要实现start方法来启动服务,需要回调onMessage来接收消息并传入消息回复器
11 | *
12 | * @author Yang Lianhuan
13 | * @version 1.0.0
14 | * @since 2024/2/4
15 | **/
16 | @Getter
17 | public abstract class AbstractServer implements Server {
18 |
19 | @Override
20 | public void onMessage(Object o, Sender responder) {
21 | // 因为每次客户端可能不一样,因此每次收到消息都创建一个ServiceExecutor来应答消息,防止消息走串
22 | new ServiceExecutor(responder).onMessage(o);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/server/ListableServiceFactory.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.server;
2 |
3 | import com.google.protobuf.Service;
4 | import org.qrpc.exception.DuplicateServiceException;
5 |
6 | import java.util.Map;
7 | import java.util.concurrent.ConcurrentHashMap;
8 |
9 | /**
10 | * @author Yang Lianhuan
11 | * @version 1.0.0
12 | * @since 2023/4/3
13 | **/
14 | public class ListableServiceFactory implements ServiceFactory {
15 | private static volatile ServiceFactory serviceFactory;
16 | private final Map serviceMap = new ConcurrentHashMap<>();
17 |
18 | @Override
19 | public void register(Service service) {
20 | ServiceHolder serviceHolder = new ServiceHolder(service);
21 | register(service.getDescriptorForType().getFullName(), serviceHolder);
22 | }
23 |
24 | @Override
25 | public void register(String name, ServiceHolder serviceHolder) {
26 | if (serviceMap.containsKey(name)) {
27 | throw new DuplicateServiceException();
28 | }
29 | serviceMap.put(name, serviceHolder);
30 | }
31 |
32 | @Override
33 | public boolean contains(String name) {
34 | return serviceMap.containsKey(name);
35 | }
36 |
37 | @Override
38 | public ServiceHolder get(String name) {
39 | return serviceMap.get(name);
40 | }
41 |
42 | @Override
43 | public void remove(String key) {
44 | serviceMap.remove(key);
45 | }
46 |
47 | public static ServiceFactory getInstance() {
48 | if (serviceFactory != null) {
49 | return serviceFactory;
50 | }
51 | synchronized (ListableServiceFactory.class) {
52 | if (serviceFactory != null) {
53 | return serviceFactory;
54 | }
55 | serviceFactory = new ListableServiceFactory();
56 | return serviceFactory;
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/server/MethodInfoHolder.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.server;
2 |
3 | import com.google.protobuf.Descriptors;
4 | import com.google.protobuf.Message;
5 | import com.google.protobuf.RpcCallback;
6 | import com.google.protobuf.RpcController;
7 | import lombok.Getter;
8 |
9 | /**
10 | * @author Yang Lianhuan
11 | * @version 1.0.0
12 | * @since 2023/4/8
13 | **/
14 | @Getter
15 | public class MethodInfoHolder {
16 | private Descriptors.MethodDescriptor method;
17 | private RpcController controller;
18 | private com.google.protobuf.Message request;
19 | private Message responsePrototype;
20 | private RpcCallback callback;
21 |
22 | public static MethodInfoHolder builder() {
23 | return new MethodInfoHolder();
24 | }
25 |
26 | public MethodInfoHolder method(Descriptors.MethodDescriptor methodDescriptor) {
27 | this.method = methodDescriptor;
28 | return this;
29 | }
30 |
31 | public MethodInfoHolder controller(RpcController controller) {
32 | this.controller = controller;
33 | return this;
34 | }
35 |
36 | public MethodInfoHolder request(com.google.protobuf.Message message) {
37 | this.request = message;
38 | return this;
39 | }
40 |
41 | public MethodInfoHolder responsePrototype(Message responsePrototype) {
42 | this.responsePrototype = responsePrototype;
43 | return this;
44 | }
45 |
46 | public MethodInfoHolder callback(RpcCallback callback) {
47 | this.callback = callback;
48 | return this;
49 | }
50 |
51 | public MethodInfoHolder build() {
52 | return this;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/qrpc-core/src/main/java/org/qrpc/server/QRpcController.java:
--------------------------------------------------------------------------------
1 | package org.qrpc.server;
2 |
3 | import com.google.protobuf.RpcCallback;
4 | import com.google.protobuf.RpcController;
5 | import org.qrpc.Meta;
6 | import org.qrpc.RpcStatus;
7 | import org.qrpc.utils.ResponseManager;
8 |
9 | /**
10 | * @author Yang Lianhuan
11 | * @version 1.0.0
12 | * @since 2023/7/4
13 | **/
14 | public class QRpcController implements RpcController {
15 | private RpcStatus status;
16 | private String reason;
17 | private final Meta.RpcMetaData metaData;
18 |
19 | public QRpcController(Meta.RpcMetaData metaData) {
20 | this.metaData = metaData;
21 | }
22 |
23 | @Override
24 | public void reset() {
25 | status = RpcStatus.INIT;
26 | }
27 |
28 | @Override
29 | public boolean failed() {
30 | return this.status == RpcStatus.FAILED;
31 | }
32 |
33 | @Override
34 | public String errorText() {
35 | return reason;
36 | }
37 |
38 | @Override
39 | public void startCancel() {
40 | this.status = RpcStatus.CANCELING;
41 | }
42 |
43 | @Override
44 | public void setFailed(String reason) {
45 | this.status = RpcStatus.FAILED;
46 | this.reason = reason;
47 | }
48 |
49 | @Override
50 | public boolean isCanceled() {
51 | return this.status == RpcStatus.CANCELED;
52 | }
53 |
54 | @Override
55 | public void notifyOnCancel(RpcCallback