The Smart Stub example
This example shows how one can create a smart client stub to cache information
returned from a server object. This is useful to minimize the time
it takes to service a request, particularly if processing time is lengthy.
From this example, you will learn how to:
-
Implement a Smart Stub by deriving from the Client's generated stub code
-
Implement a simple cache within the smart stub that caches data from the
server object
Directory Contents
-
Bank.idl
IDL interface for the 'Bank' object.
-
Client.java
This is the Bank client program which was discussed in the
Bank example. In this class,
the client invokes setStubClass() to make use of the
smart stub.
-
Server.java
This is the Bank Server program which was discussed in the
Bank example.
-
SmartAccount.java
This is the implementation of the smart stub for the Account object.
In this class, instead of first sending a request for the balance,
the code checks to see if one has been obtained from a previous request
and cached. if it has not received the balance, then it sends a request
to the server by calling super.balance(), which causes the
base class (the default stub) to do the remote invocation.
-
SmartAccountManager.java
This is the smart implementation of the AccountManager which caches
all accounts opened so far in a dictionary. When a client asks for an
account to be opened for the first time, the smart Account manager
stores the name of the client in a dictionary. The second time a client
asks to open the same account, the manager looks up the name in its
dictionary.
Building this example
Choose Build | Make Project. To see the settings for Bank.idl, right-click the
file and select IDL Properties.
Running this example
-
First make sure that the VisiBroker Smart Agent (osagent
executable) is running on your network.
-
Run the Bank Server.
-
Run the Bank Client.
Return to the top-level examples page.