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
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.
e.g. Stream a = new SuccessorImpl("1");
|Serves tokens from the stream 1, 2, 3, ... (that is, n
||TimesImpl(String n, Stream s)
e.g. Stream a = new TimesImpl("3", stream);
|Assumes Stream s serves BigInteger tokens.
Multiplies each token by the BigInteger n.
||MergeImpl(Stream s1, Stream s2)
e.g. Stream a = new MergeImpl(stream1,stream2);
|Assumes Stream s1 and Stream s2 serve
BigInteger tokens in increasing order. Produces a single
stream containing all tokens from s1 and
s2 in increasing order.
||HammingImpl(BigInteger p, BigInteger m)
e.g. Stream a = new HammingImpl(primes, b);
where BigInteger b = new BigInteger("1");
and BigInteger primes = new BigInteger;
and primes = new BigInteger("11");, etc.
|Serves the Hamming sequence associated with the list of prime
numbers given by BigInteger p. The BigInteger m is
technically not needed: it is used to help establish a unique binding
name for Hamming subsequences and is the multiplier of tokens in that
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.
||Gets tokens 1, 2, 3, ... from a Successor stream.
||Creates two Successor streams, multiplies tokens of one
by 7 and one by 5. Outputs both in the textarea.
||Creates two Successor streams, a Times stream
which multiplies by 7 and a Times stream that multiplies by
5. Each Times stream connects to a Successor
stream. Serves the Merge of the two Times streams.
||Serves tokens from the hamming sequence for the primes list
- Collect all Impl and Client files along with
Makefile. Change the Makefile to
suit your computer.
- Type make all
- Copy all Stub, Skel, Impl class files
to ~java/jre/lib or the usual place where the jar files
for your java distribution reside. Also copy Server.class and
- Leave Stub and Client class files as well as
the Stream.class, and
IntObject.class in the user's directory hierarchy.
- Type make rmi to start the registry and the server.
- Type make run_ham to run the Hamming sequence applet.
Hit the "Get Next" button to get the next token in the stream.
The servers that become registered are listed in the shell when
they are registered.