| Product: RPC/XDR Toolkit - for Java | Platform: Java | Last updated: 11/8/2001 |
| |
| Broadcast Demo |
| |
The "BroadcastTest.class" sample program demonstrates how to use broadcast RPCs to locate a server. The sample keeps sending broadcast messages to all NFS servers on the local subnet until it receives an answer. It then prints the host name and IP address of the responding server.
This sample can be found in the subfolder \samples located under the folder in which you installed the RPC Toolkit for Java.
Download |
| |
| |
|
| Product: RPC/XDR Toolkit - for Java | Platform: Java | Last updated: 11/8/2001 |
| |
| Callbacks with JRPC |
| |
The sample explains how to use callbacks with Distinct RPC for Java. This can be done with the standard package without any modifications.
Again the sample is based on the well-known counter example. This time a new procedure has been added to the cou.x file, named "do_callback":
void do_callback(string host, int progno) = 4;
This procedure instructs the server to call back the client. In order to be able to do that it tells the server the host name and the (transient) program number it should connect to. An unused transient program number has been obtained in quite the same way as the C sample does by calling the static method "CALLBACKServer.getTransient()". Also, a new server object of class "CALLBACKServer", named "callb_server" has been created. This is a full RPC for Java server object with its own threads for serving client (callback) requests.
The server ("docount.java") contains a new thread class that tries to call back a client every 5 seconds. It checks whether a global variable "cb", pointing to a client object (of class "CALLBACK"), has been set to a non-null value and if so it calls it once before destroying the client again (of course, if required, it might call back several times, not just once).
The two stub classes for the callback "CALLBACK" and "CALLBACKServer" have not been created by Jrpcgen directly. Instead most of their basic skeleton comes from running Jrpcgen and they have been modified to accept the program number as an initialization parameter in the constructor. This means, callback programming has to be done currently at the same level of abstraction as the C binding where also no Jrpcgen-generated code but manually created stubs are required.
To run the sample, start "docount" as the server and "testprg <server-host>" as the client. The client will create a new temporary server object, call the "do_callback" procedure, and wait 10 seconds for the server to call back before terminiating. If everything is running properly the server will call back the "inc" procedure within 5 seconds.
The sample code does not handle synchronization issues. To handle more sophisticated tasks using callbacks you have to be aware that the callback at the client site is executed by a separate thread that has to be synchronized with the actions of the other client threads when accessing shared data. This is the major difference to the C-binding where typically everything is focused on the "select" main loop which has no real concurrency.
This sample can be found in the subfolder \samples\callback located under the folder in which you installed the RPC Toolkit for Java.
Download RPC Toolkit for Java |
| |
| |
|
| Product: RPC/XDR Toolkit - for Java | Platform: Java | Last updated: 11/8/2001 |
| |
| Multithreaded JRPC Server |
| |
The sample illustrates how to implement a multithreaded server.
For comparisons, the same server may be run single or multithreaded.
Again the sample is based on the well-known counter example. First, start
the server either single threaded with
java docount s
or multithreaded with
java docount m
You will see different behavior depending on whether you run a single or a multithreaded server. This is intentional and corrrect because the internal
counter is NOT protected against concurrent access.
Then in at least two other windows start
java testprg localhost inc
or
java testprg localhost dec
The increment and decrement RPC calls include an internal sleep delay to
illustrate the effects of concurrency. Select the UDP or TCP protocol by
uncommenting the appropriate lines.
Note that in the single threaded version all RPCs are put in a queue (and
take longer to process) while in the multithreaded version they are really
processed concurrently. This will also be displayed by the server. It prints
a line on each call and it reports on the number of threads currently active
in RPC procedures.
This sample can be found in the subfolder \samples\thread located under the folder in which you installed the RPC Toolkit for Java.
Download RPC Toolkit for Java |
| |
| |
|
| Product: RPC/XDR Toolkit - for Java | Platform: Java | Last updated: 11/8/2001 |
| |
| Port Mapper Demo |
| |
The "PmapTest.class" sample program contacts the port mapper on the local machine and checks if the demo server is currently running. If the demo server is registered with the local port mapper, then the sample program will display the port on which the server is running.
This sample can be found in the subfolder \samples located under the folder in which you installed the RPC Toolkit for Java.
Download RPC Toolkit for Java |
| |
| |
|
| Product: RPC/XDR Toolkit - for Java | Platform: Java | Last updated: 11/8/2001 |
| |
| RPCInfo |
| |
RPCInfo makes an RPC call to an RPC server and lists all the registered RPC services on host. If host is not specified, the localhost is the default.
This sample can be found in the subfolder \samples\rpcinfo located under the folder in which you installed the RPC Toolkit for Java.
Download RPC Toolkit for Java |
| |
| |
|