blob: b9fc56e584a530e70279a664d77b98bb7a88ea34 [file] [log] [blame]
Clement Escoffier130ca572008-10-13 07:33:03 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Clement Escoffier3e0db1e2009-01-15 15:35:17 +00002<html><head>
3
4
Clement Escoffier130ca572008-10-13 07:33:03 +00005
Clement Escoffier3e0db1e2009-01-15 15:35:17 +00006 <title>Apache Felix - Event Admin Handlers</title>
7 <link rel="stylesheet" href="event-admin-handlers_files/site.css" type="text/css" media="all">
8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
9 </head><body>
10 <div class="title"><div class="logo"><a href="http://felix.apache.org/site/index.html"><img alt="Apache Felix" src="event-admin-handlers_files/logo.png" border="0"></a></div><div class="header"><a href="http://www.apache.org/"><img alt="Apache" src="event-admin-handlers_files/apache.png" border="0"></a></div></div>
11 <div class="menu">
12<ul>
13 <li><a href="http://felix.apache.org/site/news.html" title="news">news</a></li>
14 <li><a href="http://felix.apache.org/site/license.html" title="license">license</a></li>
Clement Escoffier580d1902009-07-21 12:06:46 +000015 <li><a href="http://felix.apache.org/site/downloads.cgi" rel="nofollow">downloads</a></li>
Clement Escoffier3e0db1e2009-01-15 15:35:17 +000016 <li><a href="http://felix.apache.org/site/documentation.html" title="documentation">documentation</a></li>
17 <li><a href="http://felix.apache.org/site/mailinglists.html" title="mailinglists">mailing lists</a></li>
18 <li><a href="http://felix.apache.org/site/contributing.html" title="Contributing">contributing</a></li>
Clement Escoffier580d1902009-07-21 12:06:46 +000019 <li><a href="http://www.apache.org/" rel="nofollow">asf</a></li>
20 <li><a href="http://www.apache.org/foundation/sponsorship.html" rel="nofollow">sponsorship</a></li>
21 <li><a href="http://www.apache.org/foundation/thanks.html" rel="nofollow">sponsors</a>
Clement Escoffier130ca572008-10-13 07:33:03 +000022<!-- ApacheCon Ad -->
Clement Escoffier580d1902009-07-21 12:06:46 +000023<iframe src="event-admin-handlers_files/button.html" style="border-width: 0pt; float: left;" scrolling="no" frameborder="0" height="135" width="135"></iframe>
Clement Escoffier3e0db1e2009-01-15 15:35:17 +000024<p style="height: 100px;">
25<!-- ApacheCon Ad -->
26</p></li></ul> </div>
27 <div class="main">
Clement Escoffier580d1902009-07-21 12:06:46 +000028<style type="text/css">
29 @import url(http://people.apache.org/~clement/ipojo/site/superfish.css);
30</style>
31
32<style type="text/css">
33 @import url(http://people.apache.org/~clement/ipojo/site/style.css);
34</style>
35
36<p>
37<script class="javascript" src="event-admin-handlers_files/shCore.js"></script>
38<script class="javascript" src="event-admin-handlers_files/shBrushCSharp.js"></script>
39<script class="javascript" src="event-admin-handlers_files/shBrushPhp.js"></script>
40<script class="javascript" src="event-admin-handlers_files/shBrushJScript.js"></script>
41<script class="javascript" src="event-admin-handlers_files/shBrushVb.js"></script>
42<script class="javascript" src="event-admin-handlers_files/shBrushSql.js"></script>
43<script class="javascript" src="event-admin-handlers_files/shBrushXml.js"></script>
44<script class="javascript" src="event-admin-handlers_files/shBrushShell.js"></script>
45<script class="javascript" src="event-admin-handlers_files/shBrushDelphi.js"></script>
46<script class="javascript" src="event-admin-handlers_files/shBrushPython.js"></script>
47<script class="javascript" src="event-admin-handlers_files/shBrushJava.js"></script>
48
49<script type="text/javascript" src="event-admin-handlers_files/jquery-1.js"></script>
50<script type="text/javascript" src="event-admin-handlers_files/hoverIntent.js"></script>
51<script type="text/javascript" src="event-admin-handlers_files/superfish.js"></script>
52<script type="text/javascript" src="event-admin-handlers_files/supersubs.js"></script>
53
54<script type="text/javascript">
55
56 $(document).ready(function(){
57 $("ul.sf-menu").supersubs({
58 minWidth: 14, // minimum width of sub-menus in em units
59 maxWidth: 30, // maximum width of sub-menus in em units
60 extraWidth: 1 // extra width can ensure lines don't sometimes turn over
61 // due to slight rounding differences and font-family
62 }).superfish(); // call supersubs first, then superfish, so that subs are
63 // not display:none when measuring. Call before initialising
64 // containing tabs for same reason.
65 });
66
67</script>
68</p><div class="main">
69<div class="page-header">
70<img src="event-admin-handlers_files/header.png" class="header">
71<a href="http://ipojo.org/"><img src="event-admin-handlers_files/ipojo.png" class="header-logo" width="225"></a>
72<ul class="sf-menu sf-js-enabled sf-shadow" id="ipojo-menu">
73<li class="current">
74<!-- Menu Overview -->
75<a href="" class="sf-with-ul">Overview<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
76<ul style="float: none; width: 14em; display: none; visibility: hidden;">
77 <li style="white-space: normal; float: left; width: 100%;">
78 <a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo.html" title="Apache Felix iPOJO">Home</a>
79 </li>
80 <li style="white-space: normal; float: left; width: 100%;">
81 <a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-why-choose-ipojo.html" title="apache-felix-ipojo-why-choose-ipojo">Why choose iPOJO</a>
82 </li>
83 <li style="white-space: normal; float: left; width: 100%;">
84 <a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-successstories.html" title="apache-felix-ipojo-successstories">Success stories</a>
85 </li>
86 <li style="white-space: normal; float: left; width: 100%;">
87 <a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-feature-overview.html" title="Apache Felix iPOJO Feature Overview">Features</a>
88 </li>
89</ul>
90</li>
91
92<li class="">
93<!-- Menu download -->
94</li><li>
95<a href="http://felix.apache.org/site/download.html" title="Download">Download </a>
96</li>
97
98<li class="">
99<!-- Menu Documentation -->
100<a href="" class="sf-with-ul">Documentation<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
101<ul style="float: none; width: 14em; display: none; visibility: hidden;">
102 <!-- sub- menu : getting started -->
103 <li style="white-space: normal; float: left; width: 100%;" class="">
104 <a style="float: none; width: auto;" href="" class="sf-with-ul">Getting Started<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
105 <ul style="left: 14em; float: none; width: 14em; display: none; visibility: hidden;">
106 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-in-10-minutes.html" title="iPOJO in 10 minutes">iPOJO in 10 minutes</a></li>
107 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/how-to-use-ipojo-annotations.html" title="How to use iPOJO Annotations">Using Annotations</a></li>
108 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-hello-word-maven-based-tutorial.html" title="iPOJO Hello Word (Maven-Based) tutorial">Maven tutorial</a></li>
109 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-advanced-tutorial.html" title="iPOJO Advanced Tutorial">Advanced tutorial</a></li>
110 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-dosgi.html" title="apache-felix-ipojo-dosgi">Using Distributed OSGi</a></li>
111 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-composition-tutorial.html" title="iPOJO Composition Tutorial">Application Composition</a></li>
112 </ul>
113 </li> <!-- end of getting started -->
114 <!-- sub menu : Describing Components -->
115 <li style="white-space: normal; float: left; width: 100%;" class="">
116 <a style="float: none; width: auto;" href="http://felix.apache.org/site/describing-components.html" class="sf-with-ul">Describing components<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
117 <ul style="left: 14em; float: none; width: 14em; display: none; visibility: hidden;">
118 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/service-requirement-handler.html" title="Service Requirement Handler">Requiring a service</a></li>
119 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/providing-osgi-services.html" title="Providing OSGi services">Providing a service</a></li>
120 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/lifecycle-callback-handler.html" title="Lifecycle Callback Handler">Lifecycle management</a></li>
121 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/configuration-handler.html" title="Configuration Handler">Configuration</a></li>
122 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/architecture-handler.html" title="Architecture Handler">Introspection</a></li>
123 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/controller-lifecycle-handler.html" title="Controller Lifecycle Handler">Impacting the lifecycle</a></li>
124 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="" title="Event Admin Handlers">Asynchronous communication</a></li>
125 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-jmx-handler.html" title="iPOJO JMX Handler">JMX management</a></li>
126 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/extender-pattern-handler.html" title="Extender Pattern Handler">Extender pattern</a></li>
127 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/white-board-pattern-handler.html" title="White Board Pattern Handler">Whiteboard pattern</a></li>
128 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/temporal-service-dependency.html" title="Temporal Service Dependency">Temporal dependencies</a></li>
129 </ul>
130 </li> <!-- End of describing components -->
131 <!-- sub- menu : User Guide -->
132 <li style="white-space: normal; float: left; width: 100%;" class="">
133 <a style="float: none; width: auto;" href="" class="sf-with-ul">User Guide<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
134 <ul style="left: 14em; float: none; width: 14em; display: none; visibility: hidden;">
135 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/using-xml-schemas.html" title="Using XML Schemas">XML Schemas</a></li>
136 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-api.html" title="apache-felix-ipojo-api">API</a></li>
137 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-testing-components.html" title="apache-felix-ipojo-testing-components">Testing components</a></li>
138 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-eclipse-integration.html" title="apache-felix-ipojo-eclipse-integration">Eclipse Integration</a></li>
139 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-faq.html" title="iPOJO FAQ">FAQ</a></li>
140 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-reference-card.html" title="iPOJO-Reference-Card">Reference Card</a></li>
141 </ul>
142 </li> <!-- end of user guide -->
143 <!-- sub- menu : Dev Guide -->
144 <li class="" style="white-space: normal; float: left; width: 100%;">
145 <a style="float: none; width: auto;" href="" class="sf-with-ul">Advanced Topics<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
146 <ul style="left: 14em; float: none; width: 14em; display: none; visibility: hidden;">
147 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/ipojo/api/1.2.0" rel="nofollow">Javadoc</a></li>
148 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/how-to-write-your-own-handler.html" title="How to write your own handler">Handler guide</a></li>
149 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/how-to-use-ipojo-manipulation-metadata.html" title="How to use iPOJO Manipulation Metadata">Manipulation Metadata </a></li>
150 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/dive-into-the-ipojo-manipulation-depths.html" title="Dive into the iPOJO Manipulation depths">Dive into the iPOJO Manipulation depths</a></li>
151 </ul>
152 </li> <!-- End of Dev guide -->
153</ul>
154</li> <!-- End of doc -->
155<!-- Menu 4 : Tools -->
156<li class="">
157<a href="" class="sf-with-ul">Tools<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
158<ul style="float: none; width: 14em; display: none; visibility: hidden;">
159 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-ant-task.html" title="iPOJO Ant Task">Ant Task</a></li>
160 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-eclipse-plug-in.html" title="iPOJO Eclipse Plug-in">Eclipse Plugin</a></li>
161 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-maven-plug-in.html" title="iPOJO Maven Plug-in">Maven Plugin</a></li>
162 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-online-manipulator.html" title="apache-felix-ipojo-online-manipulator">Online Manipulator</a></li>
163 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-webconsole-plugin.html" title="iPOJO Webconsole Plugin">Webconsole plugin</a></li>
164 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-junit4osgi.html" title="apache-felix-ipojo-junit4osgi">Junit4OSGi</a></li>
165</ul>
166</li><!-- End of tools -->
167<!-- Menu 5 : Misc -->
168<li class="">
169<a href="" class="sf-with-ul">Misc<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
170<ul style="float: none; width: 14em; display: none; visibility: hidden;">
171 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-issuestracker.html" title="apache-felix-ipojo-issuestracker">Issues Tracker</a></li>
172 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-supportedvms.html" title="apache-felix-ipojo-supportedVMs">Supported JVMs</a></li>
173 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-supportedosgi.html" title="apache-felix-ipojo-supportedOSGi">Supported OSGi Implementations</a></li>
174 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://ipojo-dark-side.blogspot.com/" rel="nofollow">iPOJO's Dark Side Blog</a></li>
175 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/article-presentations.html" title="Article &amp; Presentations">Article &amp; Presentations</a></li>
176</ul>
177</li><!-- End of misc -->
178</ul> <!-- End of the menu -->
179</div> <!-- Page header -->
180
181
182<div class="content">
183
Clement Escoffier130ca572008-10-13 07:33:03 +0000184
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000185<h1><a name="EventAdminHandlers-EventAdminHandlers"></a>Event Admin Handlers</h1>
Clement Escoffier130ca572008-10-13 07:33:03 +0000186
Clement Escoffier580d1902009-07-21 12:06:46 +0000187<p><em>The goal of the Event Admin Handlers is to allow event
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000188communications between iPOJO component instances. The implementation of
189these handlers relies on an event admin services. It enables the iPOJO
190component to listen to a list of topics and to receive all related
Clement Escoffier580d1902009-07-21 12:06:46 +0000191event. It also allows components to send events in an easy way.</em></p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000192
Clement Escoffier580d1902009-07-21 12:06:46 +0000193<div class="toc">
194<ul>
195 <li><a href="#EventAdminHandlers-Anexample">An example</a></li>
196 <li><a href="#EventAdminHandlers-Download">Download</a></li>
197 <li><a href="#EventAdminHandlers-Howdoesitwork%253F">How does it work?</a></li>
198 <li><a href="#EventAdminHandlers-EventHandlerSpecification">EventHandler Specification</a></li>
199<ul>
200 <li><a href="#EventAdminHandlers-Eventsubscriberattributes">Event subscriber attributes</a></li>
201 <li><a href="#EventAdminHandlers-Eventpublisherattributes">Event publisher attributes</a></li>
202 <li><a href="#EventAdminHandlers-Instanceconfiguration">Instance configuration</a></li>
203 <li><a href="#EventAdminHandlers-Publisherinterface">Publisher interface</a></li>
204</ul>
205 <li><a href="#EventAdminHandlers-HandlerArchitecture">Handler Architecture</a></li>
206 <li><a href="#EventAdminHandlers-EventHandlerFeatures">EventHandler Features</a></li>
207<ul>
208 <li><a href="#EventAdminHandlers-Instancecustomization">Instance customization</a></li>
209 <li><a href="#EventAdminHandlers-Dataevents">Data events</a></li>
210 <li><a href="#EventAdminHandlers-Noteonsynchronouseventsending">Note on synchronous event sending</a></li>
211 <li><a href="#EventAdminHandlers-Publisherinstanceinformation">Publisher instance information</a></li>
212 <li><a href="#EventAdminHandlers-Configuringthehandlerwithannotations">Configuring the handler with annotations</a></li>
213</ul>
214</ul></div>
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000215
Clement Escoffier580d1902009-07-21 12:06:46 +0000216<div class="panelMacro"><table class="infoMacro"><colgroup><col width="24"><col></colgroup><tbody><tr><td valign="top"><img src="event-admin-handlers_files/information.gif" alt="" border="0" align="absmiddle" height="16" width="16"></td><td><b>change in the 1.2.0</b><br><p>The 1.2.0 version use the namespace : <tt>org.apache.felix.ipojo.handlers.event</tt> instead of <tt>org.apache.felix.ipojo.handlers.event.EventAdminHandler</tt></p></td></tr></tbody></table></div>
217
218<h2><a name="EventAdminHandlers-Anexample"></a>An example</h2>
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000219<p>Hereafter is presented a small example of the metadata.xml file :</p>
Clement Escoffier580d1902009-07-21 12:06:46 +0000220<div class="code">
221<div class="dp-highlighter"><table class="dp-xml" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span></span><span class="tag">&lt;</span><span>ipojo&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;xmlns:<span class="attribute">ev</span><span>=</span><span class="attribute-value">"org.apache.felix.ipojo.handlers.event"</span><span>&gt;&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>component&nbsp;</span><span class="attribute">className</span><span>=</span><span class="attribute-value">"...MyComponent"</span><span>&gt;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>ev:subscriber&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">name</span><span>=</span><span class="attribute-value">"mySubscriber"</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">callback</span><span>=</span><span class="attribute-value">"receive"</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">topics</span><span>=</span><span class="attribute-value">"foo"</span><span>/&gt;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>ev:publisher&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">name</span><span>=</span><span class="attribute-value">"myPublisher"</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">field</span><span>=</span><span class="attribute-value">"m_publisher"</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">topics</span><span>=</span><span class="attribute-value">"bar,nuts"</span><span>/&gt;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;/</span><span>component</span><span class="tag">&gt;</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>instance&nbsp;</span><span class="attribute">component</span><span>=</span><span class="attribute-value">"...MyComponent"</span><span>/&gt;&nbsp;</span></td></tr><tr><td class="line2"><span class="tag">&lt;/</span><span>ipojo</span><span class="tag">&gt;</span><span>&nbsp;</span></td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly">&lt;ipojo
222 xmlns:ev="org.apache.felix.ipojo.handlers.event"&gt;
223 &lt;component className="...MyComponent"&gt;
Clement Escoffier130ca572008-10-13 07:33:03 +0000224 &lt;ev:subscriber
Clement Escoffier580d1902009-07-21 12:06:46 +0000225 name="mySubscriber"
226 callback="receive"
227 topics="foo"/&gt;
Clement Escoffier130ca572008-10-13 07:33:03 +0000228 &lt;ev:publisher
Clement Escoffier580d1902009-07-21 12:06:46 +0000229 name="myPublisher"
230 field="m_publisher"
231 topics="bar,nuts"/&gt;
232 &lt;/component&gt;
233 &lt;instance component="...MyComponent"/&gt;
234&lt;/ipojo&gt;</textarea>
235<script class="javascript">
236 if(!window.newcodemacro_initialised)
237 {
238 window.newcodemacro_initialised = true;
239 window.oldonloadmethod = window.onload;
240 window.onload = function(){
241 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
242 if(window.oldonloadmethod)
243 {
244 window.oldonloadmethod();
245 }
246 }
247 }
248
249</script>
250</div>
251
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000252<p>You need to specify the namespace of the Handler. You can find here
253one event subscriber (named mySubscriber) and one event publisher
254(named myPublisher). In these handler configurations, the name
255parameter is mandatory. The topics parameter is optional as it can be
256specified in the instance configuration. The callback parameter of the
257mySubscriber element is mandatory and indicates the method that handles
258received events. In this case, this method must have a single argument
259of type org.osgi.service.event.Event. The field parameter of the
260myPublisher element indicates the field (of type
261org.apache.felix.ipojo.handlers.event.publisher.Publisher) that is used
262by the POJO to send events on the specified topics. All type compliance
263will be checked by the handler at component instantiation time.</p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000264
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000265<p>Here is an example of the component implementation, compatible with the given description :</p>
Clement Escoffier580d1902009-07-21 12:06:46 +0000266<div class="code">
267<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span></span><span class="keyword">import</span><span>&nbsp;org.apache.felix.ipojo.handlers.event.publisher.Publisher;&nbsp;</span></td></tr><tr><td class="line2"><span class="keyword">import</span><span>&nbsp;org.osgi.service.event.Event;&nbsp;</span></td></tr><tr><td class="line1">&nbsp;</td></tr><tr><td class="line2"><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">class</span><span>&nbsp;MyComponent&nbsp;...&nbsp;{&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;Publisher&nbsp;m_publisher;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;receive(Event&nbsp;e)&nbsp;{&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;Event&nbsp;received</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;Do&nbsp;something&nbsp;with&nbsp;the&nbsp;event}</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;doSomething()&nbsp;{&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dictionary&nbsp;e&nbsp;=&nbsp;new&nbsp;Properties();&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//...</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;Fill&nbsp;out&nbsp;the&nbsp;event</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;Send&nbsp;event</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_publisher.send(e);&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</td></tr><tr><td class="line2">}&nbsp;</td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">import org.apache.felix.ipojo.handlers.event.publisher.Publisher;
268import org.osgi.service.event.Event;
Clement Escoffier130ca572008-10-13 07:33:03 +0000269
Clement Escoffier580d1902009-07-21 12:06:46 +0000270public class MyComponent ... {
271 private Publisher m_publisher;
272 public void receive(Event e) {
273 // Event received
274 // Do something with the event}
275
276 public void doSomething() {
277 Dictionary e = new Properties();
278 //...
279 // Fill out the event
280
281 // Send event
282 m_publisher.send(e);
Clement Escoffier130ca572008-10-13 07:33:03 +0000283 }
Clement Escoffier580d1902009-07-21 12:06:46 +0000284}</textarea>
285<script class="javascript">
286 if(!window.newcodemacro_initialised)
287 {
288 window.newcodemacro_initialised = true;
289 window.oldonloadmethod = window.onload;
290 window.onload = function(){
291 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
292 if(window.oldonloadmethod)
293 {
294 window.oldonloadmethod();
295 }
296 }
297 }
Clement Escoffier130ca572008-10-13 07:33:03 +0000298
Clement Escoffier580d1902009-07-21 12:06:46 +0000299</script>
300</div>
301
302
303<h2><a name="EventAdminHandlers-Download"></a>Download</h2>
Clement Escoffier130ca572008-10-13 07:33:03 +0000304
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000305<p>The event admin handlers (to send and receive events) are available in the Felix trunk in the iPOJO project. See the <a href="http://felix.apache.org/site/download.html" title="Download">Download</a> page to download and compile these sources.</p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000306
Clement Escoffier580d1902009-07-21 12:06:46 +0000307<h2><a name="EventAdminHandlers-Howdoesitwork?"></a>How does it work?</h2>
Clement Escoffier130ca572008-10-13 07:33:03 +0000308
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000309<p>The handler will parse the description provided in the metadata, and
310register for you the EventHandler in the OSGi Registry. On one hand,
311your POJO will receive each event through the handler. With this
312handler you can specify different callback methods for different
313topics. On the other side, the handler instantiates and injects
314configured Publisher references in your POJO, so you can send events
315transparently through these publishers.</p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000316
Clement Escoffier580d1902009-07-21 12:06:46 +0000317<h2><a name="EventAdminHandlers-EventHandlerSpecification"></a>EventHandler Specification</h2>
Clement Escoffier130ca572008-10-13 07:33:03 +0000318
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000319<p>Here you can find all configuration options of the EventAdmin
320handler. As seen before, the handler contains two components : the
321event subscriber and the event publisher. These components can be
322configured, using several attributes, as described below. Some of these
323attributes can be (re)defined in the instance configuration.</p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000324
Clement Escoffier580d1902009-07-21 12:06:46 +0000325<p><b>Handler namespace :</b> org.apache.felix.ipojo.handlers.event</p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000326
Clement Escoffier580d1902009-07-21 12:06:46 +0000327<h3><a name="EventAdminHandlers-Eventsubscriberattributes"></a>Event subscriber attributes</h3>
328<div class="borderedTable"><table class="confluenceTable"><tbody>
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000329<tr>
330<th class="confluenceTh"> Attribute name </th>
331<th class="confluenceTh"> Required </th>
332<th class="confluenceTh"> Description </th>
333</tr>
334<tr>
335<td class="confluenceTd"> <em>name</em> </td>
336<td class="confluenceTd"> YES </td>
337<td class="confluenceTd"> The name of the event subscriber, acting as a unique identifier. </td>
338</tr>
339<tr>
340<td class="confluenceTd"> <em>callback</em> </td>
341<td class="confluenceTd"> YES </td>
342<td class="confluenceTd"> The name of the POJO's method that will be
343called each time an event is received. This method takes only one
344parameter, of typeorg.osgi.service.event.Eventby default, but this type
345can be overridden by defining the data-key and/or the data-type
346attributes. </td>
347</tr>
348<tr>
349<td class="confluenceTd"> <em>topics</em> </td>
350<td class="confluenceTd"> YES* </td>
351<td class="confluenceTd"> The comma-separated-list of the topics that
352the handler will listen to. Each event sent on a topic present in this
353list will be sent to the specified callback method. </td>
354</tr>
355<tr>
356<td class="confluenceTd"> <em>data-key</em> </td>
357<td class="confluenceTd"> NO </td>
358<td class="confluenceTd"> The data key is used when you want to receive
359data events. This attribute's value is the key corresponding to the
360received data in the event's dictionary. <br clear="all">
361If you use this attribute, the parameter passed to the callback method
362is the the value associated to this key, not the whole event. <br clear="all">
363This attribute is generally used with the <em>data-type</em> attribute to specify the received object type. <br clear="all">
364If an event is received and it does not contain such a key, it is ignored (with a warning message). </td>
365</tr>
366<tr>
367<td class="confluenceTd"> <em>data-type</em> </td>
368<td class="confluenceTd"> NO </td>
369<td class="confluenceTd"> This attribute is associated to the data-key
370attribute. It specifies the type of objects (java.lang.Objectby
371default) that the callback expects. It is used to determine the unique
372callback method (in case of multiple methods with the same name) and to
373check type compliance at event reception. <br clear="all">
374Data events that are not corresponding to the specified type will be ignored (with a warning message). </td>
375</tr>
376<tr>
377<td class="confluenceTd"> <em>filter</em> </td>
378<td class="confluenceTd"> NO* </td>
379<td class="confluenceTd"> The event filter is used to filter incoming
380events before sending them to the callback. The syntax of this field is
381described in the OSGi EventAdmin Specification. If you don't specify a
382filter, all events sent on the listened topics will be considered. </td>
383</tr>
384</tbody></table>
Clement Escoffier580d1902009-07-21 12:06:46 +0000385<p>* These attributes can be (re)defined in the instance configuration.</p></div>
386<h3><a name="EventAdminHandlers-Eventpublisherattributes"></a>Event publisher attributes</h3>
387<div class="borderedTable"><table class="confluenceTable"><tbody>
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000388<tr>
389<th class="confluenceTh"> Attribute name </th>
390<th class="confluenceTh"> Required </th>
391<th class="confluenceTh"> Description </th>
392</tr>
393<tr>
394<td class="confluenceTd"> <em>name</em> </td>
395<td class="confluenceTd"> YES </td>
396<td class="confluenceTd"> The name of the event publisher, acting as a unique identifier. </td>
397</tr>
398<tr>
399<td class="confluenceTd"> <em>field</em> </td>
400<td class="confluenceTd"> YES </td>
401<td class="confluenceTd"> The name of the POJO's field that will be
402used to send events. The field is initialized at component
403instantiation time. The type of the field must be :
404org.apache.felix.ipojo.handlers.event.publisher.Publisher. Despite it
405creates a dependency between the component code and the handler, this
406system allows hiding the whole complexity of event sending. </td>
407</tr>
408<tr>
409<td class="confluenceTd"> <em>topics</em> </td>
410<td class="confluenceTd"> YES* </td>
411<td class="confluenceTd"> The comma-separated-list of the topics on which events will be sent. </td>
412</tr>
413<tr>
414<td class="confluenceTd"> <em>data-key</em> </td>
415<td class="confluenceTd"> NO </td>
416<td class="confluenceTd"> The data key is used when you want to send
417data events. This attribute's value is the key, in the event's
418dictionary, in which sent data are stored. When you use the <em>sendData</em> method of the Publisher, the given object is placed in the event dictionary, associated with the specified data-key. <br clear="all">
419The default value of this attribute is user.data. </td>
420</tr>
421<tr>
422<td class="confluenceTd"> <em>synchronous</em> </td>
423<td class="confluenceTd"> NO </td>
424<td class="confluenceTd"> Determines if event sending is synchronous or
425not. By default, events are sent asynchronously, but you can specify
426there the desired behaviour of the Publisher. <br clear="all">
427The default value of this attribute is "false". </td>
428</tr>
429</tbody></table>
Clement Escoffier580d1902009-07-21 12:06:46 +0000430<p>* These attributes can be (re)defined in the instance configuration.</p></div>
431<h3><a name="EventAdminHandlers-Instanceconfiguration"></a>Instance configuration</h3>
Clement Escoffier130ca572008-10-13 07:33:03 +0000432
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000433<p>Some of the described attributes can be (re)defined in the instance
434configuration section of your metadata file. Its permits to configure
435event management instance by instance. The following properties are
436used by the handler :</p>
437<ul>
438 <li><em>event.topics</em> : overrides <em>topics</em> attribute, available for both subscribers and publishers configuration</li>
439 <li><em>event.filter</em> : overrides <em>filter</em> attribute, available for subscribers configuration only.</li>
440</ul>
Clement Escoffier130ca572008-10-13 07:33:03 +0000441
442
Clement Escoffier580d1902009-07-21 12:06:46 +0000443<h3><a name="EventAdminHandlers-Publisherinterface"></a>Publisher interface</h3>
Clement Escoffier130ca572008-10-13 07:33:03 +0000444
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000445<p>The Publisher interface is the link between the component code and
446the handler. It permits to publish events on the topics specified in
447the component's description (or instance configuration). The
448implemented methods are :</p>
449<ul>
450 <li>public void send<font color="#000000">(Dictionary content);</font><br>
451This method is used to send a standard event, with the specified
452content. Some specific properties may be added in the content to
453satisfy EventAdmin specification. (e.g., event.topic).</li>
454 <li>public void sendData<font color="#000000">(Object o);</font><br>
455This method is the easier way to send data. The given object is placed in the event dictionary according to the <em>data-key</em> attribute (or its default value). Then, this dictionary is sent as a normal event.</li>
456</ul>
Clement Escoffier130ca572008-10-13 07:33:03 +0000457
458
Clement Escoffier580d1902009-07-21 12:06:46 +0000459<h2><a name="EventAdminHandlers-HandlerArchitecture"></a>Handler Architecture</h2>
Clement Escoffier130ca572008-10-13 07:33:03 +0000460
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000461<p>Here is shown the global architecture of the EventHandler : the
462interactions between the user components (i.e., POJO), the handler and
463the OSGi runtime environment.</p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000464
Clement Escoffier580d1902009-07-21 12:06:46 +0000465<p><img src="event-admin-handlers_files/handler-arch.png" border="0" align="absmiddle"></p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000466
Clement Escoffier580d1902009-07-21 12:06:46 +0000467<h2><a name="EventAdminHandlers-EventHandlerFeatures"></a>EventHandler Features</h2>
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000468<p>In this section, you will find some examples of the handler's features.</p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000469
Clement Escoffier580d1902009-07-21 12:06:46 +0000470<h3><a name="EventAdminHandlers-Instancecustomization"></a>Instance customization</h3>
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000471<p>As described in the 'Instance configuration' section, you can
472(re)define some of the subscribers or publishers attributes. You can
473notice that required attributes that are not defined in the component
474description must be defined in the instance configuration section.
475Hereafter is an example of an instance configuration of this handler :</p>
Clement Escoffier580d1902009-07-21 12:06:46 +0000476<div class="code">
477<div class="dp-highlighter"><table class="dp-xml" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span></span><span class="tag">&lt;</span><span>ipojo&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;xmlns:<span class="attribute">ev</span><span>=</span><span class="attribute-value">"org.apache.felix.ipojo.handlers.event"</span><span>&gt;&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>component&nbsp;</span><span class="attribute">className</span><span>=</span><span class="attribute-value">"...MyComponent"</span><span>&gt;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>ev:subscriber&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">name</span><span>=</span><span class="attribute-value">"mySubscriber"</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">callback</span><span>=</span><span class="attribute-value">"handleEvent"</span><span>/&gt;&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>ev:publisher&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">name</span><span>=</span><span class="attribute-value">"myPublisher"</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">field</span><span>=</span><span class="attribute-value">"m_publisher"</span><span>/&gt;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;/</span><span>component</span><span class="tag">&gt;</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>instance&nbsp;</span><span class="attribute">component</span><span>=</span><span class="attribute-value">"...MyComponent"</span><span>&gt;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>property&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">"event.topics"</span><span>&gt;&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>property&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">"mySubscriber"</span><span>&nbsp;</span><span class="attribute">value</span><span>=</span><span class="attribute-value">"foo"</span><span>/&gt;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>property&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">"myPublisher"</span><span>&nbsp;</span><span class="attribute">value</span><span>=</span><span class="attribute-value">"bar,nuts"</span><span>/&gt;&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;/</span><span>property</span><span class="tag">&gt;</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>property&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">"event.filter"</span><span>&gt;&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>property&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">"mySubscriber"</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">value</span><span>=</span><span class="attribute-value">"|((arg=Minibar)(arg=Coconuts))"</span><span>/&gt;&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;/</span><span>property</span><span class="tag">&gt;</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;/</span><span>instance</span><span class="tag">&gt;</span><span>&nbsp;</span></td></tr><tr><td class="line1"><span class="tag">&lt;/</span><span>ipojo</span><span class="tag">&gt;</span><span>&nbsp;</span></td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly">&lt;ipojo
478 xmlns:ev="org.apache.felix.ipojo.handlers.event"&gt;
479 &lt;component className="...MyComponent"&gt;
Clement Escoffier130ca572008-10-13 07:33:03 +0000480 &lt;ev:subscriber
Clement Escoffier580d1902009-07-21 12:06:46 +0000481 name="mySubscriber"
482 callback="handleEvent"/&gt;
Clement Escoffier130ca572008-10-13 07:33:03 +0000483 &lt;ev:publisher
Clement Escoffier580d1902009-07-21 12:06:46 +0000484 name="myPublisher"
485 field="m_publisher"/&gt;
486 &lt;/component&gt;
487 &lt;instance component="...MyComponent"&gt;
488 &lt;property name="event.topics"&gt;
489 &lt;property name="mySubscriber" value="foo"/&gt;
490 &lt;property name="myPublisher" value="bar,nuts"/&gt;
491 &lt;/property&gt;
492 &lt;property name="event.filter"&gt;
493 &lt;property name="mySubscriber"
494 value="|((arg=Minibar)(arg=Coconuts))"/&gt;
495 &lt;/property&gt;
496 &lt;/instance&gt;
497&lt;/ipojo&gt;</textarea>
498<script class="javascript">
499 if(!window.newcodemacro_initialised)
500 {
501 window.newcodemacro_initialised = true;
502 window.oldonloadmethod = window.onload;
503 window.onload = function(){
504 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
505 if(window.oldonloadmethod)
506 {
507 window.oldonloadmethod();
508 }
509 }
510 }
Clement Escoffier130ca572008-10-13 07:33:03 +0000511
Clement Escoffier580d1902009-07-21 12:06:46 +0000512</script>
513</div>
Clement Escoffier130ca572008-10-13 07:33:03 +0000514
Clement Escoffier580d1902009-07-21 12:06:46 +0000515
516<h3><a name="EventAdminHandlers-Dataevents"></a>Data events</h3>
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000517<p>One of the most important features of the EventHandler is the
518capability of sending and receiving data events. You may know that the
519OSGi EventAdmin Service allows bundles to send custom objects in
520events, inserting them in the event's dictionary. The EventHandler
521hides the dictionary manipulation and allows iPOJO components to
522receive custom objects at any time.</p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000523
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000524<p>First, you have define the <em>data-key</em> attribute in the
525publisher configuration. Sent objects will be contained in the event
526dictionary and are accessible with the "user.data" key.</p>
Clement Escoffier580d1902009-07-21 12:06:46 +0000527<div class="code">
528<div class="dp-highlighter"><table class="dp-xml" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span></span><span class="tag">&lt;</span><span>ipojo&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;xmlns:<span class="attribute">ev</span><span>=</span><span class="attribute-value">"org.apache.felix.ipojo.handlers.event"</span><span>&gt;&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>component&nbsp;</span><span class="attribute">className</span><span>=</span><span class="attribute-value">"...DataPublisher"</span><span>&gt;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>ev:publisher&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">name</span><span>=</span><span class="attribute-value">"myPublisher"</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">field</span><span>=</span><span class="attribute-value">"m_publisher"</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">topics</span><span>=</span><span class="attribute-value">"myTopic"</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">data-key</span><span>=</span><span class="attribute-value">"my.data"</span><span>/&gt;&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;/</span><span>component</span><span class="tag">&gt;</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>instance&nbsp;</span><span class="attribute">component</span><span>=</span><span class="attribute-value">"...DataPublisher"</span><span>/&gt;&nbsp;</span></td></tr><tr><td class="line1"><span class="tag">&lt;/</span><span>ipojo</span><span class="tag">&gt;</span><span>&nbsp;</span></td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly">&lt;ipojo
529 xmlns:ev="org.apache.felix.ipojo.handlers.event"&gt;
530 &lt;component className="...DataPublisher"&gt;
Clement Escoffier130ca572008-10-13 07:33:03 +0000531 &lt;ev:publisher
Clement Escoffier580d1902009-07-21 12:06:46 +0000532 name="myPublisher"
533 field="m_publisher"
534 topics="myTopic"
535 data-key="my.data"/&gt;
536 &lt;/component&gt;
537 &lt;instance component="...DataPublisher"/&gt;
538&lt;/ipojo&gt;</textarea>
539<script class="javascript">
540 if(!window.newcodemacro_initialised)
541 {
542 window.newcodemacro_initialised = true;
543 window.oldonloadmethod = window.onload;
544 window.onload = function(){
545 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
546 if(window.oldonloadmethod)
547 {
548 window.oldonloadmethod();
549 }
550 }
Clement Escoffier130ca572008-10-13 07:33:03 +0000551 }
Clement Escoffier130ca572008-10-13 07:33:03 +0000552
Clement Escoffier580d1902009-07-21 12:06:46 +0000553</script>
554</div>
555
556<p>Then you can use the <em>sendData</em> method of your configured publisher.</p>
557<div class="code">
558<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span></span><span class="keyword">import</span><span>&nbsp;org.apache.felix.ipojo.handlers.event.publisher.Publisher;&nbsp;</span></td></tr><tr><td class="line2"><span class="comment">//...</span><span>&nbsp;</span></td></tr><tr><td class="line1"><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">class</span><span>&nbsp;DataPublisher&nbsp;...&nbsp;{&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;Publisher&nbsp;m_publisher;&nbsp;</span></td></tr><tr><td class="line1">&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;doSomething()&nbsp;{&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;MyFavoriteType&nbsp;extends&nbsp;MyFavoriteInterface</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyFavoriteType&nbsp;data&nbsp;=&nbsp;new&nbsp;MyFavoriteType(...);&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//...</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;Send&nbsp;a&nbsp;data&nbsp;event</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_publisher.sendData(data);&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</td></tr><tr><td class="line1">}&nbsp;</td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">import org.apache.felix.ipojo.handlers.event.publisher.Publisher;
559//...
560public class DataPublisher ... {
561 private Publisher m_publisher;
562
563 public void doSomething() {
564 // MyFavoriteType extends MyFavoriteInterface
565 MyFavoriteType data = new MyFavoriteType(...);
566 //...
567 // Send a data event
568 m_publisher.sendData(data);
569 }
570}</textarea>
571<script class="javascript">
572 if(!window.newcodemacro_initialised)
573 {
574 window.newcodemacro_initialised = true;
575 window.oldonloadmethod = window.onload;
576 window.onload = function(){
577 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
578 if(window.oldonloadmethod)
579 {
580 window.oldonloadmethod();
581 }
582 }
583 }
584
585</script>
586</div>
587
588<p>The second step is to configure an event subscriber to receive such events. The <em>data-key</em> attribute's value of the subscriber must be the same than the publisher's one. The <em>data-type</em>
589describes the type of received data events, and thus, must be
590compatible with the sent object's type (i.e., super-class or inherited
591interface). Then you can finally receive the sent object in the
592callback method. The parameter type of the callback must be the same
593than the data-type attribute value.</p>
594<div class="code">
595<div class="dp-highlighter"><table class="dp-xml" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span></span><span class="tag">&lt;</span><span>ipojo&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;xmlns:<span class="attribute">ev</span><span>=</span><span class="attribute-value">"org.apache.felix.ipojo.handlers.event"</span><span>&gt;&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>component&nbsp;</span><span class="attribute">className</span><span>=</span><span class="attribute-value">"...DataEventSubscriber"</span><span>&gt;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>ev:subscriber&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">name</span><span>=</span><span class="attribute-value">"mySubscriber"</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">callback</span><span>=</span><span class="attribute-value">"handleData"</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">topics</span><span>=</span><span class="attribute-value">"myTopic"</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">data-key</span><span>=</span><span class="attribute-value">"my.data"</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">data-type</span><span>=</span><span class="attribute-value">"my.package.MyFavoriteInterface"</span><span>/&gt;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;/</span><span>component</span><span class="tag">&gt;</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>instance&nbsp;</span><span class="attribute">component</span><span>=</span><span class="attribute-value">"...DataEventSubscriber"</span><span>/&gt;&nbsp;</span></td></tr><tr><td class="line2"><span class="tag">&lt;/</span><span>ipojo</span><span class="tag">&gt;</span><span>&nbsp;</span></td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly">&lt;ipojo
596 xmlns:ev="org.apache.felix.ipojo.handlers.event"&gt;
597 &lt;component className="...DataEventSubscriber"&gt;
598 &lt;ev:subscriber
599 name="mySubscriber"
600 callback="handleData"
601 topics="myTopic"
602 data-key="my.data"
603 data-type="my.package.MyFavoriteInterface"/&gt;
604 &lt;/component&gt;
605 &lt;instance component="...DataEventSubscriber"/&gt;
606&lt;/ipojo&gt;</textarea>
607<script class="javascript">
608 if(!window.newcodemacro_initialised)
609 {
610 window.newcodemacro_initialised = true;
611 window.oldonloadmethod = window.onload;
612 window.onload = function(){
613 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
614 if(window.oldonloadmethod)
615 {
616 window.oldonloadmethod();
617 }
618 }
619 }
620
621</script>
622</div>
623
624<div class="code">
625<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span></span><span class="keyword">import</span><span>&nbsp;my.</span><span class="keyword">package</span><span>.MyFavoriteInterface;&nbsp;</span></td></tr><tr><td class="line2"><span class="comment">//...</span><span>&nbsp;</span></td></tr><tr><td class="line1"><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">class</span><span>&nbsp;DataEventSubscriber&nbsp;...&nbsp;{&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;handleData(MyFavoriteInterface&nbsp;o)&nbsp;{&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;Object&nbsp;received</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//...</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;}&nbsp;</td></tr><tr><td class="line2">}&nbsp;</td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">import my.package.MyFavoriteInterface;
626//...
627public class DataEventSubscriber ... {
628 public void handleData(MyFavoriteInterface o) {
629 // Object received
630 //...
631 }
632}</textarea>
633<script class="javascript">
634 if(!window.newcodemacro_initialised)
635 {
636 window.newcodemacro_initialised = true;
637 window.oldonloadmethod = window.onload;
638 window.onload = function(){
639 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
640 if(window.oldonloadmethod)
641 {
642 window.oldonloadmethod();
643 }
644 }
645 }
646
647</script>
648</div>
649
650
651<h3><a name="EventAdminHandlers-Noteonsynchronouseventsending"></a>Note on synchronous event sending</h3>
Clement Escoffier130ca572008-10-13 07:33:03 +0000652
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000653<p>By default, events are sent using asynchronous sending (a.k.a.<em>post</em> in OSGi EventAdmin). You can use synchronous sending by defining the <em>synchronous</em> attribute of your publisher to true.</p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000654
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000655<p>The behaviour of synchronous event sending is particular when you
656specify several topics in the publisher description. The event is
657synchronously sent to each topic, one by one. So when you return from
658this function, you can be sure that the event has been delivered to
659each topic.</p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000660
Clement Escoffier580d1902009-07-21 12:06:46 +0000661<h3><a name="EventAdminHandlers-Publisherinstanceinformation"></a>Publisher instance information</h3>
Clement Escoffier130ca572008-10-13 07:33:03 +0000662
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000663<p>All events sent by a publisher contains the name of the component
664instance that sent them. Its enables to filter received events
665depending the sender instance. The instance name is accessible in the
666event dictionary by the key <em>publisher.instance.name</em>. Despite it goes against MOM principles, this property is useful to trace events and especially event sources.</p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000667
668
Clement Escoffier580d1902009-07-21 12:06:46 +0000669<h3><a name="EventAdminHandlers-Configuringthehandlerwithannotations"></a>Configuring the handler with annotations</h3>
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000670
671<p>It is possible to configure the handler with a simple annotations
672available in the annotation pack ('annotation' project in the iPOJO
673trunk). Here is an example of usage:</p>
Clement Escoffier580d1902009-07-21 12:06:46 +0000674<div class="code">
675<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span></span><span class="keyword">import</span><span>&nbsp;org.apache.felix.ipojo.annotations.Component;&nbsp;</span></td></tr><tr><td class="line2"><span class="keyword">import</span><span>&nbsp;org.apache.felix.ipojo.handlers.event.Subscriber;&nbsp;</span></td></tr><tr><td class="line1"><span class="keyword">import</span><span>&nbsp;org.osgi.service.event.Event;&nbsp;</span></td></tr><tr><td class="line2"><span class="preprocessor"></span></td></tr><tr><td class="line1"><span class="preprocessor"></span></td></tr><tr><td class="line2"><span class="preprocessor">@Component</span><span>&nbsp;</span></td></tr><tr><td class="line1"><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">class</span><span>&nbsp;PubSub&nbsp;{&nbsp;</span></td></tr><tr><td class="line2"><span class="preprocessor">&nbsp;&nbsp;&nbsp;&nbsp;@org.apache.felix.ipojo.handlers.event.Publisher(name="p1",&nbsp;synchronous=true)</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;org.apache.felix.ipojo.handlers.event.publisher.Publisher&nbsp;publisher1;&nbsp;</td></tr><tr><td class="line2"><span class="preprocessor">&nbsp;&nbsp;&nbsp;&nbsp;</span></td></tr><tr><td class="line1"><span class="preprocessor">&nbsp;&nbsp;&nbsp;&nbsp;@org.apache.felix.ipojo.handlers.event.Publisher(name="p2",&nbsp;synchronous=false,&nbsp;topics="foo,bar",&nbsp;data_key="data")</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;org.apache.felix.ipojo.handlers.event.publisher.Publisher&nbsp;publisher2;&nbsp;</td></tr><tr><td class="line1"><span class="preprocessor">&nbsp;&nbsp;&nbsp;&nbsp;</span></td></tr><tr><td class="line2"><span class="preprocessor">&nbsp;&nbsp;&nbsp;&nbsp;@org.apache.felix.ipojo.handlers.event.Publisher(name="p3",&nbsp;synchronous=true,&nbsp;topics="bar")</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;org.apache.felix.ipojo.handlers.event.publisher.Publisher&nbsp;publisher3;&nbsp;</td></tr><tr><td class="line2"><span class="preprocessor">&nbsp;&nbsp;&nbsp;&nbsp;</span></td></tr><tr><td class="line1"><span class="preprocessor">&nbsp;&nbsp;&nbsp;&nbsp;@Subscriber(name="s1",&nbsp;data_key="data")</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;receive1(Object&nbsp;foo)&nbsp;{&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;Process&nbsp;event</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</td></tr><tr><td class="line1"><span class="preprocessor">&nbsp;&nbsp;&nbsp;&nbsp;</span></td></tr><tr><td class="line2"><span class="preprocessor">&nbsp;&nbsp;&nbsp;&nbsp;@Subscriber(name="s2",&nbsp;topics="foo,bar",&nbsp;filter="(foo=true)")</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;receive2(Event&nbsp;foo)&nbsp;{&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;Process&nbsp;event</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</td></tr><tr><td class="line2"><span class="preprocessor">&nbsp;&nbsp;&nbsp;&nbsp;</span></td></tr><tr><td class="line1"><span class="preprocessor">&nbsp;&nbsp;&nbsp;&nbsp;</span></td></tr><tr><td class="line2"><span class="preprocessor">&nbsp;&nbsp;&nbsp;&nbsp;@Subscriber(name="s3",&nbsp;topics="foo",&nbsp;data_key="data",&nbsp;data_type="java.lang.String")</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;receive3(String&nbsp;foo)&nbsp;{&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;Process&nbsp;event</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</td></tr><tr><td class="line2">}&nbsp;</td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">import org.apache.felix.ipojo.annotations.Component;
676import org.apache.felix.ipojo.handlers.event.Subscriber;
677import org.osgi.service.event.Event;
Clement Escoffier130ca572008-10-13 07:33:03 +0000678
679
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000680@Component
Clement Escoffier580d1902009-07-21 12:06:46 +0000681public class PubSub {
682 @org.apache.felix.ipojo.handlers.event.Publisher(name="p1", synchronous=true)
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000683 org.apache.felix.ipojo.handlers.event.publisher.Publisher publisher1;
684
Clement Escoffier580d1902009-07-21 12:06:46 +0000685 @org.apache.felix.ipojo.handlers.event.Publisher(name="p2", synchronous=false, topics="foo,bar", data_key="data")
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000686 org.apache.felix.ipojo.handlers.event.publisher.Publisher publisher2;
687
Clement Escoffier580d1902009-07-21 12:06:46 +0000688 @org.apache.felix.ipojo.handlers.event.Publisher(name="p3", synchronous=true, topics="bar")
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000689 org.apache.felix.ipojo.handlers.event.publisher.Publisher publisher3;
690
Clement Escoffier580d1902009-07-21 12:06:46 +0000691 @Subscriber(name="s1", data_key="data")
692 public void receive1(Object foo) {
693 // Process event
694 }
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000695
Clement Escoffier580d1902009-07-21 12:06:46 +0000696 @Subscriber(name="s2", topics="foo,bar", filter="(foo=true)")
697 public void receive2(Event foo) {
698 // Process event
699 }
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000700
701
Clement Escoffier580d1902009-07-21 12:06:46 +0000702 @Subscriber(name="s3", topics="foo", data_key="data", data_type="java.lang.String")
703 public void receive3(String foo) {
704 // Process event
705 }
706}</textarea>
707<script class="javascript">
708 if(!window.newcodemacro_initialised)
709 {
710 window.newcodemacro_initialised = true;
711 window.oldonloadmethod = window.onload;
712 window.onload = function(){
713 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
714 if(window.oldonloadmethod)
715 {
716 window.oldonloadmethod();
717 }
718 }
719 }
Clement Escoffier130ca572008-10-13 07:33:03 +0000720
Clement Escoffier580d1902009-07-21 12:06:46 +0000721</script>
722</div>
Clement Escoffier130ca572008-10-13 07:33:03 +0000723
Clement Escoffier580d1902009-07-21 12:06:46 +0000724<p><br clear="all"></p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000725
Clement Escoffier580d1902009-07-21 12:06:46 +0000726 </div>
727 <img src="event-admin-handlers_files/footer.png" class="footer">
728</div>
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000729
730<script type="text/javascript">
731var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
732document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
733</script><script src="event-admin-handlers_files/ga.js" type="text/javascript"></script>
734<script type="text/javascript">
Clement Escoffier580d1902009-07-21 12:06:46 +0000735try{
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000736var pageTracker = _gat._getTracker("UA-1518442-4");
737pageTracker._trackPageview();
Clement Escoffier580d1902009-07-21 12:06:46 +0000738} catch(err) {}
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000739</script>
Clement Escoffier580d1902009-07-21 12:06:46 +0000740
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000741 </div>
742 </body></html>