[Moved here from Remote Method Invocation]
From Java Programming
RMI allows an object to invoke methods of a remote object
Remote object runs on a different Java Virtual Machine (JVM)
JVMs may reside on different platforms
See java.sun.com for RMI documentation.
RMI architecture
From java.sun.com
The illustration below depicts an RMI distributed application that uses the registry to obtain references to a remote object. The server calls the registry to associate a name with a remote object. The client looks up the remote object by its name in the server's registry and then invokes a method on it. The illustration also shows that the RMI system uses an existing web server to load bytecodes of classes written in the Java programming language, from server to client and from client to server, for objects when needed. RMI can load class bytecodes using any URL protocol (e.g., HTTP, FTP, file, etc.) that is supported by the Java platform.
java.sun.com
Stubs and Skeletons
Stub object represents server object on the client
Skeleton object passes remote calls to the server
Remote reference layer defines remote call semantics
Transport layer provides connection
Development process:
Define an interface that inherits from Remote interface:
SomeRMIClass
Implement the interface:
SomeRMIClassImpl
Generate stub and skeleton classes with the rmic utility
RMI Interfaces and Classes
From java.sun.com
The interfaces and classes that are responsible for specifying the remote behavior of the RMI system are defined in the java.rmi package hierarchy. The following figure shows the relationship between several of these interfaces and classes:
java.sun.com
Parameter Passing with RMI
Remote object
Implemets Remote interface
Passed by reference
Non-remote object
Must be known by remote application
Must be serializable (when shared by client and server processes)
Passed by value
Only non-static variables are passed
Remote methods throw Remote Exception
Locating Remote Objects
Simple bootstrap registry used to store reference to objects
Can be started from command line (rmiregistry) or programmatically (java.rmi.registry.Locate Registry)
Must run on same machine as server
Server:
Bind objects to the registry using java.rmi.Naming class
Client:
Locate remote objects using java.rmi.naming.lookup(URL)
See also Rmi Patterns, Transparent Rmi, Rmi Vs Corba
See original on c2.com