| FazBrowse Wikipedia Viewer | Main Page | | |
| Viewing: https://en.wikipedia.org/wiki/Java_remote_method_invocation |
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"); } }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
| View original on Wikipedia | Back | FazBrowse Home |