Title: The RMI Registry
1The RMI Registry
2The registry
- A standalone RMI Naming Service
- run from the OS commandline
- The java.rmi.registry package
- defines the low level API for the registry and
the registry interface and its methods. - bind(), rebind(), list() and unbind()
- Can be used to find or create a registry
3LocateRegistry
- Java.rmi.registry.LocateRegistry class
- used to get a handle on a registry that can then
be queried using registry interface methods
Registry r java.rmi.registry.LocateReg
istry.getRegistry(www.foo.com) MyRemoteObject
o (MyRemoteObject)r.lookup(MyClass)
- MyClass is not treated as a URL, it is the name
of the that the object being queried -
getRegistry returns a reference to an instance of
a registry running on the remote system
4Example
Registry reg MyRemoteObject ro try ro
new MyRemoteObject() // get a handle
on the local registry server reg
java.rmi.registry.LocateRegistry.getRegistry()
// bind the object to the registry
reg.bind(MyObject, ro) catch (
RemoteException e ) out.println(Couldnt locate
registry) catch ( AccessException e )
// registry didnt allow
access out.println(rebind(),
access was denied)
5Implementing the registry interface
- Can be started only on the machine that is
hosting the application - should be used with ports above 1024
- use createRegistry method of java.rmi.registry.Loc
ateRegistry class
6Example
Registry reg // start up a registry object try
reg java.rmi.registry.LocateRegistry.
createRegistry(5100) catch
(RemoteException e
out.ptintln(Couldnt create registry, try
another port) // create an object and
register it try MyRemoteObject ro
new MyRemoteObject() reg.rebind(MyObjec
t , ro ) catch (RemoteException e)
out.println(error creating
remote object or binding to registry)
catch (AccessException ax)
out.println( operation rebind, not allowed)
7Example (cont.)
// print a list of all objects bound to the
registry String list try // get a
list of the object names list
reg.list() catch (RemoteException rx)
out.println(list method
failed) catch (AccessException ax)
out.println(Access denied)
// print the list for (int j0 j lt
list.length j) out.println( listj)