The Event Handler example
The Event Bank example s based on the simple bank
example to open a bank account and to query the balance in a bank account.
It illustrates how to create communication event handlers that allow client
applications and object implementations to define methods that the ORB
will invoke to handle events such as the success or failure of a bind request
or the failure of an object implementation.
From this example, you will learn how to:
-
Create a communication event handler class for your object, defining the
event methods you wish to handle
-
Provide implementations for the event methods you wish to handle
-
Add code to the client or object implementation to register the communication
event handler
Note that two different communication event handler classes are provided
because of the types of events that can be handled are different for clients
and object implementations.
Directory Contents
-
Bank.idl
IDL interface for the Bank object.
-
Server.java
Bank server. Creates an instance of the Bank and calls org.omg.CORBA.BOA.impl_is_ready()
to make this object available to client programs. The Bank Server
implementation implements two methods: open, which opens a bank
account, and balance, which returns the balance in a person's
account whose name is provided as input (by generating a random number).
Here, the Server creates an Implementation Communication Event handler,
registers two such Communication event handlers with the ORB using the
reg_glob_impl_handler() and reg_obj_impl_handler() methods
respectively.
-
Client.java
This is the Bank client. It binds to an AccountManager object
and invokes open() to open a bank account. It then invokes balance()
on the account object reference obtained. In particular, the client
creates a Client Communication event handler, registers two such communication
event handler instances with the ORB, one globally for all objects the
client uses and one for a specific object using the reg_glob_client_handler()
and reg_obj_client_handler() methods respectively.
-
ClientApplet.java
This is the Bank Client Applet.
-
ClientApplet.html
This is the html file to download the ClientApplet.
-
Makefile (vbmake.bat on Windows): Used to build all the test targets.
Building this example
Typing make (vbmake on Windows) in the event_bank
subdirectory will cause the Bank.idl to be run through
the idl2java compiler. It will also build the following classes for the
examples described above:
-
Server.class
-
Client.class
-
ClientApplet.class
Compilation Errors and Warnings
You will see the following compilation warning when you type make
(vbmake on Windows) in the event_bank subdirectory
or when you explicitly compile ClientApplet.java
using:
prompt>javac ClientApplet.java
Note: ClientApplet.java uses a deprecated API. Recompile with
"-deprecation" for details.
1 warning
This warning occurs because the example uses a Java API that has been deprecated
since JDK1.1. The calls to the deprecated Java API have not been changed
for the sake of JDK1.0.2 users.
You may also see the following compilation error when you compile this
example using either JDK1.0.2 or JDK1.1.1:
prompt>javac Client.java
Client.java:3: Package com.visigenic.vbroker.interceptor not found
in import.
import com.visigenic.vbroker.interceptor.*;
^
1 error
The above error occurs because the javac compiler in JDK1.0.2 and JDK1.1.1
cannot locate packages imported from JAR files. The solution to this problem
is to either:
-
Unjar the vbjorb.jar file found in the VisiBroker for Java 3.2 installation/lib
directory using the following command:
prompt>jar xvf vbjorb.jar
Modify the example: delete the import statment and explicitly prefix each
occurrence of classes from the imported package with the complete package
name.
Upgrade to JDK1.1.2 or higher
Running this example
To run this example, first make sure that the VisiBroker Smart Agent (osagent
executable) is running on your network. Then start the Bank Server using
the command:
prompt> vbj Server &
(start vbj Server on Windows)
// make the server run in the background
Next, open a user's bank account and query the balance in the account using
the command
prompt> vbj Client john
or
prompt> vbj Client
// uses a default name
or
You could use a Java-enabled browser and load ClientApplet.html
Return to the top-level examples page.