Noel Enete
Service with a User Interface


This is an example of a server that registers an applet with Jini.

The client pulls the applet from Jini and launches it in a Frame window. When the applet's button is pressed, the applet uses Jini to find and call the server. All activity is logged to the standard output device.

  1. Run example
  2. Client
  3. Server
  4. ServerInterface
  5. ServerApplet
  6. Compile example

Run Instructions


Start Jini.

Edit the JiniExample2 SetInstallPoint script file.

  • Open a commandline and change to the directory \java \nuggets \pages \examples \JiniExample2 (remove the spaces from the path).
  • Edit the script file SetInstallPoint (for Linux) and SetInstallPoint.bat (for NT) and change them to reflect your environment.

Start the web server and the Jini service.

  • Open a new command line and change to the server run directory: \java \nuggets \pages \examples \JiniExample2 \server-side (remove the spaces from the path). Run the web server program by executing the r1 script file.
  • Open a new command line and change to the same directory: \java \nuggets \pages \examples \JiniExample2 \server-side (remove the spaces from the path). Run the server program by executing the r2 script file.

Start the client.

  • Wait until the server is up (~15 seconds) then open a new command line and change to the client run directory: \java \nuggets \pages \examples \JiniExample2 \client-side (remove the spaces from the path). Run the client program by executing the r script file.
  • When the applet is launched, click on the button. Notice the output in the client window and in the server window and in the webserver window. The first time the button is pressed, a few classes are fetched from the webserver.

Client


This is the client. Instead of fetching the server class from Jini, it enumerates through the attributes of the server and launches the applet attribute in a frame. The user is allowed to manipulate the applet from there. When the button is pressed, a call is made to the server object. All activity is written to the standard output device of the client and the server windows.





Figure 2: MyClient


This client is substantially like that of example1 except the client does not need to have any knowledge of "MyServer".

Instead of constructing attributes that look specifically for "MyServer", it enumerates through all the services in the registrar. If it comes across a service that contains an attribute that is a subclass of Applet, it launches it.

To launch the applet, its init() method is called first. Then the applet is placed in a launched frame window. The MyFrame window is a subclass of Frame and can be found further down in the listing.

Notice that this client has presented the user with an applet that it found in Jini. The user can use the applet to interact with its server. All of this happened without the client having prior knowledge of the applet or the service.

Server


The server registers itself with Jini and registers its applet as one of the attributes it passes to Jini. The activity is displayed on the standard output device.






Figure 3: MyServer


The new idea is in the JoinManager section. The server adds MyServerApplet (which implements the Entry interface) as one of the server's attributes that it passes to Jini during registration.

Then, any client can enumerate through this service's attributes and test to see if the attribute is a subclass of Applet. If so, the client can assume this is the service's user interface and launch it for the user.

Server Interface


There is nothing new in this server interface.


Figure 4: MyServerInterface


Server Applet


This is the server's user interface -- an applet.

In this example, the applet puts up a button. When the user presses the button, the applet invokes the sayHello() method in the server. All activity is written to the standard output device.


Figure 5: MyServerApplet


This applet has a handle to the remote server in the instance variable myServerInterface. This was populated in MyServer when the applet was instantiated. This is what is used to call the server.

When the button is pressed, the callServer() method calls the server's sayHello() method.

Since this applet is used as an attribute of the service, it implements the Entry interface (all attributes should be Entries). Entries must be serialized as they are passed to the lookup service, so each instance variable that must be retained during serialization must be declared public.

Compile Example


To compile the example, run the c compile script. This script places the output of the compile process in 2 separate run directories. The server-side subdirectory launches the Jini service. The client-side subdirectory launches the Jini client.



Figure 6: Compile Script




by Noel Enete . . . www.enete.com . . . noel@enete.com