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

jGuru: RMI Client Callbacks

 


[Help | API Docs | Short Course| Exercises]

In this exercise you will build a client applet that will act as both a RMI client and a server. Usually applets only act as clients, however in some cases it makes sense for a server to make calls back into the applet. In this exercise the server will make periodic calls to the applet and pass it the current date and time.

To support a callback, the applet must act as an RMI server. It does this by exporting and implementing a remote interface. Our applet will define and implement the TimeMonitor interface. It is designed to be called by a time service that supplies the current date and time.

The server cannot call back to the applet until it knows where to find it. It is the applet's responsibility to register itself with the server. It does this by using the server's registerTimeMonitor method in the TimeServer and passes a reference to itself to the server. interface.

In this exercise, you will need to define the interfaces and the implementations for both the server and the Applet.

RMI Client Side Callbacks

Skeleton Code

TimeMonitor.java
TimeServer.java
RMIServer.java
Applet1.java

Tasks

1. Define and compile the TimeMonitor interface.

2. Define and compile the TimeServer interface.

3. Complete the implementation for the method registerTimeMonitor in RMIServer.

4. Complete the definition of the class TimeTicker.

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

6. Prepare the Applet for execution.

7. Start the RMI Server in its own DOS console.

8. Start the Applet with the appletviewer.

Where help exists, the task numbers above are linked to the step-by-step help page.

Solution Source

TimeMonitor.java
TimeServer.java
RMIServer.java
Applet1.java

Demonstration

When the server is run in its DOS console, the output will be:

Registry created
Bindings Finished
Waiting for Client requests

Then when applet is run in its DOS console, the output will be:

Exporting the Applet
Looking up TimeService at: 
  rmi://<your_computer_name>:10005/TimeServer
We have been registered!

The applet will appear in a window and start to display the current date and time every two seconds.

Next Magercise



Exercises



Short Course



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