RMI underlying implementation principle

This is the back-end small class of the monastery. Each article is shared from

[background introduction] [knowledge analysis] [common problems] [solutions] [coding practice] [extended thinking] [more discussion] [References]

Eight aspects of in-depth analysis of back-end knowledge / skills. This article shares:

[RMI underlying implementation principle]

RMI underlying implementation principle_ Tencent video

1. Background introduction

As the name suggests, remote method invocation (RMI) is a program on one machine calling a method on another machine. Its main purpose is to make the calls between objects running in different computers behave like local calls, so as to realize distributed computing.

2. Knowledge analysis

RMI applications typically contain two separate programs, a server and a client. A typical server program creates remote objects, makes references to these objects accessible, and waits for the client to call methods on these objects. Typical client programs acquire remote references to one or more remote objects on the server, then invoke the methods on them. RMI provides a mechanism for server and client to pass information back and forth. Such applications are sometimes referred to as distributed object applications.

3. Frequently asked questions

What role do stubs and skeletons play?

What is the role of rmiregistry?

4. Solution

Stub and skeleton are combined to form RMI framework protocol, which is responsible for network communication related functions

The stub acts as the local representative or agent of the remote object. It is responsible for grouping and packaging the method name and parameters of the remote object method to be called, and forwarding the package to the server where the remote object is located

When you call the method of stub, you do the following:

(1) Establish a socket connection with the skeleton on the server (2) package the parameters (write and transfer)

(3) Wait for method call results

(4) Unpack (read) returned value or returned exception

(5) The result is returned to the client

Skeleton runs on the server and accepts calls from the stub object. After skeleton receives the call request from the stub object, skeleton will do the following:

(1) Unpack (read) parameters from stub

(2) Call the method on the matching implementation

(3) Package the return value or send an error to the stub object

What is the role of rmiregistry?

java. rmi. The naming class provides methods to store and obtain references to remote objects on the remote object registry. Each method of naming class uses URL format parameters. A / / IP: port / name can uniquely locate a published object on an RMI server

When running the public static remote lookup (string name) method, a stub object will be generated. The construction parameters of the stub object need an object of remoteref type,

The server runs public static void bind (string name, remote obj). This method will pass in a reference of the implementation class as the second parameter. At this time, naming will use getClass to obtain the name of the class and construct a stub

Get the remoteref object from the entity class, which encapsulates the details of the server, including the hostname and port of the server. Rmiregistry stores the stub object and provides it to the client

5. Extended thinking

Is rmiregistry necessary?

No, rmiregistry is only used to facilitate the client to get the stub object. If there are other methods for the client to get the stub, rmiregistry is not required, because once the client gets the stub, rmiregistry is not required

Just create a stub object in client new?

No, a remoteref object is required in the stub constructor, which can only be obtained on the server side.

------------------------------------------------------------------------------------------------------------------------

That's all for today's sharing. You are welcome to like, forward, leave messages and make bricks~

Skill tree It Academy

"We believe that everyone can become an engineer. From now on, find a senior brother to introduce you, control your learning rhythm, and stop being confused on the way to learning.".

Here is the skill tree In it academy, thousands of senior brothers have found their own learning route here. Learning is transparent and growth is visible. Senior brothers have 1-to-1 free guidance. Come and study with me~

My invitation code: 14229748, or you can click this link directly: http://www.jnshu.com/login/1/14229748

Author: YaoYuan 17023 link: https://www.jianshu.com/p/a9f72cc9fb31 Source: the copyright of Jianshu Jianshu belongs to the author. Please contact the author for authorization and indicate the source for any form of reprint.

For more information, you can join the IT communication group 565734203 to discuss and communicate with you

Here is the skill tree · it Academy: a gathering place for beginners to switch to the Internet

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>