Support seamless remote invocation on objects in different virtual machines. Support callbacks from servers to applets. Integrate the distributed object model into the Java language in a natural way while retaining most of the Java language's object semantics. Make differences between the distributed object model and local Java object model apparent. Make writing reliable distributed applications as simple as possible. Preserve the safety provided by the Java runtime environment."
Quoting again from Sun's Remote Method Invocation Specification:
In the Java distributed object model, a remote object is one whose methods can be invoked from another Java Virtual Machine, potentially on a different host. An object of this type is described by one or more remote interfaces, which are Java interfaces that declare the methods of the remote object.
Remote method invocation (RMI) is the action of invoking a method of a remote interface on a remote object. Most importantly, a method invocation on a remote object has the same syntax as a method invocation on a local object.
The Java distributed object model differs from the Java object model in these ways:
The following diagram provides a time-line for interactions and events necessary to write
Here is the source code:
file: Hello.java
import java.rmi.*; public interface Hello extends java.rmi.Remote { String sayHello() throws java.rmi.RemoteException; }
file: HelloMain.java
import java.awt.*; import java.rmi.*; public class HelloMain { String message = ""; public static void main(String[] args ) { // Create and install a security manager if(System.getSecurityManager()==null) System.setSecurityManager(new RMISecurityManager()); try { Hello obj = (Hello)Naming.lookup("//jinx.umsl.edu/~siegel/myRMI/HelloServer"); System.out.println( obj.sayHello()); } catch (Exception e) { System.out.println("HelloApplet exception:"+ e.getMessage()); e.printStackTrace(); } } }file: HelloImpl.java
import java.rmi.*; import java.rmi.server.UnicastRemoteObject; public class HelloImpl extends UnicastRemoteObject implements Hello { private String name; public HelloImpl(String s) throws RemoteException { super(); name = s; } public String sayHello() throws RemoteException { return "Hello World!"; } public static void main(String args[]) { // Create and install a security manager System.setSecurityManager(new RMISecurityManager()); try { HelloImpl obj = new HelloImpl("HelloServer"); Naming.rebind("//jinx.umsl.edu/~siegel/myRMI/HelloServer", obj); System.out.println("HelloServer bound in registry"); } catch (Exception e) { System.out.println("HelloImpl err: " + e.getMessage()); e.printStackTrace(); } } }
I will work in a directory "myRMI" in my public_html directory. Since references will be through URLs we need to be in public_html
grant { permission java.net.SocketPermission "*:1024-65535","connect,accept"; permission java.net.SocketPermission "*:80" , "connect" ; };
the message that we get back is: HelloServer bound in registry.
I will run it from my Windows 2000 laptop: