Home > database >  RMI
RMI

Time:10-19

RMI

RMI (Remote Method Invocation, Remote Method Invocation (RMI) are implemented in Java in JDK1.2, it greatly enhances the ability of Java development of distributed application, Java web development language, as a kind of be the rage, its enormous power is reflected in its powerful ability to develop distributed network applications, and the development of one hundred percent pure Java RMI is one of the core solution of network distributed application system, it can be seen as a Java version of the RPC, but traditional RPC is not well applied in the distributed object system, while Java RMI support application-level stored in different address Spaces between objects communicate with each other, realize seamless Remote calls between a Remote object,

RMI now (Java Remote Messaging Protocol) for communication, JRMP is designed for Java Remote object set Protocol, as a result, the Java RMI has Java "Write Once, Run Anywhere", the advantages of the distributed application system of one hundred percent pure Java solution, with the development of the Java RMI application system can be deployed in any support JRE (Java Run Java Environment, running Environment) platform, but since the JRMP is designed for Java objects, as a result, the RMI for development of application system with the Java language support is insufficient, can't communicate with the objects written in the Java language,

Java Java remote method invocation (RMI) is a Java API for remote procedure call (RPC) provided by the object-oriented equivalent form, support direct transmission serialized Java objects, and the distributed garbage collection, remote method invocation (RMI) is seen as a remote objects that are running on the method of step, the RMI callers are location transparency, because the caller feel method is to perform running locally on the object, look at the some matters needing attention of the RMI,

The basic principle of RMI architecture
RMI architecture is based on a very important behavior definition and behavior to realize the principle of phase separation, RMI allows you to define the behavior of the code and implementation phase separation behavior of the code, and run on a different JVM,

RMI architecture
Stub and Skeleton layer (Stub and Skeleton layer) : this layer is transparent for programmers, it is mainly responsible for intercept method invocation request from the client, then the request is redirected to the remote RMI service,
Remote Reference Layer (Remote Reference Layer) : the second floor of the RMI architecture used to resolve the client to the server to the Remote object Reference, this Layer analysis and manage the client to the server to the Remote object Reference, is a point-to-point connection,
Transport layer, Transport layer) : this layer is responsible for the connection to participate in the service of the two JVM, this layer is based on TCP/IP connection between machines on the network, it provides basic connectivity, there are some firewall penetration strategy,

* * Remote Interface of RMI (Remote Interface) * * what method can be used to identify the local virtual machine call Interface, Remote object to realize Remote Interface, directly or indirectly realizes Remote Interface is implemented with class should be declared the Remote Interface, give each a Remote object define constructors, to all of the methods provide Remote Interface implementation,

RMI Binding (Binding)
Binding is to query a remote object and the object associated to the remote or is the process of registration will use the name of the remote object can use Naming classes of the bind () or the rebind () method that is associated with the name,

Let the RMI program can run right step

Compile all source files

Using rmic generated stub

Start the rmiregistry

Start the RMI server

Run the client program

The role of RMI stubs
Remote object stub of a representative or agent of the remote object role, the caller on the local stub method is called, it is responsible for the execution method on a remote object, when the stub method is invoked, go through the following steps:
Initialized to contain the remote object of the JVM connection,
Serialization parameters to a remote JVM,
Wait for the results of the method calls and,
Deserialize the return value or the method does not perform successful cases of abnormal,
The value is returned to the caller,

DGC is called distributed garbage collection, RMI DGC be used for automatic garbage collection, because the RMI contains the remote object reference across the virtual machine, recycling is difficult, DGC use reference counting algorithm to provide remote object automatic memory management,

RMI use RMI security manager (RMISecurityManager)
the purpose ofRMISecurityManager use downloaded code can be used by the RMI application security manager, if there is no set the security manager, RMI class loader is not from the remote download any class,


CodePudding user response:

BBS is to discuss the problem, this knowledge Suggestions to personal blog,