oval
Centre International de Mathİmatiques Pures et Appliquİes
International Center for Pure and Applied Mathematics
A CIMPA-UNSA-INRIA-UNESCO-VIETNAM SCHOOL ON
Objects and Network
RMI Exercises
Emmanuel Chailloux
Emmanuel.Chailloux@lip6.fr
http://www-spi.lip6.fr/~emmanuel
Exercises : RMI
- Test the RMI Points
- Modify the Producer-Consumer
- Hanoi's Towers in RMI
- Adapt the World of robots
Exercises
To test the RMI Points
To read, to understand the following files, to compile them and to test the RMI mechanism.
Some Sources
To modify the Producer-Consumer
The Shop instance is a Remote object to the different clients :
Producer instance and Consumer instances.
- To define ShopRMI interface
- To reuse Shop class and to modify it to implement ShopRMI interface.
- To create the RMI Shop server.
- To Modify clients in order to send and to receive Product instances from the RMI SHop server.
- To test it.
Hanoi's Towers in RMI
Problem Statment:
The Tower of Hanoi is a classic puzzle. It consists of three poles and a set of discs each of different diameter. Initially all the disks are arranged on one of the poles so that each disc is on top of a larger one. The aim is to move the discs, one at a time, from one pole to another, such that a larger disc is never placed on top of a smaller disc, until all the discs are arranged on one of the initially empty poles.
To implement this puzzle in Java, we need two main classes :
- classes Pole and Disc.
- Pole class
has 3 main methods :
void moveTo(Pole dest, Pole tmp, int n)
void push(Disc d)
Disc pop()
- Disc class has 2 main methods :
void goTo(Pole from, Pole to)
int size()
This algorithm is recursive.
If we have 3 poles from, tmp, to and n discs, the following calls resolve the problem : from.moveTo(to,tmp,n)
from.moveTo(tmp.to,n-1);
from.moveTo(to,tmp,1); // from.pop().goTo(this,to);
tmp.moveTo(to,from,n-1);
Some Sources
- To write PoleRMI and DiscRMI interfaces.
- To modify Pole, Disc classes in order to implement theses interfaces.
- To write a server, which has 3 registred poles. The first one contains n discs.
- To write a client application to move discs.
- To test the server and the client.
- To write another application, an inspector, which looks the current positions and display it.
- To modify the inspector to have a graphical representation.
- How can the inspector know when a disc will move?
- To add a checking when a disk comes to a pole if its neighbor has a good size.
- To run 3 servers, one for each pole and to modify client and inspector.
To adapt the World of robots
The world belongs to a World server (RMI). Each robot needs to communicate to this server to know free positions and to indicate its new movement. How do you resolve conflicts between robots?
This document was translated from LATEX by HEVEA.