Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
 

RMI Client Callbacks


by jGuru

[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

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

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.


[ This page was updated: 23-Feb-2000 ]
Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-2000 Sun Microsystems, Inc.
All Rights Reserved. Terms of Use. Privacy Policy.