Java IDL: Example with Callback Object

Client programs often react to changes or updates that occur in
a server. For example, a client graph or spreadsheet program might
need to be updated with each stock price update on a stock market
server. The client has two options in this scenario:

Periodically ask for the stock price via a method request on
the stock server. This is known as the "polling" or "pull"
model.

Ask to be notified by the server whenever a price change
occurs. This option is referred to as a "callback" or the "push"
model.

The example in this document illustrates how a client program
can pass a callback object to a server, and the server can then
callback to notify changes to the client. At this time, we have
provided the code for an extension of a simple application. Notes
about simplifying the application are contained within the
code.

Writing the Listener Implementation

When the Listener identifies that a message has been received
from the server, it displays the message on the client. For the
example application, the ListenerImpl.java file looks like
the following example.

Instructions for compiling and running the example

To run the example application, you would follow these instructions
on the SERVER machine:

If you've run the example previously, remove any existing
generated files. In the UNIX operating environment, this command
would be as follows:

rm -rf ./classes ./orb.db

Generate the stubs and skeletons. First, you need to create the
directory where the stubs and skeletons will reside, then run the
idlj compiler to generate the stubs and skeletons. This
command would look like this:

At this prompt, you will send messages to the client, but first
you need to start the client application. From the
CLIENT terminal, follow these steps to run the
client. Make sure that you used the host name on which the
server is running in the properties
section of the client code.

To display the functionality of using a callback, you would
enter a data on the server terminal, at the prompt, and it will
display on all client terminals. This could be anything where
clients are interested in some notifications.

One example is a football game score where clients are notified
whenever the score changes.