A Remote Java RMI Registry
by Oliver Haase, Jurgen Wasch, Bo Zhao


Listing One

public RemoteRegistry (int port) throws RemoteException {
  ...
  LiveRef lref = new LiveRef (new ObjID(ObjID.REGISTRY_ID),port);
  new UnicastServerRef (lref).exportObject (this,null);
}

Listing Two

grant {
  permission java.net.SocketPermission "*:*",
    "connect,accept,resolve,listen";
  permission java.lang.RuntimePermission
    "accessClassInPackage.sun.rmi.*";
  permission java.io.FilePermission".rrrbindings",
    "read write,delete";
};


Listing Three
// Remote interface
public interface Hello extends Remote {
  String getHello() throws RemoteException;
}
// Implementation class
public class HelloImplimplements Hello {
  public String getHello() throws RemoteException {
    return "hello, world" ;
  }
}
// Startup of RMI serverobject, including registration of 
// the instantiated server object with remote RMI registry
public class HelloSetup {
  public static void main (String[] args) throws
    UnknownHostException,RemoteException,
    MalformedURLException,NotBoundException,
    InterruptedException,AlreadyBoundException {
  System.setProperty ("java.rmi.server.codebase",
         "http://192.168.2.32/hello.jar");
  Hello stub = (Hello) UnicastRemoteObject.
            exportObject (new HelloImpl(),0);
  //registration with remote RMI-Registry is now possible
  Registry registry = LocateRegistry.getRegistry ("192.168.2.31");
  registry.rebind ("hello",stub);
  System.out.println ("Successfully registered.");
  }
}

Listing Four

public class HelloClient {
  public static void main (String[] args) throws
    RemoteException,NotBoundException {
  Registry registry = LocateRegistry.getRegistry ("192.168.2.31");
  Hello server = (Hello) registry.lookup ("hello");
  System.out.println (server.getHello ());
  }
}




2


