Lab 1 - Java RMI
Lab tasks
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
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.
Example Source
Download source code from https://d3s.mff.cuni.cz/legacy/files/teaching/nswi080/labs/Files/sources-1.zip .
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.
Scripts
make
- Compiles all java source code. No code generation is needed anymore
clean
run-registry
run-server
- 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).
run-client
- 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
bash make
- compiles all Java files
- Run the registry
bash run-registry
- the registry does not print any thing and listens for connections
- Run the server
bash run-server
- the server does not print any thing and listens for connections
- Run the client
bash run-client
- Gets a timestamp on both the client and the server
- Prints both timestamps on both the client and the server
Lab Activity
As a required Lab activity task, change the client to connect to our server.
The RMI registry is running at lab.d3s.mff.cuni.cz:5000
.
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
https://d3s.mff.cuni.cz/legacy/files/teaching/nswi080/labs/Files/task-1-en.html.
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.
-
Node.java
- An interface for a node of a graph
-
NodeImpl.java
- An implementation of such node
-
Searcher.java
- An interface for an algorithm that searches for the distance between nodes in a graph
-
SearcherImpl.java
- An implementation of such algorithm
-
make
- Compiles all java source code
-
clean
-
run-client