![]() |
![]() |
![]() |
![]() |
![]() |
Table 4‑1 outlines the development process for creating Notification Service applications.
Table 4‑1 Development Process The design of events is basic to any notification service. The design impacts not only the volume of information that is delivered to matching subscriptions, but the efficiency and performance of the Notification Service as well. Therefore, careful planning should be done to ensure that your Notification Service will be able to handle your needs now and allow for future growth. For a discussion of event design, see “Designing Events” on page -6.This development step is illustrated in Listing 4‑1. Listing 4‑1 is code from the Reporter.cpp file in the Introductory sample application that uses the CosNotification Service API.To get the event channel factory object reference, the resolve_initial_references method is invoked on the Bootstrap object using the "NotificationService" environmental object. The object reference is used to get the channel factory, which is, in turn, is used to get the event channel. Listing 4‑1 shows code examples in C++.Listing 4‑1 Getting the Event Channel (Reporter.cpp)// Get the CosNotification channel factory object reference.
CORBA::Object_var channel_factory_oref =
bootstrap.resolve_initial_references(
"NotificationService" );
CosNotifyChannelAdmin::EventChannelFactory_var
channel_factory =
CosNotifyChannelAdmin::EventChannelFactory::_narrow(
channel_factory_oref.in() );
// use the channel factory to get the default channel
CosNotifyChannelAdmin::EventChannel_var channel =
channel_factory->get_event_channel(
Tobj_Notification::DEFAULT_CHANNEL );Listing 4‑2 shows how this is implemented in C++.Listing 4‑2 Creating and Posting the Event (Reporter.cpp)
• Implement a CosNotifyComm OMG IDL interface that supports the push_structured_event operation.
• Create a callback object that implements the CosNotifyComm::StructuredPushConsumer interface.In order for the callback servant object to receive events, it must implement the CosNotifyComm::StructuredPushConsumer interface that supports the push_structured_event operation. When an event occurs that has a matching subscription, the Notification Service invokes this operation on the servant callback object in the subscriber application to deliver the event to the subscriber application.The CosNotifyComm::StructuredPushConsumer interface also defines the operations offer_change and disconnect_structured_push_consumer. The Notification Service never invokes these operations, so you should implement stubbed out versions that throw CORBA::NO_IMPLEMENT.Listing 4‑3 and Listing 4‑4 show how this interface is implemented in C++.Listing 4‑3 Sample CosNotifyComm::StructuredPushConsumer Interface Implementation (NewsConsumer_i.h)Listing 4‑4 Sample CosNotifyComm::StructuredPushConsumer Interface Implementation (NewsConsumer_i.cpp)Before an application can create a subscription, it must get the event channel and the ConsumerAdmin and Filter Factory objects. Listing 4‑5 shows how this is implemented in C++.To get the event channel factory object reference, the resolve_initial_references method is invoked on the Bootstrap object using the "NotificationService" environmental object. The object reference is used to get the channel factory, which is, in turn, used to get the event channel. Finally, the event channel is used to get the ConsumerAdmin object and the FilterFactory object.For a complete description of the BEAWrapper Callbacks object and its methods, see the Joint Client/Servers chapter in the CORBA Programming Reference.
Note: Using the BEAWrapper Callback object to create a callback object is discussed below. For a discussion of how to implement a callback object using the POA, see Using CORBA Server-to-Server Communication.Listing 4‑6 shows how to use the BEAWrapper Callbacks object to create a callback object in C++. In the code examples, the NewsConsumber_i servant is created and the start_transient method is used to create a transient object reference.// Create a callback wrapper object since this client needs to
// support callbacks
BEAWrapper::Callbacks wrapper(orb.in());
NewsConsumer_i* news_consumer_impl = new NewsConsumer_i;
// Create a transient object reference to this servant.
CORBA::Object_var news_consumer_oref =
wrapper.start_transient(
news_consumer_impl,
CosNotifyComm::_tc_StructuredPushConsumer->id()
);
CosNotifyComm::StructuredPushConsumer_var
news_consumer =
CosNotifyComm::StructuredPushConsumer::_narrow(
news_consumer_oref.in() );
3. Listing 4‑7 from the Introductory sample application, shows how to create a transient subscription in C++.Listing 4‑7 Creating a Transient Subscription// Create a new subscription (at this point, it is not complete).
CosNotifyChannelAdmin::ProxyID subscription_id;
CosNotifyChannelAdmin::ProxySupplier_var generic_subscription =
consumer_admin->obtain_notification_push_supplier(
CosNotifyChannelAdmin::STRUCTURED_EVENT,
subscription_id );
CosNotifyChannelAdmin::StructuredProxyPushSupplier_var
subscription =
CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow(
generic_subscription );
s_subscription = subscription.in();
// Set the quality of service. This sets the subscription name
// and subscription type (=TRANSIENT).
CosNotification::QoSProperties qos;
qos.length(2);
qos[0].name =
CORBA::string_dup(Tobj_Notification::SUBSCRIPTION_NAME);
qos[0].value <<= subscription_name;
qos[1].name =
CORBA::string_dup(Tobj_Notification::SUBSCRIPTION_TYPE);
qos[1].value <<=
Tobj_Notification::TRANSIENT_SUBSCRIPTION;
subscription->set_qos(qos);
// Create a filter (used to specify domain, type and data filter).
CosNotifyFilter::Filter_var filter =
filter_factory->create_filter(
Tobj_Notification::CONSTRAINT_GRAMMAR );
s_filter = filter.in();
// Set the filtering parameters.
// (domain = "News", type = “Sports”, and no data filter)
CosNotifyFilter::ConstraintExpSeq constraints;
constraints.length(1);
constraints[0].event_types.length(1);
constraints[0].event_types[0].domain_name =
CORBA::string_dup("News");
constraints[0].event_types[0].type_name =
CORBA::string_dup(“Sports”);
constraints[0].constraint_expr =
CORBA::string_dup(""); // No data filter.
CosNotifyFilter::ConstraintInfoSeq_var
add_constraints_results = // ignore this returned value
filter->add_constraints(constraints);
// Add the filter to the subscription.
CosNotifyFilter::FilterID filter_id =
subscription->add_filter(filter.in());
// Now that we have set the subscription name, type and filtering
// parameters, complete the subscription by passing in the
// reference of the callback object to deliver the events to.
subscription->connect_structured_push_consumer(
news_consumer.in() );To generate the client stub and skeleton files, you must execute the idl command for each of the Notification IDL files that your application uses. Table 4‑2 shows the idl commands used for each type of subscriber.
Table 4‑2 idl Command Requirements The following is an example of an idl command:Table 4‑3 lists the IDL files required by each type of Notification Service application.
The compiling and linking procedure differs depending on the type of Notification Service application you are building. Table 4‑4 provides an overview of the commands and files used to compile each type of application.
Table 4‑4 Application Build Requirements Use the buildobjclient command to compile the application files and the IDL stubs. Use the buildobjclient command with the -P option to compile the application files and the IDL stubs. Use the buildobjserver command to compile the application files and the IDL client stubs. Use the buildobjclient command with the -P option to compile the application files, the IDL stubs, and the IDL skeletons. Use the buildobjserver command to compile the application files, the IDL stubs, and the IDL skeletons.Listing 4‑8 shows the commands used for a C++ Reporter application (Reporter.cpp) on a Microsoft Windows system. To form a C++ executable, the idl command is run on the required IDL file and the buildobjclient command compiles the C++ client application file and the IDL stubs.Listing 4‑8 C++ Reporter Application Build and Run CommandsListing 4‑9 and Listing 4‑10 show the commands used for a C++ Subscriber application (Subscriber.cpp) on Microsoft Windows and UNIX, respectively. To form a C++ executable, the buildobjclient command, with the -P option, compiles the joint client/server application files (Subscriber.cpp and NewsConsumer_i.cpp), the IDL stubs, the IDL skeleton (for CosNotifyComm_s.cpp).