Sophie

Sophie

distrib > Fedora > 17 > i386 > media > updates > by-pkgid > 675c8c8167236dfcf8d66da674f931e8 > files > 384

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 -- cosNotification Examples</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/cosNotification-1.1.18.pdf">PDF</a><br><a href="../../../../doc/index.html">Top</a></small><p><strong>cosNotification</strong><br><strong>User's Guide</strong><br><small>Version 1.1.18</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 cosNotification Application" expanded="false">The cosNotification Application<ul>
<li><a href="ch-contents.html">
              Top of chapter
            </a></li>
<li title="Content Overview"><a href="ch-contents.html#id63553">Content Overview</a></li>
<li title="Brief Description of the User's Guide"><a href="ch-contents.html#id57496">Brief Description of the User's Guide</a></li>
</ul>
</li>
<li id="no" title="Introduction to cosNotification" expanded="false">Introduction to cosNotification<ul>
<li><a href="ch_introduction.html">
              Top of chapter
            </a></li>
<li title="Overview"><a href="ch_introduction.html#id59810">Overview</a></li>
</ul>
</li>
<li id="no" title="Installing cosNotification" expanded="false">Installing cosNotification<ul>
<li><a href="ch-install.html">
              Top of chapter
            </a></li>
<li title="Installation Process "><a href="ch-install.html#id61483">Installation Process </a></li>
</ul>
</li>
<li id="no" title="The Notification Service Components" expanded="false">The Notification Service Components<ul>
<li><a href="ch_system.html">
              Top of chapter
            </a></li>
<li title="The Notification Service Components"><a href="ch_system.html#id62962">The Notification Service Components</a></li>
</ul>
</li>
<li id="no" title="Filters and the Constraint Language BNF" expanded="false">Filters and the Constraint Language BNF<ul>
<li><a href="ch_BNF.html">
              Top of chapter
            </a></li>
<li title="Filters and the Constraint Language BNF"><a href="ch_BNF.html#id64314">Filters and the Constraint Language BNF</a></li>
</ul>
</li>
<li id="no" title="Quality Of Service and Admin Properties" expanded="false">Quality Of Service and Admin Properties<ul>
<li><a href="ch_QoS.html">
              Top of chapter
            </a></li>
<li title="Quality Of Service and Admin Properties"><a href="ch_QoS.html#id65103">Quality Of Service and Admin Properties</a></li>
</ul>
</li>
<li id="loadscrollpos" title="cosNotification Examples" expanded="true">cosNotification Examples<ul>
<li><a href="ch_example.html">
              Top of chapter
            </a></li>
<li title="A Tutorial on How to Create a Simple Service"><a href="ch_example.html#id65997">A Tutorial on How to Create a Simple Service</a></li>
</ul>
</li>
</ul>
</div></div>
<div id="content">
<div class="innertube">
<h1>7 cosNotification Examples</h1>
  

  <h3><a name="id65997">7.1 
        A Tutorial on How to Create a Simple Service</a></h3>
    

    <h4>Interface Design</h4>
      
      <p>To use the cosNotification application <strong>clients</strong> must be implemented. 
        There are twelve types of clients: </p>
      <ul>
        <li>Structured Push Consumer</li>
        <li>Sequence Push Consumer </li>
        <li>Any Push Consumer</li>
        <li>Structured Pull Consumer</li>
        <li>Sequence Pull Consumer</li>
        <li>Any Pull Consumer</li>
        <li>Structured Push Supplier</li>
        <li>Sequence Push Supplier</li>
        <li>Any Push Supplier</li>
        <li>Structured Pull Supplier</li>
        <li>Sequence Pull Supplier</li>
        <li>Any Pull Supplier</li>
      </ul>
      <p>The interfaces for these participants are defined in <strong>CosNotification.idl</strong>
        and <strong>CosNotifyComm.idl</strong>.</p>
    

    <h4>Generating a Client Interface</h4>
      
      <p>We start by creating an interface which inherits from the correct interface, e.g., <strong>CosNotifyComm::SequencePushConsumer</strong>. Hence, 
        we must also implement all operations defined in the SequencePushConsumer interface. The IDL-file could look like: </p>
      <div class="example"><pre>
#ifndef _MYCLIENT_IDL
#define _MYCLIENT_IDL
#include &lt;CosNotification.idl&gt;
#include &lt;CosNotifyComm.idl&gt;
 
module myClientImpl {
 
  interface ownInterface:CosNotifyComm::SequencePushConsumer {
 
    void ownFunctions(in any NeededArguments)
       raises(Systemexceptions,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>
      <p>The callback module must contain the necessary functions inherited from 
        <strong>CosNotification.idl</strong> and <strong>CosNotifyComm.idl</strong>.</p>
    

    <h4>How to Run Everything</h4>
      
      <p>Below is a short transcript on how to run cosNotification. </p>
      <div class="example"><pre>
 
%% 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),
      </pre></div>
      <p>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.</p>
    
  
</div>
<div class="footer">
<hr>
<p>Copyright © 2000-2012 Ericsson AB. All Rights Reserved.</p>
</div>
</div>
</div></body>
</html>