Free High Performance CORBA Notification Service from AT&T Laboratories |
omniORB Home AT&T Research |
Back to Documentation Home Page
In the original CORBA Event Service model, every consumer application connected to an event channel receives all events that are announced to the channel. While this may be desirable in some application domains, it is inefficient when consumers are interested in only a subset of the announced events. The CORBA Notification Service offers a solution to this problem and enables clients to subscribe to the precise set of events they are interested in receiving by using filter objects.
Each filter object encapsulates a set of one or more constraints, each of which is specified in a constraint grammar. Each constraint consists of two components:
Filter objects implement the CosNotifyFilter::Filter interface. This interface includes two operations that are used to evaluate the constraints associated with a filter against a given event: match_structured and match. The former is used for events of type CosNotification::StructuredEvent and the latter for events of type CORBA::Any. The returned value of these operations is TRUE when at least one of the constraints associated with the filter object evaluates to TRUE, and FALSE, otherwise.
Filter objects can be associated with both administrative and proxy objects using the add_filter operation of the CosNotifyFilter::FilterAdmin interface, which is inherited by these objects. In addition these is no limit on the number of filters that can be associated with any of them. When multiple filters are associated with some administrative or proxy object, an event is considered to satisfy these filters when the corresponding match operation of at least one of these filters returns TRUE. Filters associated with administrative objects are inherited by all proxy objects created by them. Consequently, each proxy object may have two sets of filters, those added to it by invoking its add_filter operation and those inherited by its administrative object. These two sets of filters can be combined using AND or OR semantics.
Filter objects are created by filter factories. Each omniNotify event channel has a default filter factory that can be used for creating filters using the extended Trader Constraint Language defined in the OMG Notification Service specification. The following code segment shows how to create a filter using the default filter factory.
// -*- Mode: C++; -*- CosNotifyFilter::Filter_var
filterp; // We assume that we have initialized channel to point to an event channel instance fltfact = channel->default_filter_factory(); |
Once a filter is created, a sequence of constraints can be added to it. Each constraint in this sequence has the following structure:
struct ConstraintExp {
CosNotification::EventTypeSeq event_types;
string constraint_expr;
};
The following code segment shows how to add a constraint that evaluates to true for events having domain name "Financial", type name "StockQuote", and an attribute "Price" whose value is greater than 25.0.
// -*- Mode: C++; -*- CosNotifyFilter::Filter_var
filterp; cexpr.length(1); // We assume that we have initialized filterp to point to a filter object cinfo = filterp->add_constraints(cexpr); |
Once we are done with the above, we can attach the filter object to a proxy object to enable filtering of events. This is done by invoking the add_filter method on the proxy object. However, the above filter object gets evaluated only when suppliers supply events that match its constraint. The code segment below shows how to construct such events.
// -*- Mode: C++; -*- CosNotification::StructuredEvent se; se.header.fixed_header.event_type.domain_name = |
The complete listing of a push consumer that uses filtering is presented below.
// -*- Mode: C++; -*- #include
<iostream.h> class StructuredPushConsumer_i : ////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) CORBA::ORB_var orb =
CORBA::ORB_init(argc, argv, "omniORB2"); // Register the consumer object with the undelying ORB consumer->_obj_is_ready(boa); // Obtain reference to the CORBA Naming Service and resolve 'EventChannel' name_service =
orb->resolve_initial_references("NameService"); // Create new ConsumerAdmin and proxy objects, and connect the consumer cadmin = channel->new_for_consumers( // Create the filter object, add a constraint to it, and attach it to the proxy fltfact =
channel->default_filter_factory(); cinfo =
filterp->add_constraints(cexpr); flID = prx_supl->add_filter(filterp); // Connect the consumer to the proxy and inform the BOA that we can receive events/callbacks prx_supl->connect_structured_push_consumer(consumer); boa->impl_is_ready(0, 1); // Wait until at least numEvents are pushed -- sleep 5 seconds between checks while ( consumer->get_num_events()
< numEvents ) // No more events to be consumed. Disconnect the consumer and destroy the admin object
prx_supl->disconnect_structured_push_supplier(); return 0; |
Back to Documentation Home Page
For comments, feedback, etc, please see the 'Keep in touch' page. |