Sophie

Sophie

distrib > Fedora > 17 > x86_64 > by-pkgid > 675c8c8167236dfcf8d66da674f931e8 > files > 289

erlang-doc-R15B-03.3.fc17.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns:fn="http://www.w3.org/2005/02/xpath-functions">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../../../doc/otp_doc.css" type="text/css">
<title>Erlang -- Event Service</title>
</head>
<body bgcolor="white" text="#000000" link="#0000ff" vlink="#ff00ff" alink="#ff0000"><div id="container">
<script id="js" type="text/javascript" language="JavaScript" src="../../../../doc/js/flipmenu/flipmenu.js"></script><script id="js2" type="text/javascript" src="../../../../doc/js/erlresolvelinks.js"></script><script language="JavaScript" type="text/javascript">
            <!--
              function getWinHeight() {
                var myHeight = 0;
                if( typeof( window.innerHeight ) == 'number' ) {
                  //Non-IE
                  myHeight = window.innerHeight;
                } else if( document.documentElement && ( document.documentElement.clientWidth ||
                                                         document.documentElement.clientHeight ) ) {
                  //IE 6+ in 'standards compliant mode'
                  myHeight = document.documentElement.clientHeight;
                } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
                  //IE 4 compatible
                  myHeight = document.body.clientHeight;
                }
                return myHeight;
              }

              function setscrollpos() {
                var objf=document.getElementById('loadscrollpos');
                 document.getElementById("leftnav").scrollTop = objf.offsetTop - getWinHeight()/2;
              }

              function addEvent(obj, evType, fn){
                if (obj.addEventListener){
                obj.addEventListener(evType, fn, true);
                return true;
              } else if (obj.attachEvent){
                var r = obj.attachEvent("on"+evType, fn);
                return r;
              } else {
                return false;
              }
             }

             addEvent(window, 'load', setscrollpos);

             //--></script><div id="leftnav"><div class="innertube">
<img alt="Erlang logo" src="../../../../doc/erlang-logo.png"><br><small><a href="users_guide.html">User's Guide</a><br><a href="index.html">Reference Manual</a><br><a href="release_notes.html">Release Notes</a><br><a href="../pdf/cosEvent-2.1.12.pdf">PDF</a><br><a href="../../../../doc/index.html">Top</a></small><p><strong>cosEvent</strong><br><strong>User's Guide</strong><br><small>Version 2.1.12</small></p>
<br><a href="javascript:openAllFlips()">Expand All</a><br><a href="javascript:closeAllFlips()">Contract All</a><p><small><strong>Chapters</strong></small></p>
<ul class="flipMenu" imagepath="../../../../doc/js/flipmenu">
<li id="no" title="The cosEvent Application" expanded="false">The cosEvent Application<ul>
<li><a href="ch_contents.html">
              Top of chapter
            </a></li>
<li title="Content Overview"><a href="ch_contents.html#id60836">Content Overview</a></li>
<li title="Brief Description of the User's Guide"><a href="ch_contents.html#id60123">Brief Description of the User's Guide</a></li>
</ul>
</li>
<li id="no" title="Introduction to cosEvent" expanded="false">Introduction to cosEvent<ul>
<li><a href="ch_introduction.html">
              Top of chapter
            </a></li>
<li title="Overview"><a href="ch_introduction.html#id61483">Overview</a></li>
</ul>
</li>
<li id="loadscrollpos" title="Event Service" expanded="true">Event Service<ul>
<li><a href="ch_es_intro.html">
              Top of chapter
            </a></li>
<li title="Overview of the CosEvent Service"><a href="ch_es_intro.html#id57986">Overview of the CosEvent Service</a></li>
<li title="Event Service Components"><a href="ch_es_intro.html#id61804">Event Service Components</a></li>
<li title="Event Service Communication Models"><a href="ch_es_intro.html#id61523">Event Service Communication Models</a></li>
<li title="A Tutorial on How to Create a Simple Service"><a href="ch_es_intro.html#id61792">A Tutorial on How to Create a Simple Service</a></li>
<li title="How to Run Everything"><a href="ch_es_intro.html#id60109">How to Run Everything</a></li>
</ul>
</li>
</ul>
</div></div>
<div id="content">
<div class="innertube">
<h1>3 Event Service</h1>
  

  <h3><a name="id57986">3.1 
        Overview of the CosEvent Service</a></h3>
    
    <p>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.
      </p>
    <p>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.</p>
  

  <h3><a name="id61804">3.2 
        Event Service Components</a></h3>
    
    <p>There are five components in the OMG CosEvent service architecture. These
      are described below:</p>
    <a name="e_s_components"></a>
    <img alt="IMAGE MISSING" src="e_s_components.gif"><br>
      <em>Figure
        3.1:
         
        
Figure 1: Event service Components</em>
    
    <ul>
      <li>
<strong>Suppliers and consumers:</strong> Consumers are the ultimate targets of
       events generated by suppliers. Consumers and suppliers can both play active
       and 
       passive roles. There could be two types of consumers and suppliers: push
       or pull. A PushSupplier object can actively push an event to a passive
       PushConsumer object. Likewise, a PullSupplier object can passively 
       wait for a PullConsumer object to actively pull an event from it.</li>
      <li>
<strong>EventChannel:</strong> The central abstraction in the CosEvent service is the 
       EventChannel which plays the role of a mediator between consumers and 
       suppliers. Consumers and suppliers register their interest with the 
       EventChannel. It can provide many-to-many communication. The channel 
       consumes events from one or more suppliers, and supplies events to one 
       or more consumers. An EventChannel can support consumers and suppliers
       using different communication models.</li>
      <li>
<strong>ProxySuppliers and ProxyConsumers:</strong> ProxySuppliers act as middlemen
       between consumers and the EventChannel. A ProxySupplier is similar to
       a normal supplier, but includes an additional method for connecting a 
       consumer to the ProxySupplier. Likewise, ProxyConsumers act as 
       middlemen between suppliers and the EventChannel. A ProxyConsumer is
       similar to a normal consumer, but includes an additional method for
       connecting a supplier to the ProxyConsumer.</li>
      <li>
<strong>Supplier and consumer administrations:</strong> Consumer administration acts as
       a factory for creating ProxySuppliers.  Supplier administration acts as
       a factory for creating ProxyConsumers.</li>
    </ul>
  

  <h3><a name="id61523">3.3 
        Event Service Communication Models</a></h3>
    
    <p>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).</p>
    <a name="e_s_models"></a>
    <img alt="IMAGE MISSING" src="e_s_models.gif"><br>
      <em>Figure
        3.2:
         
        
Figure 2: Event service Communication Models</em>
    
    <ul>
      <li>
<strong>The Canonical Push Model:</strong> The Canonical push model shown in figure 2(A) allows
       the suppliers of events to initiate the transfer of event data to consumers.
       In this model, suppliers are active initiators and consumers are the passive
       targets of the requests. EventChannels play the role of <span class="code">Notifier</span>.
       Thus, active suppliers use EventChannels to push data to passive consumers that 
       have registered with the EventChannels.</li>
      <li>
<strong>The Canonical Pull Model:</strong>The Canonical pull model shown
       in figure 2(B) 
       allows consumers to request events from suppliers. In this model,
       Consumers are 
       active initiators and suppliers are the passive targets of the pull
       requests. 
       EventChannel plays the role of <span class="code">Procurer</span> since it procures
       events
       on behalf of consumers. Thus, active consumers can explicitly pull
       data 
       from passive suppliers via the EventChannels.</li>
      <li>
<strong>The Hybrid Push/Pull Model:</strong> The push/pull model shown in figure 2(C) is a 
       hybrid that allows consumers to request events queued at an EventChannel
       by suppliers. In this model, both suppliers and consumers are active 
       initiators of the requests. EventChannels play the role of <span class="code">Queue</span>.
       Thus, active consumers can explicitly pull data deposited by active
       suppliers via the EventChannels.</li>
      <li>
<strong>The Hybrid Pull/Push Model:</strong> The pull/push model shown in figure 2(D) is another
       hybrid that allows the channel to pull events from suppliers and push them 
       to consumers. In this model, suppliers are passive targets of pull requests 
       and consumers are passive targets of pushes. EventChannels play the role of 
      <span class="code">Intelligent Agent</span>. Thus, active EventChannels can pull data from 
       passive suppliers and push that data to passive consumers.</li>
    </ul>
  

  <h3><a name="id61792">3.4 
        A Tutorial on How to Create a Simple Service</a></h3>
    
    <p>To be able to use the cosEvent application supplier and consumer objects
      must be implemented, which must inherit from the appropriate interface
      defined in the <strong>CosEventComm.idl</strong> specification.</p>
    <p>We start by creating an interface which inherits from the correct interface, 
      e.g., CosEventComm::PushConsumer. Hence, we must also implement all
      operations defined in the PushConsumer interface. The IDL-file could look like: 
      </p>
    <div class="example"><pre>
#ifndef _MYCLIENT_IDL
#define _MYCLIENT_IDL
#include &lt;CosEventComm.idl&gt;
 
module myClientImpl {
 
  interface ownInterface:CosEventComm::PushConsumer {
 
    void ownFunctions(in any NeededArguments)
       raises(OwnExceptions);
 
  };
};
 
#endif
    </pre></div>
    <p>Run the IDL compiler on this file by calling the <span class="code">ic:gen/1</span> function. 
      This will produce the API named <span class="code">myClientImpl_ownInterface.erl</span>.
      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 <span class="code">myClientImpl_ownInterface_impl.erl</span>.</p>
  

  <h3><a name="id60109">3.5 
        How to Run Everything</a></h3>
    
    <p>Below is a short transcript on how to run cosEvent. </p>
    <div class="example"><pre>
 
%% Start Mnesia and Orber
mnesia:delete_schema([node()]),
mnesia:create_schema([node()]),
orber:install([node()]),
mnesia:start(),
orber:start(),
 
%% Install cosEvent in the IFR.
cosEventApp:install(), 

%% Register the application specific Client implementations
%% in the IFR.
'oe_myClientImpl':'oe_register'(), 
 
%% Start the cosEvent application.
cosEventApp:start(), 
 
%% Start a channel using the default configuration
Ch = cosEventApp:start_channel(),
%% ... or use configuration parameters.
Ch = cosEventApp:start_channel([{pull_interval, 10}, {maxEvents, 50}]),
 
%% Retrieve a SupplierAdmin and a ConsumerAdmin.
AdminSupplier = 'CosEventChannelAdmin_EventChannel':for_suppliers(Ch),
AdminConsumer = 'CosEventChannelAdmin_EventChannel':for_consumers(Ch),

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

%% Create a Push Consumer Proxy, which the Client Push Supplier will push 
%% events to.
ProxyPushConsumer = 
  'CosEventChannelAdmin_SupplierAdmin':obtain_push_consumer(AdminSupplier),

%% Create a Push Supplier Proxy, which will push events to the registered
%% Push Consumer.
ProxyPushSupplier =
  'CosEventChannelAdmin_ConsumerAdmin':obtain_push_supplier(AdminConsumer),


%% Create application Clients. We can, for example, start the Clients 
%% our selves or look them up in the naming service. This is application
%% specific.
Consumer = myClientImpl_ownInterface:oe_create(),
Supplier = ...

%% Connect each Client to the corresponding Proxy.
'CosEventChannelAdmin_ProxyPushConsumer':
   connect_push_supplier(ProxyPushConsumer, Supplier),
'CosEventChannelAdmin_ProxyPushSupplier':
   connect_push_consumer(ProxyPushSupplier, Consumer),
    </pre></div>
    <p>The example above, exemplifies a event system, i.e., the <strong>Canonical Push Model</strong>, where the Supplier client in some way generates event
      and pushes them to the proxy. The push supplier proxies will eventually
      push the events to each Consumer client.</p>
  
</div>
<div class="footer">
<hr>
<p>Copyright © 1999-2012 Ericsson AB. All Rights Reserved.</p>
</div>
</div>
</div></body>
</html>