The main
method of the service first needs to create
and install a security
manager: either the RMISecurityManager
or one that you have
defined
yourself.
A security manager needs to be running so that it can guarantee that the classes loaded do not perform "sensitive" operations. If no security manager is specified, no class loading for RMI classes, local or otherwise, is allowed.
The main
method of the service needs to create one or
more instances of the
remote object which provides the service.
The constructor provided by UnicastRemoteObject
exports the remote object, which means that
once created, the
remote object is ready to begin listening for incoming calls.
For a caller (client, peer, or applet) to be able to invoke a method on a remote object, that caller must first obtain a reference to the remote object. Most of the time, the reference will be obtained as a parameter to, or a return value from, another remote method call.
For bootstrapping, the RMI system also provides a URL-based registry that
allows you to bind a URL of the form //host/objectname
to the
remote
object, where objectname
is a simple string name. Once a remote
object is
registered on the server, callers can look up the object by name, obtain a
remote
object reference, and then remotely invoke methods on the object.
Note the following about the arguments to the call:
obj
argument.
Remote
implementation objects like instances of HelloImpl
never leave
the virtual
machine where they are created, so when a client performs a lookup in a
server's remote object registry, a reference to the stub is returned.
Next is the source for the ThermApplication.java
file.