![]() |
Minimalist Service
|
|---|
|
This is a minimalist example of a Jini server and a Jini
client.
|
|
When you start Jini, the |
![]() Figure 1: Jini is Started |
|
Edit the JiniExample1
Start the web server.
|
![]() Figure 2: The Service's Web Server is Added |
|
Start the Jini service.
|
![]() Figure 3: The Service is Added |
|
Start the client.
|
![]() Figure 4: The Client is Added |
|
|
|
This is a Jini client. It finds the Jini lookup service and asks it
for the service This example requires the file |
|
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
To find the
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.
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.
|
|
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
To register a class with the lookup manager, you need to create an array
of
Then
Once the services arrive in the
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.
|
|
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.
|
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 |