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
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.
Building this example
To build the example, select Build | Make Project. To modify the options passed
to IDL2JAVA, right click the Bank.idl 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.
or
You could use a Java-enabled browser and load ClientApplet.html
Return to the top-level examples page.