1 / 7

The RMI Registry

The RMI Registry. CS-328 Dick Steflik. The 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()

Download Presentation

The RMI Registry

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The RMI Registry CS-328 Dick Steflik

  2. The 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

  3. LocateRegistry • 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.LocateRegistry.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

  4. Example 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(“Couldn’t locate registry”); } catch ( AccessException e ) { // registry didn’t allow access out.println(“rebind(), access was denied”); }

  5. Implementing 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.LocateRegistry class

  6. Example Registry reg; // start up a registry object try { reg = java.rmi.registry.LocateRegistry.createRegistry(5100); } catch (RemoteException e { out.ptintln(“Couldn’t create registry, try another port”); } // create an object and register it try { MyRemoteObject ro = new MyRemoteObject(); reg.rebind(“MyObject” , ro ); } catch (RemoteException e) { out.println(“error creating remote object or binding to registry”); } catch (AccessException ax) { out.println(“ operation rebind, not allowed”); }

  7. Example (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 j=0 ; j < list.length; j++) out.println( list[j]);

More Related