Sun Java Solaris Communities My SDN Account Join SDN
 
Tutorials & Code Camps

jGuru: Help: RMI Client Callbacks

 


[Exercise | API Docs | Short Course| Exercises]

Help is available for each task.

Task 1

Define and compile the TimeMonitor interface.

Create the interface TimeMonitor, which has one method. The method is called tellMeTheTime. It accepts one parameter of type Date and returns void.

Remember that remote interfaces must extend java.rmi.Remote and the all remote methods can throw java.rmi.RemoteException.

Compile the file with the command:

javac TimeMonitor.java

Task 2

Define and compile the TimeServer interface.

Create the interface TimeServer, which has one method. The method is called registerTimeMonitor. It accepts one parameter of type TimeMonitor and returns void.

Remember that remote interfaces must extend java.rmi.Remote and the all remote methods can throw java.rmi.RemoteException.

Compile the file with the command:

javac TimerServer.java

Task 3

Complete the implementation for the method registerTimeMonitor in RMIServer.

The class RMIServer implements the TimeServer interface. You will need to complete the implementation of registerTimeMonitor in RMIServer. Refer to the comments in the code file for guidance.

Task 4

Complete the definition of the class TimeTicker.

The class TimeTicker is defined inside the file for RMIServer. You will need to complete the implementation of this class by adding a call to the tellMeTheTime method of the TimeMonitor interface. This is the call that performs the callback to the Applet.

Task 5

Compile the server, RMIServer and create the stub and skeleton files.

Use the javac utility to compile the RMIServer file.

javac RMIServer

Use the rmic utility with RMIServer.

rmic RMIServer

Notice that RMIServer implements the exported service. Because RMIServer extends RMIServer it cannot also extend UnicastRemoteObject. Instead, RMIServer must make an explicit call to UnicastRemoteObject.exportObject before it can register itself with the Registry. This call is normally made automatically in the constructor of UnicastRemoteObject.

Task 6

Prepare the Applet for execution.

The Applet code has been completed for you. You should examine it to see how it implements the TimeMonitor interface and prepares itself for use by RMI with a call to UnicastRemoteObject.exportObject.

First you must compile it with the following command:

javac Applet1.java

Next, create the stub and skeleton files with the rmic utility:

rmic Applet1

Task 7

Start the RMI Server in its own DOS console.

Run the class RMIServer with the java utility.

java RMIServer

Task 8

Start the Applet with the appletviewer.

Use the program appletviewer and execute the Applet.html file. This HTML file contains the commands to run Applet1.class.

appletviewer Applet.html

Copyright 1996-2000 jGuru.com. All Rights Reserved.