Applications Classes for Each Object






Recall from a previous slide that we must write a thermometer server application class to

  1. Create and install a security manager.

    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.

  2. Create one or more instances of a remote object.

    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.

  3. Register at least one of the remote objects with the RMI remote object registry, for bootstrapping purposes.

    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:

    • The host defaults to the current host if omitted from the URL, and no protocol needs to be specified in the URL.
    • The RMI runtime substitutes a reference to the remote object's stub for the actual remote object reference specified by the 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.
    • Optionally, a port number can be supplied in the URL: for example //myhost:1234/HelloServer. The port defaults to 1099. It is necessary to specify the port number only if a server creates a registry on a port other than the default 1099.
    For security reasons, an application can bind or unbind only in the registry running on the same host.

Next is the source for the ThermApplication.java file.