<html>
<head>
<base href="https://wiki.asterisk.org/wiki">
<link rel="stylesheet" href="/wiki/s/en/2172/18/9/_/styles/combined.css?spaceKey=TOP&forWysiwyg=true" type="text/css">
</head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
<h2><a href="https://wiki.asterisk.org/wiki/display/TOP/Listener+Pattern">Listener Pattern</a></h2>
<h4>Page <b>edited</b> by <a href="https://wiki.asterisk.org/wiki/display/~khunt">Ken Hunt</a>
</h4>
<br/>
<h4>Changes (4)</h4>
<div id="page-diffs">
<table class="diff" cellpadding="0" cellspacing="0">
<tr><td class="diff-snipped" >...<br></td></tr>
<tr><td class="diff-unchanged" > <br>|!ListenerPattern.png|border=1!| <br></td></tr>
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">|{center}*Figure 1. The Listener Pattern*{center}| <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">|*Figure 1. The Listener Pattern*| <br></td></tr>
<tr><td class="diff-unchanged" > <br> <br></td></tr>
<tr><td class="diff-snipped" >...<br></td></tr>
<tr><td class="diff-unchanged" > <br>|!Listener Pattern Sequence.png|border=1!| <br></td></tr>
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">|{center}*Figure 2. IceStorm used to propagate notifications.*{center}| <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">|*Figure 2. IceStorm used to propagate notifications.*| <br></td></tr>
<tr><td class="diff-unchanged" > <br> <br></td></tr>
<tr><td class="diff-snipped" >...<br></td></tr>
</table>
</div> <h4>Full Content</h4>
<div class="notificationGreySide">
<p>This page describes how the Listener Pattern is typically implemented within Asterisk SCF. </p>
<h5><a name="ListenerPattern-Overview"></a>Overview</h5>
<p>The Listener Pattern is a simple pattern in which an interface is defined by some event publisher with methods of the interface representing each of the events that the publisher produces, at least for a specific category of events. In this example, there is a Server component which exposes an interface of FooOperations. In addition to the operations <b>join()</b> and <b>visit()</b> the FooOperations interface also supports adding and removing listeners to those operations. The Listener interface is defined in another interface named FooListener. The FooListener interface provides a callback operation that serve as notification of each of the two primary operations of the FooOperations interface. In addition to providing the parameters provided to the original operations, the listener callback notifications can additionally provide arguments that described the outcome of the operation (such as success/failure), or provide any other information that might be useful. Since the Listener interface is typically custom designed for a specific set of operations, the interface designer can choose what type of additional information (if any) would be useful. </p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<td class='confluenceTd'><span class="image-wrap" style=""><img src="/wiki/download/attachments/5996584/ListenerPattern.png?version=1&modificationDate=1285894566209" style="border: 1px solid black" /></span></td>
</tr>
<tr>
<td class='confluenceTd'><b>Figure 1. The Listener Pattern</b></td>
</tr>
</tbody></table>
</div>
<p>When a Client of the Server process invokes the operations of the Server, notifications are sent to all registered listeners. Figure 2 below shows how IceStorm is typically used in Asterisk SCF to propagate the listener notifications. The Server process in this examples accepts the listener from the ListeningComponent, and creates (or retrieves) an IceStorm topic specific to it's needs. The Server then subscribes the FooListener proxy to the IceStorm topic on behalf of the ListeningComponent. </p>
<p>As Client operations are invoked on the FooOperations interface, the Server forwards notifications to the relevant IceStorm topic, which handles propagating the notifications to all registered listeners. This offloads the routing of notification messages from the Server to IceStorm, which is specifically designed to handle Quality of Service and other needs of a scalable messaging system. </p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<td class='confluenceTd'><span class="image-wrap" style=""><img src="/wiki/download/attachments/5996584/Listener+Pattern+Sequence.png?version=1&modificationDate=1285894577506" style="border: 1px solid black" /></span></td>
</tr>
<tr>
<td class='confluenceTd'><b>Figure 2. IceStorm used to propagate notifications.</b></td>
</tr>
</tbody></table>
</div>
<p>It should be noted that from the ListeningComponent perspective, the use of IceStorm to propagate notifications is totally transparent. From the listener's point of view, the messages could just have well come directly from the Server. </p>
</div>
<div id="commentsSection" class="wiki-content pageSection">
<div style="float: right;" class="grey">
<a href="https://wiki.asterisk.org/wiki/users/removespacenotification.action?spaceKey=TOP">Stop watching space</a>
<span style="padding: 0px 5px;">|</span>
<a href="https://wiki.asterisk.org/wiki/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
<a href="https://wiki.asterisk.org/wiki/display/TOP/Listener+Pattern">View Online</a>
|
<a href="https://wiki.asterisk.org/wiki/pages/diffpagesbyversion.action?pageId=5996584&revisedVersion=6&originalVersion=5">View Changes</a>
|
<a href="https://wiki.asterisk.org/wiki/display/TOP/Listener+Pattern?showComments=true&showCommentArea=true#addcomment">Add Comment</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>