Accessing Remote Objects as a Client
Now that we’ve defined a remote object interface and its server implementation and generated the stub and skeleton classes that RMI uses to establish the link between the server object and the remote client, it’s time to look at how you make your remote objects available to remote clients.
The Registry and Naming Services
The first remote object reference in an RMI
distributed application is typically obtained through the RMI
registry facility and the Naming
interface. Every host that wants to export remote references to
local Java objects must be running an RMI registry daemon of some kind. A registry daemon listens (on a
particular port) for requests from remote clients for references to
objects served on that host. The standard JDK distribution provides
an RMI registry daemon, rmiregistry. This
utility simply creates a Registry
object that listens to a specified port and then goes into a wait
loop, waiting for local processes to register objects with it or for
clients to connect and look up RMI objects in its registry. You
start the registry daemon by running the
rmiregistry command, with an optional argument
that specifies a port to listen to:
objhost% rmiregistry 5000 &
Without the port argument, the RMI registry daemon listens on
port 1099. Typically, you run the registry daemon in the background
(i.e., put an &
at the end of
the command on a Unix system or run start rmiregistry [
port
]
in a command prompt on a Windows system) or run it ...
Get Java Enterprise in a Nutshell, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.