Erlang logo
User's Guide
Reference Manual
Release Notes
PDF
Top

cosNotification
User's Guide
Version 1.1.14


Expand All
Contract All

Chapters

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:

#ifndef _MYCLIENT_IDL
#define _MYCLIENT_IDL
#include <CosNotification.idl>
#include <CosNotifyComm.idl>
 
module myClientImpl {
 
  interface ownInterface:CosNotifyComm::SequencePushConsumer {
 
    void ownFunctions(in any NeededArguments)
       raises(Systemexceptions,OwnExceptions);
 
  };
};
 
#endif
      

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
mnesia:delete_schema([node()]),
mnesia:create_schema([node()]),
orber:install([node()]),
mnesia:start(),
orber:start(),
 
%% If cosEvent not installed before it is necessary to do it now.
cosEventApp:install(), 

%% Install cosNotification in the IFR.
cosNotificationApp:install(30), 
 
%% Register the application specific Client implementations
%% in the IFR.
'oe_myClientImpl':'oe_register'(), 
 
%% Start the cosNotification application.
cosNotificationApp:start(), 
 
%% 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}= 
         'CosNotifyChannelAdmin_EventChannel':new_for_consumers(Ch,'OR_OP'),

%% 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.
{ProxyPushSupplier,I4D}='CosNotifyChannelAdmin_ConsumerAdmin':
      obtain_notification_push_supplier(AdminConsumer, 'ANY_EVENT'),
{StructuredProxyPushSupplier,ID5}='CosNotifyChannelAdmin_ConsumerAdmin':
      obtain_notification_push_supplier(AdminConsumer, 'STRUCTURED_EVENT'),
{SequenceProxyPushSupplier,ID6}='CosNotifyChannelAdmin_ConsumerAdmin':
      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.
'CosNotifyChannelAdmin_StructuredProxyPushConsumer':
  connect_structured_push_supplier(StructuredProxyPushConsumer, SupplierClient),
'CosNotifyChannelAdmin_ProxyPushSupplier':
  connect_any_push_consumer(ProxyPushSupplier, ConsumerClient1),
'CosNotifyChannelAdmin_StructuredProxyPushSupplier':
  connect_structured_push_consumer(StructuredProxyPushSupplier, ConsumerClient2),
'CosNotifyChannelAdmin_SequenceProxyPushSupplier':
  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.