Lab 2 - Java RMI
The tasks for today are:
- Use Java RMI in a simple example
- download the example code
- compile and run the example program
- Lab activity
- modify the example program
- connect to our server and make a remote method invocation
- send the transferred data by e-mail, to be counted as lab activity
- Read the homework assignment
Java RMI (Remote Method Invocation) is a system for distributed objects and remote procedure calls in Java.
It is part of the standard JDK distribution.
Download source code from https://d3s.mff.cuni.cz/teaching/nswi080/labs/ .
Unzip the code and explore the sources in the Example directory.
- Example.java contains a definition of an interface which enables remote calls. Note the usage of Remote and RemoteException.
- ExampleImpl.java contains an implementation of this interface. This calss extends UnicastRemoteObject, so it is automatically exported during construction, and therefore the instances are remotely accessible.
- ExampleServer.java is a Java application which creates a single remotely accessible instance and binds it to the name HelloServer in RMI registry running on the same computer
- ExampleClient.java is a Java application which retrieves a proxy to the remotely accessible object from the RMI registry and calls both of its methods.
Note that for simplicity, all classes are in the default package.
- Compiles all java source code. No code generation is needed anymore
- Starts the server application.
- The option java.rmi.server.hostname specifies the name of the server that will be used in proxies exported by this server. If the object should be accessible over the internet, must be change to the address of the computer (for example, u-plX.ms.mff.cuni.cz).
- Runs the client application
Note that for simplicity, all programs run with the same classpath, where all the classes can be found.
Running the example
- Compile the programs
- compiles all Java files
- Run the registry
- the registry does not print any thing and listens for connections
- Run the server
- the server does not print any thing and listens for connections
- Run the client
- Gets a timestamp on both the client and the server
- Prints both timestamps on both the client and the server
As a required Lab activity task, change the client to connect to our server.
The RMI registry is running at
Run the client and e-mail the output of the program to the lab assistant (who will respond with a confirmation).
Read the homework assignment
Follow the link from https://d3s.mff.cuni.cz/teaching/nswi080/labs/.
Explore assignment source code
The code provided in Homework-Input is a local implementation
your task is to extend this implementation with RMI according to the assignment.
- An interface for a node of a graph
- An implementation of such node
- An interface for an algorithm that searches for the distance between nodes in a graph
- An implementation of such algorithm
- Compiles all java source code