FazBrowse Wikipedia Viewer | Main Page |
Search Wikipedia:
|
Viewing: https://en.wikipedia.org/wiki/Java_remote_method_invocation

Java remote method invocation

A typical implementation model of Java-RMI using stub and skeleton objects. Java 2 SDK, Standard Edition, v1.2 removed the need for a skeleton.

The Java Remote Method Invocation (Java RMI) is a Java API that performs remote method invocation, the object-oriented equivalent of remote procedure calls (RPC), with support for direct transfer of serialized Java classes and distributed garbage-collection.

The original implementation depends on Java Virtual Machine (JVM) class-representation mechanisms and it thus only supports making calls from one JVM to another. The protocol underlying this Java-only implementation is known as Java Remote Method Protocol (JRMP). In order to support code running in a non-JVM context, programmers later developed a CORBA version.

Usage of the term RMI may denote solely the programming interface or may signify both the API and JRMP, IIOP, or another implementation, whereas the term RMI-IIOP (read: RMI over IIOP) specifically denotes the RMI interface delegating most of the functionality to the supporting CORBA implementation.

The basic idea of Java RMI, the distributed garbage-collection (DGC) protocol, and much of the architecture underlying the original Sun implementation, come from the "network objects" feature of Modula-3.

packageorg.wikipedia.examples; importjava.rmi.Naming; importjava.rmi.RemoteException; importjava.rmi.server.UnicastRemoteObject; importjava.rmi.registry.*; publicclass RmiServerextendsUnicastRemoteObjectimplementsRmiServerIntf{ publicstaticfinalStringMESSAGE="Hello World"; publicRmiServer()throwsRemoteException{ super(0);// required to avoid the 'rmic' step, see below } publicStringgetMessage(){ returnMESSAGE; } publicstaticvoidmain(String[]args)throwsException{ System.out.println("RMI server started"); // Special exception handler for registry creation try{ LocateRegistry.createRegistry(1099); System.out.println("Java RMI registry created."); }catch(RemoteExceptione){ // Do nothing; error means registry already exists System.out.println("Java RMI registry already exists."); } // Instantiate RmiServer RmiServerserver=newRmiServer(); // Bind this object instance to the name "RmiServer" Naming.rebind("//localhost/RmiServer",server); System.out.println("PeerServer bound in registry"); } }
RmiClient class
this is the client which gets the reference (a proxy) to the remote object living on the server and invokes its method to get a message. If the server object implemented java.io.Serializable instead of java.rmi.Remote, it would be serialized and passed to the client as a value.
rmic RmiServer

Note that since version 5.0 of J2SE, support for dynamically generated stub files has been added, and rmic is only provided for backwards compatibility with earlier runtimes, or for programs that don't provide an explicit port number (or zero) when exporting remote objects, which is required for generated stubs to be possible, as described in the Javadoc for

  • ↑ "Remote Method Invocation Home". Oracle Technology Network for Java Developers. Redwood Shores, CA, USA: Oracle Corporation. Retrieved 2014-07-14.
  • The Java RMI tutorial - a good starting point to learn RMI. Also check the Hello World in RMI (Java 5)
  • Java RMI online training (Java 7) at the Wayback Machine(archived 2012-08-12) - Very good for training JavaRMI and as reference
  • The RMI page in the JDK 8 docs

  • View original on Wikipedia | Back | FazBrowse Home