Noel Enete
Minimalist Service


This is a minimalist example of a Jini server and a Jini client.
  1. Run example
  2. Client
  3. Server
  4. ServerInterface
  5. Compile example

Run Example


Start Jini.

When you start Jini, the r1 through r4 scripts launch the Jini Lookup Service and its supporting programs. Notice that there is a web server present and that the lookup service has registered the class portion of its stub object with the web server.




Figure 1: Jini is Started


Edit the JiniExample1 SetInstallPoint script file.

  • Open a commandline and change to the directory \java \nuggets \pages \examples \JiniExample1 (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.

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




Figure 2: The Service's Web Server is Added


Start the Jini service.

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




Figure 3: The Service is Added


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 \JiniExample1 \client-side (remove the spaces from the path). Run the client program by executing the r script file.




Figure 4: The Client is Added


Client


This is a Jini client. It finds the Jini lookup service and asks it for the service "MyServer". Jini hands back the interface MyServerInterface which is used to call a method in MyServer. The results are written to standard output.

This example requires the file MyServerInterface.class to be located in the same directory as the client. The next example, JiniExample2, shows how to lift this restriction. Although the approach in this example seems counter to the benefits of Jini, if a standards committee issues a collection of generalized standard interfaces, they would be used in much the same way as MyServerInterface is used in this example.





Figure 1: MyClient


First, an RMI security manager must be used to allow the RMI class loader to try and find class files that are needed but are not in the launching directory or classpath. It fetches them from the specified web server.

To find the Jini lookup service, a LookupLocator object is instantiated with an URL that points to the machine. There are many other ways to do this, but this is the simplest. Notice the protocol specified in the URL is jini:. When the lookup object is asked to find the ServiceRegistrar, it goes out and finds the lookup service and returns a ServiceRegistrar object. This is the object through which you interact with the lookup service.

To find the MyServer service, an array of Entry objects is constructed that describe the attributes of the desired service. This array is passed to the registrar's lookup() method. The lookup method returns the server's interface object MyServerInterface.

It may seem suprising that an interface object is returned rather than the server object itself. This is a convention that was established by RMI and is used when talking to a Jini service. MyClient uses the interface object to call the sayHello() method in MyServer and the resulting string is displayed at the standard output device.

The launching script file specifies a security file for JKD 1.2 security manager and a codebase for any classes that must be loaded from the web server.

Server


The server finds the Jini lookup service and registers with it. Then it asks the lookup service for all of the services that have registered and displays them on the standard output device.






Figure 2: MyServer


Notice that this server has a specific signature. It subclasses the UnicastRemoteObject to identify itself as an RMI server object that be accessed from remote machines. It implements the ServiceIDListener as a required feature of the JoinManager object.

The significant interface is MyServerInterface. This interface contains the method signatures of each method a client can call. In this case, the only method contained in the interface is the method sayHello().

To register a class with the lookup manager, you need to create an array of Entry objects that collectively describe the attributes of the new service. Then hand that array to the JoinManager object. The JoinManager takes care of locating the lookup service, performing the registration, and renewing the lease of the service as long as the service is running. It is the recommended way to register with Jini and it is a delightfully complete service.

Then MyServer locates the lookup service and asks for all of its registered services and displays them on the standard output device. To get the services, the ServiceRegistrar object is sent the lookup() method specifying the attributes of the desired service and specifying the maximum number of services desired (in this case 50).

Once the services arrive in the ServiceMatches object, they are accessable as instance variables. The array variable holds ServiceItem objects and its instance variable service holds the service object itself.

The launching script file specifies a security file for JKD 1.2 security manager and a codebase for any classes that must be loaded from the web server.

Server Interface


The server interface object identifies which methods in the server object have been made available to clients.



Figure 3: MyServerInterface


In this case, the only method specified is the sayHello() method.

RMI Server interfaces must all be public and extend the Remote interface. The Remote interface is unusual because it has no methods. It simply sets a bit that identifies itself as a remote object. All methods in the interface must throw the RemoteException.

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 4: Compile Script




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