I hope the following specifications and suggestions can guide you in this coursework so that you can avoid possible traps and can focus on essential technical points without spending too much time. Please read this document carefully. If you think I am saying too much, well, my apologies.
The precise method to test your RMI programs is now given (though you do not have to obey it as far as you can demonstrate essentially the same thing). The default registry, with interfaces and testing programs can be used. See Section 2 below (direct links are here for testing and here for the registry). The link given in Section 2.3 also offers further hints on designing your RMI.
To think of what you need for realising RMI is one of the interesting bits of this coursework, since, in the end, you will say "aha! this is so simple indeed!". Anyway, I hope that giving a few hints to you may not spoil your fun. Here are a few suggestions.
My observations: the first method is interesting and stimulating. To do it would be rewarding. However if you want to be timewise economical you may use a combined method (I should stop here so that I do not tell you everything!). The marshalling methods will be called from a proxy or a CM.
So this is not as complex as you first thought: the whole code should be quite unexpectedly short. Difficulties however lie in the following: so far you have mostly been writing application programs rather than this kind of program, which requires what is often called system programming. That is, you are going to realise fundamental functionalities used for other application programs. A different kind of mind set is necessary to think in that way.
In the rest of this decument, I offer some technical specifications which should help in your decision making.
(a) Primitive datatypes: int and character strings.
(b) Classes: those which directly subclass Object, as
well as remote objects themselves.
We assume (b) can only use primitive data of form (a). [note: if you use serialisation appropriately, you can essentially get rid of this restriction: however I do not require this].
Here you can find the code for a remote server and a client , which are to be used for testing your program.
The following are default constructions. The subsequent suggestions etc. are based on these the default constructions. Maybe it will make your life easier to use these constructions. On the other hand, if you consider it is better, you may refine/change these constructions.
As a default, we assume that the registry etc. returns an
instance of the following class, which offers a default representation
of remote object reference, RemoteObjectRef.java
In the code, there is a "localise" method, which you
will implement according to your design.
The method is used as follows:
aRemoteInterface x= (ARemoteInterface) r.localise();
where r is an instance of RemoteObjectRef above, x is an instance of the proxy class and ARemoteInterface is the class of the remote interface. As noted in Section 1 above, this works because the proxy class should implement the remote interface.
Here is a specification and a code for SimpleRegistry and LocateSimpleResistry, as well as a registry server. The test programs give sample code which uses these classes. Note that the registry program shows a way of using TCP, via the Java socket interface.
This is described here. Please read this part carefully.
For any object o,
Class o.getClass()
returns the runtime class of an object.
For any class/interface c,
Class c.getSuperclass()
returns the Class representing its superclass.
Also the following methods may be useful:
For an appropriate className,
Class forName(String className)
returns the Class object associated with the class or interface with the given string name.
For a class c,
Objec c.newInstance()
returns a new instance of the class c, as if its default constructor (with no argument) is called.
For other pertinent operations, see the sections for Java.lang.object, java.lang.class and java.lang.reflect of the Java API specification. By the way the idea of reflection was invented by Brian Cantwell Smith at Xerox Palo Alto, even though the idea of Class Class has existed in OOP for long years (at least since Smalltalk).