|20-CS-694||Advanced Programming Techniques||Spring 2012|
It is possible for clients to remotely add class servers to an rmi registry. This is accomplished by means of a meta server that receives the name of the server to register, the binding name, constructor argument types, and specific arguments from the client. The meta server registers the named server class, creating an instance with the passed arguments. This allows the same server class to be used in infinitely many ways. Therefore, free-form binding names are supported.
The following is an example. The meta server is given in Server.java. Classes it serves in this example are SuccessorImpl, TimesImpl, MergeImpl, and HammingImpl. All Impl classes implement the Stream interface, which requires implementing a next() method, and use an object of class Monitor to implement the putIt() and next() methods. Using the Monitor class is necessary because it is not possible to extend from an abstract class as before (recall the old "Stream" class) since it is required for all Impl classes to extend the UnicastRemoteObject class. Supplying the Thread for use with putIt() and next() methods is a bit different from normal: the Impl classes implement the Runnable interface but the runnable Thread itself is supplied by the Monitor class (a little easier on the user's eyes this way).
An object of any one of the Impl classes delivers tokens from a possibly infinite stream of tokens, one at a time, when requested using next(). Particular streams are specified using constructor arguments. The following table explains what services the above classes provide and what arguments the constructors take.
|SuccessorImpl|| SuccessorImpl(String n)
|TimesImpl|| TimesImpl(String n, Stream s)
|MergeImpl|| MergeImpl(Stream s1, Stream s2)
|HammingImpl|| HammingImpl(BigInteger p, BigInteger m)
Examples of the use of these classes is shown in the following table. All classes use an object of the GetStream class to connect to the RMI registry. This happens when the getStream() method is invoked with arguments for the respective constructors. All client classes below are applets containing a textarea for viewing stream tokens and a "Get Next" button for demanding the next token in the stream. The hostname of the RMI registry is hardwired into the code.
|SuccessorClient||Gets tokens 1, 2, 3, ... from a Successor stream.|