Free High Performance CORBA Notification Service from AT&T Laboratories |
omniORB Home AT&T Research |
Back to Documentation Home Page
omniNotify supports push and pull event communication for suppliers of events. A push supplier sends events to a omniNotify event channel by invoking a push operation on the proxy object it is connected with. A pull supplier implements a pull operation that is invoked by an event channel to retrieve any event(s) the supplier may have available. The event messages send to an event channel by a push supplier or requested from a pull supplier by an event channel belong to three categories:
To develop event supplier applications, you must implement these suppliers as normal CORBA applications that communicate with event channels through the CORBA Notification Service IDL interfaces. These IDL definitions are supplied with omniNotify.
In the remainder of this document we will present two example event supplier applications. Both of these applications use CosNotification::StructuredEvent messages, and they differ in the event communication model they implement; one is a push supplier and the other is a pull supplier. In both applications, the following steps have to be executed before any event communication takes place:
Our supplier implements the CosNotifyComm::StructuredPushSupplier interface. This is done by inheriting from the corresponding skeleton class, which is generated by the IDL compiler, and implementing all abstract methods defined in this class.
// -*- Mode: C++; -*- class
StructuredPushSupplier_i : |
We can locate a reference to the default event channel created by the omniNotify notification server using the CORBA Naming Service. The code segment below illustrates how this is done, assuming that the name of the default channel is "EventChannel" and the name of the Naming Service is "NameService".
// -*- Mode: C++; -*- CORBA::ORB_var
orb; // The following assumes that the orb reference is initialized. name_service =
orb->resolve_initial_references("NameService"); |
The following code segment illustrates how we can connect the event supplier to the channel. First, we need to obtain a reference to a CosNotifyChannelAdmin::SupplierAdmin object. This can be done by either requesting the creation of a new object or retrieving a reference to the default SupplierAdmin object that is created by each channel. The ID of this object is 0. Next, we create a StructuredProxyPushConsumer object using the SupplierAdmin reference from the previous step. Once this is done, we connect the supplier instance to this proxy object and start supplying structured events to the channel.
// -*- Mode: C++; -*- CosNotifyChannelAdmin::AdminID
saID; StructuredPushSupplier_i* supplier = new StructuredPushSupplier_i(); sadmin =
channel->new_for_suppliers(CosNotifyChannelAdmin::AND_OP, saID); |
The following code segment illustrates the transfer of structured events to the channel. The structure of these events is very simple. The domain name is set to "Ready" and type name is set to "Long". The payload of the event is stored in the remainder_of_body field, and contains the value of a counter whose type is CORBA::Long. Here, the supplier pushes numEvents to the channel without carrying out any other operation between successive pushes.
// -*- Mode: C++; -*- CosNotification::StructuredEvent se; se.header.fixed_header.event_type.domain_name =
CORBA::string_dup("READY"); for (CORBA::Long i = 0; i < numEvents; i++) { |
The complete listing of the push supplier application is presented below, assuming that omniORB is being used.
// -*- Mode: C++; -*- #include
<iostream.h> class StructuredPushSupplier_i : ////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) CORBA::ORB_var orb =
CORBA::ORB_init(argc, argv, "omniORB2"); // Register the supplier object with the ORB supplier->_obj_is_ready(boa); // Obtain reference to the CORBA Naming Service and resolve 'EventChannel' name_service =
orb->resolve_initial_references("NameService"); // Create new SupplierAdmin and proxy objects, and connect the supplier sadmin = channel->new_for_suppliers( // Inform the BOA that we are ready to receive callbacks from the event channel, if any boa->impl_is_ready(0, 1); // Populate the common fields of each structured event that will be supplied
se.header.fixed_header.event_type.domain_name = for (CORBA::Long i = 0; i < numEvents;
i++) { // No more events to be supplied. Disconnect the supplier and destroy the admin object
prx_cons->disconnect_structured_push_consumer(); return 0; |
The development of a pull event supplier is similar to the development of a push event supplier. The only major difference is the implementation of the CosNotifyComm::StructuredPullSupplier interface. The code segment below shows a simple implementation of this interface.
Since the event channel may invoke the pull_structured_event and try_pull_structured_event methods of the pull supplier at any time between the connection and disconnection times, the implementation of the pull supplier application should be prepared to handle such asynchronous callback invocations. The complete listing of a simple pull supplier application is presented below.
// -*- Mode: C++; -*- #include
<iostream.h> CORBA::Long numEvents = 100; // Remaining number of events to be pulled class StructuredPullSupplier_i : ////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) CORBA::ORB_var orb =
CORBA::ORB_init(argc, argv, "omniORB2"); // Register the supplier object with the ORB supplier->_obj_is_ready(boa); // Obtain reference to the CORBA Naming Service and resolve 'EventChannel' name_service =
orb->resolve_initial_references("NameService"); // Create a new SupplierAdmin object, create a proxy object, and connect the supplier sadmin = channel->new_for_suppliers( // Inform the BOA that we are ready to receive callbacks from the event channel, if any boa->impl_is_ready(0, 1); // Wait until there are no more events to be pulled -- sleep 5 seconds between checks while ( numEvents != 0 ) // No more events to be supplied. Disconnect the supplier and destroy the admin object
prx_cons->disconnect_structured_pull_consumer(); return 0; |
Back to Documentation Home Page
For comments, feedback, etc, please see the 'Keep in touch' page. |