|
|
FB 4
Internationale Media and Computing
MeSoII: Media Software II
Sommersemester 2003
|
Exercise 12:
Doing it from somewhere else - RMI
We're back to a MageLang
tutorial today (hurrah!), except that this is a newer one and the group is now
called jGuru.
Remote message invocation,
RMI, is all about having one of your objects call a method - and get a result
- that is being offered by another object that is living somewhere in the Java
Universe. This is a pretty amazing concept, and it has been around in Java for
a long time! Back in the good old days when I was learning programming, we had
to do this all ourselves: pack the parameters appropriately, find the other object,
shovel all the data over the network, wait for a result, decode it and go on.
You kids have it so easy these days :-)
- Read the "Introduction
to Distributed Computing" in the tutorial found at http://developer.java.sun.com/developer/onlineTraining/rmi/.
The table "Comparison of Distributed and Nondistributed Java Programs"
is important. Make sure that you understand, more or less, the column about local
objects. The column about remote ones should make sense by the end of the session.
Then read the chapter "Java RMI Architecture" - here we meet our old
friend, the interface, again! And you will find that some knowledge of TCP/IP
will be of help. Describe, at this point, how you think RMI works, in just a few
sentences.
- Let's get going on RMI! Read the chapter "Naming Remote
Objects". We are going to do the little calculator using RMI. Write and compile
the Java code for the service interface using copy & paste from the exercise.
You implementation will have to extend java.rmi.server.UnicastRemoteObject in
order to be of any use. Copy the code given into your directory and compile it.
Now use the RMI compiler, rmic, to generate the stub and skeleton files. Lastly,
we set up the CalculatorServer using a free port on localhost. We now have the
server put together, let's start with a simple little client. Use the one given
in the tutorial for a start. Let it begin using the three consoles as described
in the tutorial. Cool! This all worked on the same machine, now put the client
on another machine and see if you can keep it working! Do not try and implement
a complete calculator with GUI as a client unless you don't want to see your family
for the next week, this is an interesting but difficult extension to the exercise.
- Now
do Magercises 1 and 2 and see if you can get the banking system to work as well.
- (Extra
exercise) If you are bored by this exercise because you did all this during your
internship, do the parameters and callbacks exercises. If you are a glutton for
punishment, plough through the garbage collection section and have a look at serializing
remote objects. Whew!
The URL to your report, which will describe what you did during the exercise
and include links to your code, is due in email box of your instructor by 8.00 next Wednesday. Do not forget to put your names on the top of the report! It is also a good idea put the number of the exercise somewhere in the title of your report.... When you
send the URL of the report to your instructor, always include your partner in the CC. That way we don't get either
2 emails or none, because each or your thought the other was sending it. This has the added advantage that when we answer
you, we can immediately answer both of you without having to look up the
email account of your partner.
Copyright 2003,
Debora Weber-Wulff
(weberwu@fhtw-berlin.de)