[Erlang Systems]

3 Event Service

3.1 Overview of the CosEvent Service

The Event service allows programmers to subscribe to information channels. Suppliers can generate events without knowing the consumer identities and the consumer can receive events without knowing the supplier identity. Both push and pull event delivery are supported. The Event service will queue information and processes.

The CORBA Event service provides a flexible model for asynchronous, decoupled communication between objects. This chapter outlines communication models and the roles and relationships of key components in the CosEvent service. It shows a simple example on use of this service.

3.2 Event Service Components

There are five components in the OMG CosEvent service architecture. These are described below:

e_s_components
Figure 1: Event service Components

3.3 Event Service Communication Models

There are four general models of component collaboration in the OMG CosEvent service architecture. The following describes these models: (Please note that proxies are not shown in the diagrams for simplicity).

e_s_models
Figure 2: Event service Communication Models

3.4 Creating an EventChannel

An EventChannel can be created by using the EventChannelFactory interface, which is implemented by OrberEventChannel_EventChannelFactory.

To start the factory server one needs to make a call to corba:create/2 which could look like this:

      -module(event_channel_factory).

      -include_lib("orber/include/corba.hrl").
      -include_lib("orber/COSS/CosNaming/CosNaming.hrl").
      -include_lib("orber/COSS/CosNaming/lname.hrl").
      
      -export([start/0]).

      start() ->
        ECFok = 'OrberEventChannel_EventChannelFactory':oe_create(),
        NS = corba:resolve_initial_references("Nameservice"),
        NC = lname_component:set_id(lname_component:create(),
                                   "EventChannelFactory"),
        N = lname:insert_component(lname:create(), 1, NC),
        'CosNaming_NamingContext':bind(NS, N, ECFok).
    

Now an EventChannelFactory is created and registered in the CosNaming service and could be found by consumers and suppliers.

3.5 Using the Event Service

This section shows an example of usage of the Event service in order to decouple communication between a measurements collector and a safety controller.

3.5.1 Using the Consumer interface for safety controller

The safety controller plays the role of a PushConsumer. It is interested in the data provided by the measurements collector, which plays the role of a PushSupplier. Safety controller is responsible for the action required in case some measurements exceed the safety limits.

First, the safety controller creates a PushConsumer itself, and then obtains an EventSupplier channel object reference using the EventChannelFactory, as follows:

// The safety controller creates a PushConsumer object
MyPushConsumer = my_push_consumer_srv:create(), 

// EventChannel created through EventChannelFactory
// EventChannelFactory obtained from the CosNaming service (not shown)
// EventChannel registered in the CosNaming service (not shown)
EventChannel = 'OrberEventChannel_EventChannelFactory':
                create_event_channel(ECFactory),
      

This code assumes that the MyPushConsumer supports the PushConsumer interface and implements the appropriate safety controller logic.

Note: If no support exists for the push consumer the process will crash.

Next, the safety controller connects itself to the EventChannel:

// first step: obtain ConsumerAdmin object reference
ConsumerAdmin = 'CosEventChannelAdmin_EventChannel'
                 :for_consumers(EventChannel),
// obtain ProxyPushSupplier from the ConsumerAdmin object
PPhS = 'CosEventChannelAdmin_ConsumerAdmin'
        :obtain_push_supplier(ConsumerAdmin),
        
// second step: connect our PushConsumer to the ProxyPushSupplier
'CosEventChannelAdmin_ProxyPushSupplier'
         :connect_push_consumer(PPhS, MyPushConsumer)
      

When an event arrives in the EventChannel, it will invoke the push operation on the registered PushConsumer object reference.

3.5.2 Using the supplier interface for measurements collector

Measurements collector sends data containing information about current measurement of the system to the EventChannel in order to keep safety controller informed of any changes.

As with the safety controller, the measurements collector needs an object reference to an EventChannel and to a PushSupplier to connect to the channel. This is accomplished as follows:

// measurements collector creates a PushSupplier
MyPushSupplier = my_push_supplier_srv:create(),
        
// EventChannel obtained from the Naming service (not shown)
EventChannel = //...
        
// obtain SupplierAdmiin object reference
SupplierAdmin = 
  'CosEventChannelAdmin_EventChannel':for_suppliers(EventChannel),
        
// obtain ProxyPushConsumer from SupplierAdmin object
PPhC = 
  'CosEventChannelAdmin_SupplierAdmin':obtain_push_consumer(SupplierAdmin),
        
// connect our PushSupplier to the ProxyPushConsumer
'CosEventChannelAdmin_ProxyPushConsumer':connect_push_supplier(PPhC, 
                                                               MyPushSupplier),
      

Once the consumer and the supplier registration code get executed, both the safety controller and the measurements collector are connected to the EventChannel. At this point, safety controller will automatically receive measurements data that are pushed by the measurements collector.

3.5.3 Exchanging and processing event data

The events exchanged between supplier and consumer must always be specified in OMG IDL so that they can be stored into an any type variable. Consider the following data example sent by the measurements controller:

   record(measurements, {temperature, pressure, water_level}).
      

In order to push an event, the measurements collector must create and initialize this record, put it into CORBA::any, and call push on the EventChannel PushConsumer interface:

// create some data
EventRecord = #measurements{temperature = 150, pressure = 100, 
                                          water_level = 200},
EventData = { measurements:tc(),EventRecord},

// push the event to consumer
'CosEventChannelAdmin_ProxyPushConsumer':push(PPhC, EventData),
      

Once the EventChannel receives an event from the measurements collector, it pushes the event data to the consumer by invoking the push operation on registered PushConsumer object reference.

The implementation of the safety controller consumer push could look like this:

push(Data) ->
{
  if
    Data#measurements.temperature > 300 ->
      // some logic to set alarm
      ;
    Data#measurements.water_level < 50 ->
      // some logic to get more water
      ;

    ......etc
  end.
}
      

Copyright © 1991-2001 Ericsson Utvecklings AB