'''[Moved here from RemoteMethodInvocation]''' From JavaProgramming * RMI allows an object to invoke methods of a remote object * Remote object runs on a different JavaVirtualMachine (JVM) * JVMs may reside on different platforms See http://java.sun.com/products/jdk/rmi/ for RMI documentation. '''RMI architecture''' ''From http://java.sun.com/j2se/1.4/docs/guide/rmi/spec/rmi-objmodel2.html'' 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. http://java.sun.com/j2se/1.4/docs/guide/rmi/spec/rmi-objmodel2a.gif '''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 http://java.sun.com/j2se/1.4/docs/guide/rmi/spec/rmi-objmodel2.html'' 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: http://java.sun.com/j2se/1.4/docs/guide/rmi/spec/rmi-objmodela.gif '''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 RemoteException '''Locating Remote Objects''' * Simple bootstrap registry used to store reference to objects * Can be started from command line (rmiregistry) or programmatically (java.rmi.registry.LocateRegistry) * 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 RmiPatterns, TransparentRmi, RmiVsCorba ---- CategoryJava