Brief introduction to RMI

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:

[brief introduction to RMI]

Hello, I'm Bai chensong, a student of the 13th phase of Wuhan Branch of it Academy. I'm an honest, pure and kind java programmer

Today, I'd like to share with you the knowledge points in deep thinking on Java task 8 on the official website of the Academy - a brief introduction to RMI

1. Background introduction

The full name of RMI is remote method invocation - remote method invocation. Java RMI is in jdk1 1, its power is reflected in its powerful ability to develop distributed network applications. It is one of the core solutions of pure java network distributed application system. In fact, it can be regarded as the Java version of RPC. However, traditional RPC can not be well applied to distributed object systems. Java RMI supports program level objects stored in different address spaces to communicate with each other, so as to realize seamless remote calls between remote objects.

RMI currently uses the Java remote messaging protocol (jrmp) for communication. Since jrmp is specifically designed for Java objects, Java RMI has Java's "write once, run anywhere" It is a 100% pure Java solution for distributed application system. The application system developed with Java RMI can be deployed on any platform supporting JRE. However, because jrmp is designed for Java objects, RMI does not support application systems developed in non java languages. Cannot communicate with objects written in a non Java language.

2. Knowledge analysis

Composition of RMI

A normal RMI system consists of the following parts:

1. Interface definition of remote service 2 Specific implementation of remote service interface 3 Stub and skeleton files 4. A server running the remote service 5. An RMI naming service that allows the client to discover the remote service 6. The provider of the class file (an HTTP or FTP server) 7. A client program that needs the remote service

To call remote RMI:

1. The client calls the method on the client auxiliary object stub

2. The client auxiliary object stub packages the call information (variable, method name) and sends it to the server auxiliary object skeleton through the network

3. The server auxiliary object skeleton unpacks the information sent by the client auxiliary object to find out the real called method and the object where the method is located

4. Call the real method on the real service object and return the result to the service side auxiliary object skeleton

5. The server auxiliary object packages the results and sends them to the client auxiliary object stub

6. The client auxiliary object unpacks the return value and returns it to the caller

7. The customer obtains the return value

3. Common problems

1. Advantages of RMI remote method call.

4. Solutions

Main advantages of RMI:

Object oriented: RMI can pass complete objects as parameters and return values, not just predefined data types. That is, you can pass complex types such as Java hash tables as a parameter.

Removable attributes: RMI can move attributes (class implementers) from the client to the server, or from the server to the client. This allows maximum flexibility, because when the policy changes, you only need to write a new Java class and install it on the server host once.

Security: RMI uses Java's built-in security mechanism to ensure the security of the user's system when downloading and executing programs.

Easy to write and use: writing RMI is actually writing Java interfaces

Can connect to existing / existing systems: RMI can connect to existing and existing systems using the standard Java Native method interface JNI

Write once and run everywhere

Distributed garbage collection: RMI uses its distributed garbage collection function to collect remote service objects that are no longer referenced by any client in the network. Parallel computing: RMI adopts multi-threaded processing method, which enables your server to use these Java threads to better process client requests in parallel.

5. Coding practice

6. Expand thinking

What are the disadvantages of RMI

One of the limitations of RMI is that RMI is a remote call of Java language, and the program languages at both ends must be implemented in Java. For the communication between different languages, we can consider using web service or Common Object Request Broker Architecture (CORBA).

The IP address and port of the server are closely dependent, but the future server IP and port are not known at the time of development, but the client program depends on this IP and port. This is also one of the limitations of RMI. There are two ways to solve this problem: one is to solve it through DNS, and the other is to expose IP outside the program code through encapsulation.

7. References

Basic knowledge of RMI

http://www.blogjava.net/zhenyu33154/articles/320245.html

RMI strengths and weaknesses summary

https://blog.csdn.net/mingtianhaiyouwo/article/details/50513577

Discussion questions:

Q:

1. Will spring RMI occupy two ports?

2. Registryport and serviceport?

3. When the RMI server restarts, the client connection is always rejected.

Answer:

1. Spring RMI has two ports, one is the registration port (1099 by default) and the other is the data transmission port. If it is not specified, the data transmission port is randomly assigned.

2. Registration port: registryport is the port where RMI registers remote services.

Service port: the port for transmitting data required by serviceport RMI communication. If serviceport is not set, the random port is used.

3. Server restart will affect the client, indicating that the client has saved the relevant records of server connection before restart. It is possible that the client has a cache, so just refresh the cache to solve the problem.

Thank you for watching. If there is any error, please correct it

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

Ppt link video link

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
分享
二维码
< <上一篇
下一篇>>