The RMI Registry - PowerPoint PPT Presentation

About This Presentation
Title:

The RMI Registry

Description:

bind the object to the registry. reg.bind('MyObject', ro) ... { out.println('error creating remote object or binding to registry'); } catch (AccessException ax) ... – PowerPoint PPT presentation

Number of Views:82
Avg rating:3.0/5.0
Slides: 8
Provided by: dickst
Category:
Tags: rmi | bind | registry

less

Transcript and Presenter's Notes

Title: The RMI Registry


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.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
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(Couldnt locate
registry) catch ( AccessException e )
// registry didnt 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.Loc
    ateRegistry class

6
Example
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)

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 j0 j lt
list.length j) out.println( listj)
Write a Comment
User Comments (0)
About PowerShow.com