Erlang logo
User's Guide
Reference Manual
Release Notes

User's Guide
Version 1.2

Expand All
Contract All


7 cosNotification Examples

7.1  A Tutorial on How to Create a Simple Service

Interface Design

To use the cosNotification application clients must be implemented. There are twelve types of clients:

  • Structured Push Consumer
  • Sequence Push Consumer
  • Any Push Consumer
  • Structured Pull Consumer
  • Sequence Pull Consumer
  • Any Pull Consumer
  • Structured Push Supplier
  • Sequence Push Supplier
  • Any Push Supplier
  • Structured Pull Supplier
  • Sequence Pull Supplier
  • Any Pull Supplier

The interfaces for these participants are defined in CosNotification.idl and CosNotifyComm.idl.

Generating a Client Interface

We start by creating an interface which inherits from the correct interface, e.g., CosNotifyComm::SequencePushConsumer. Hence, we must also implement all operations defined in the SequencePushConsumer interface. The IDL-file could look like:

#include <CosNotification.idl>
#include <CosNotifyComm.idl>
module myClientImpl {
  interface ownInterface:CosNotifyComm::SequencePushConsumer {
    void ownFunctions(in any NeededArguments)

Run the IDL compiler on this file by calling the ic:gen/1 function. This will produce the API named myClientImpl_ownInterface.erl. After generating the API stubs and the server skeletons it is time to implement the servers and if no special options are sent to the IDl compiler the file name is myClientImpl_ownInterface_impl.erl.

The callback module must contain the necessary functions inherited from CosNotification.idl and CosNotifyComm.idl.

How to Run Everything

Below is a short transcript on how to run cosNotification.

%% Start Mnesia and Orber
%% If cosEvent not installed before it is necessary to do it now.

%% Install cosNotification in the IFR.
%% Register the application specific Client implementations
%% in the IFR.
%% Start the cosNotification application.
%% Start a factory using the default configuration
ChFac = cosNotificationApp:start_factory(),
%% ... or use configuration parameters.
ChFac = cosNotificationApp:start_factory([]),
%% Create a new event channel. Note, if no QoS- anr/or Admin-properties
%% are supplied (i.e. empty list) the default settings are used.
{Ch, ChID} = 'CosNotifyChannelAdmin_EventChannelFactory':
          create_channel(ChFac, DefaultQoS, DefaultAdmin),
%% Retrieve a SupplierAdmin and a Consumer Admin.
{AdminSupplier, ASID}=
         'CosNotifyChannelAdmin_EventChannel':new_for_suppliers(Ch, 'OR_OP'),
{AdminConsumer, ACID}= 

%% Use the corresponding Admin object to get access to wanted Proxies

%% Create a Push Consumer Proxie, i.e., the Client Push Supplier will
%% push events to this Proxy.
{StructuredProxyPushConsumer,ID11}= 'CosNotifyChannelAdmin_SupplierAdmin':
     obtain_notification_push_consumer(AdminSupplier, 'STRUCTURED_EVENT')),

%% Create Push Suppliers Proxies, i.e., the Proxy will push events to the
%% registered Push Consumers.
      obtain_notification_push_supplier(AdminConsumer, 'ANY_EVENT'),
      obtain_notification_push_supplier(AdminConsumer, 'STRUCTURED_EVENT'),
      obtain_notification_push_supplier(AdminConsumer, 'SEQUENCE_EVENT'),

%% Create application Clients. We can, for example, start the Clients 
%% our selves or look them up in the naming service. This is application
%% specific.
SupplierClient  = ...
ConsumerClient1 = ...
ConsumerClient2 = ...
ConsumerClient3 = ...

%% Connect each Client to corresponding Proxy.
  connect_structured_push_supplier(StructuredProxyPushConsumer, SupplierClient),
  connect_any_push_consumer(ProxyPushSupplier, ConsumerClient1),
  connect_structured_push_consumer(StructuredProxyPushSupplier, ConsumerClient2),
  connect_sequence_push_consumer(SequenceProxyPushSupplier, ConsumerClient3),

The example above, exemplifies a notification system where the SupplierClient in some way generates event and pushes them to the proxy. The push supplier proxies will eventually push the events to each ConsumerClient.