RMI (Remote Method Invocation)

xiaoxiao2021-03-06  42

One: Working principle The RMI system structure has several layers of structure in the client and server. ----------------- | Customer object | | Remote object | --------------- | | | ------------------------------------------------ ----------- | Placeboard stub | | 网 Skeleton | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---- ---------------------------------------- -------------------------------------------------- --- | Telegraph Remote Reference Layer | ------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------- --------------- | Communication Layer Transport Layer | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------

Method call is passed from the customer object to the host, the remote reference layer (Remote Reference Layer) and the transport layer, and then pass the transmission layer again, pass through the remote call layer and backbone network. (Skeleton) to reach the server object. The placeholder program plays the role of the proxy of the remote server object, so that the object can be activated by the customer. The remote reference layer handles semantics, manages single or multiple objects, and determines that the call should be sent to a server or multiple. The transport layer manages the actual connection and tracking the tracking of the remote object that is called. The backbone network of the server is called the actual method of the server object, and gets the return value. The return value is subjected to the remote reference layer, the server-side transport layer is passed back to the client, and then returned to the transport layer and the remote call layer. Finally, the placeholder program gets the return value. (The above is the original words of the reference) 2: RMI Related class RMI consists of 5 packs and 3 application tools: Java.RMI organizational client's RMI class, interface and exception Java.rmi.Sever organization server-side RMI, interface and Abnormal Java.rmi.Registry organizations for managing RMI naming services class Java.rmi.dgc organizations for managing distributed garbage collection Java.rmi.Activation organizations for implementing RMIC compilers for RMI services on demand seizures Generate STUB and Sketon RMiregistry a server that provides naming services for RMI, this service associates the name and object together RMID a server that supports the RMI activation frame, but in most cases, we only need to use a part of each package and The interface can be successfully implemented using RMI distributed solutions. 3: Steps To complete the above steps to have the following steps: 1 Generate a remote interface 2, implement the remote object (server-side program) 3, generate a placeholder program And backbone network (server-side program) 4, write server programs 5, write client programs 6, register remote object 7, start remote objects 4: A simple application has three Java classes, remote interfaces, server programs, client programs Remote interface: import java.rmi. *; Public interface helloin extension java.rmi.Remote {string selfiexception;} server program: import java.rmi. *; Import java.net. *; Import java.rmi .registry. *; import java.rmi.server. *;

public class Hello extends java.rmi.server.UnicastRemoteObject implements HelloIn {public Hello () throws RemoteException {super ();} public String sayHello () throws RemoteException {return "Hello, World!";} public static void main (String [ ] args) {//system.setsecuritymanager (New java.rmi.rmisecuritymanager ()); try {hello h = new hello (); java.rmi.naming.rebind ("Hello", H); System.out.print ("Ready ...");} catch (Exception E) {E.PrintStackTrace ();}}} RMIC Hello Generates Stub and Skeleton Start RMIREGISTRY to start RMI in the command line mode before executing the server program Program Java Hello launch server client program: import java.rmi. *; Import java.rmi.registry. *; Public class helloworld {public static void main (string [] args) {//system.setproperty ("java.security .policy "," client.policy "); //system.setsecuritymanager (new java.rmi.rmiseCurityManager ()); try {helloin hi = (helloin) Naming.lookup (" // 127.0.0.1/hello "); For (int i = 0; i <10; i ) {system.out.println (hi.sayhello ());}} catch (Exception e) {E.PrintStackTrace ();}}} compile: Javac HelloWorld.java Finally, the Java HelloWorld console prints Hello, World, successful calls.

转载请注明原文地址:https://www.9cbs.com/read-66024.html

New Post(0)