Many languages have RPC technology built into them. Since ancient times, there have been many attempts to:
- Corba (Common ObjectRequest Broker Architecture) is a technical specification of Common ObjectRequest Broker Architecture proposed by OMG in 1991. The underlying structure is based on the object-oriented model, consisting of OMG Interface Definition Language (OMG IDL), object Request Broker (Objec tRequest Broker), ORB) and IIOP standard Protocol (Internet Inter ORB Protocol, also known as network ORB Switching Protocol).
- COM (Component Object Model) is a Component technology proposed by Microsoft in 1993. It is a platform independent, language neutral, location transparent, support network middleware technology. Many older programmers in the mind of the god book “COM essence”.
1. Consider users
Define the process interface
The client uses the generated stub proxy object
2 Client design
The client generates a proxy object for the procedure interface.
Client proxy factory, which uses JDK dynamic proxies (or AOP implementations) to generate proxy objects for interfaces.
- ClientStubInvocationHandler
- Is the message protocol fixed? What does it relate to?
Depending on the breadth of the framework’s support for protocols, it will be flexible if multiple protocols are supported, which is related to specific services. Service provider A may choose Protocol 1 and service provider B may choose protocol 2.
- What message protocol does a service use and where does this information come from?
From the service information retrieved, so a service information finder is required.
The discoverer design, requirements: flexible support for a variety of discovery mechanisms
- How should a class be designed to support multiple protocols? Interface oriented, policy pattern, composition
Question: Marshalling and unmarshalling methods what parameters and return values should be defined? The object of marshalling or unmarshalling is a request and a response, and the contents of the request and response are different. Are the two methods of grouping and ungrouping satisfied?
Design the client protocol layer
Define framework standard request and response classes
- Expand the protocol layer to four
A separate layer of messaging protocols (both client and server required)
The network layer sends the request and gets the response
To initiate a network request, you need to know the service address
- Client complete class diagram
In the implementation process, the protocol layer involves an important concept
- Parameter serialization, de-sequence
3 Design the server
3.1 RPCServer
When a client request comes in, the server first needs to receive the request through the RPCServer.
- RPCServer
3.2 thinking
What else does the RPCServer need to do after receiving the client request?
The network layer provides multithreading in THE RPCServer to handle requests, and the message protocol layer is designed for reuse by the client. (Design a request handling class to do things beyond the network layer.)
3.3 RequestHandler
The RPCServer receives the Request and hands it to the RequestHandler for processing. The RequestHandler calls the protocol layer to ungroup the Request message into a Request object, and then calls the procedure!
Torture of humanity
: : How does a RequestHandler obtain a process object? What is in the Request? Question: Is a process registration module required?
Look at the design after that
Process registration module: Allowing users to register their processes with the RPC framework
- RPCServer implementation of the network layer: Netty, using RequestHandler
- The Service reader module registers and publishes services.
- RequestHandler to achieve message protocol processing, procedure call
Code implementation
- First, the user needs to set up your port and protocol
- Related to the source code