![]() |
Service without RMI
|
|---|
|
This example demonstrates how to construct a Jini service and
Jini client so that RMI (Remote Method Invocation) is not used
when invoking the service.
|
To run this example Jini must first be started. Even though this
service will not use RMI to receive its service requests, the
RMI daemon, r2.bat, still needs to be launched because the
lookup service, reggie, is dependent upon it.
Then move the webserver files from this example to the webserver directory:
Then start the server:
Then start the client:
|
|
To simplify this example, the client assumes that the lookup service
is running on the localhost and makes a unicast search for it.
|
|
Figure 1: MyClient |
|
The client extracts the proxy object from the lookup service.
When it wants to invoke service from The proxy object actually makes the call to the server. The only element of RMI that is contained in this example
occurs in the first part of this client. When the
For that reason, I coded the client
to set the RMISecurityManager. This allows the class loader
to follow the codebase in the serialized object and make a
http request for the |
|
The server proxy object lives in the lookup server and is
sent to the client upon request. The client calls the proxy's
methods and the proxy makes any needed calls to the server.
|
|
Figure 2: MyServerProxy |
|
The server instantiates the proxy and hands it to the lookup service. During the instantiation, the server's IP and port are passed to the proxy and held in instance variables. Then the client pulls the proxy from the lookup service and calls one of its methods. The proxy method, opens a socket and communicates to the server through normal socket communications. The socket protocol used in this example is the simplest possible
socket interaction. For every connection the server receives, it
sends back a string. Normal socket communications call for
the client to send a length and request then the server responds
with a length and a reply.
|
|
This interface identifies what methods the client can call in
the proxy.
|
|
Figure 3: MyServerProxyInterface |
|
|
|
This Jini service receives its requests through socket
connections rather than through remote method invocations.
|
|
Figure 4: MyServer |
|
When this server is instantiated, it launches a new thread that opens a server socket on port 7777. This socket expects to receive requests from the server's proxy object over this socket. After instantiation, the server's proxy object is handed to the lookup service and the client pulls it from the lookup service. Whenever the client wants to invoke service from the server, it makes a call to the proxy object which opens a socket to the server. In this example, every new socket connection receives a simple
string reply. In a normal socket protocol, the proxy would speak
first and send a request (preceded by a length in the case of a
string request). Then the server would respond with an appropriate
reply.
|
|
by Noel Enete . . . www.enete.com . . . noel@enete.com |