blob: b80c7359c34d2066bc122ab9f7df0ab3e7bc01f5 [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 - iPOJO JMX Handler</title>
7 <link rel="stylesheet" href="ipojo-jmx-handler_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="ipojo-jmx-handler_files/logo.png" border="0"></a></div><div class="header"><a href="http://www.apache.org/"><img alt="Apache" src="ipojo-jmx-handler_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="ipojo-jmx-handler_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="ipojo-jmx-handler_files/shCore.js"></script>
38<script class="javascript" src="ipojo-jmx-handler_files/shBrushCSharp.js"></script>
39<script class="javascript" src="ipojo-jmx-handler_files/shBrushPhp.js"></script>
40<script class="javascript" src="ipojo-jmx-handler_files/shBrushJScript.js"></script>
41<script class="javascript" src="ipojo-jmx-handler_files/shBrushVb.js"></script>
42<script class="javascript" src="ipojo-jmx-handler_files/shBrushSql.js"></script>
43<script class="javascript" src="ipojo-jmx-handler_files/shBrushXml.js"></script>
44<script class="javascript" src="ipojo-jmx-handler_files/shBrushShell.js"></script>
45<script class="javascript" src="ipojo-jmx-handler_files/shBrushDelphi.js"></script>
46<script class="javascript" src="ipojo-jmx-handler_files/shBrushPython.js"></script>
47<script class="javascript" src="ipojo-jmx-handler_files/shBrushJava.js"></script>
48
49<script type="text/javascript" src="ipojo-jmx-handler_files/jquery-1.js"></script>
50<script type="text/javascript" src="ipojo-jmx-handler_files/hoverIntent.js"></script>
51<script type="text/javascript" src="ipojo-jmx-handler_files/superfish.js"></script>
52<script type="text/javascript" src="ipojo-jmx-handler_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="ipojo-jmx-handler_files/header.png" class="header">
71<a href="http://ipojo.org/"><img src="ipojo-jmx-handler_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="http://felix.apache.org/site/event-admin-handlers.html" 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="" 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">
Clement Escoffier130ca572008-10-13 07:33:03 +0000183
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000184<h1><a name="iPOJOJMXHandler-iPOJOJMXHandler"></a>iPOJO JMX Handler</h1>
Clement Escoffier130ca572008-10-13 07:33:03 +0000185
Clement Escoffier580d1902009-07-21 12:06:46 +0000186<p><em>This handler provides JMX management of component instance. It
187could be useful to manage instance remotely. As the handler exposes
188MBeans, you must have a MBean server running on your platform (as the
189platform MBean server or the MOSGi MBean Server).</em></p>
190
191<div class="toc">
192<ul>
193 <li><a href="#iPOJOJMXHandler-Features">Features</a></li>
194 <li><a href="#iPOJOJMXHandler-Prerequisites">Prerequisites</a></li>
195 <li><a href="#iPOJOJMXHandler-Download">Download</a></li>
196 <li><a href="#iPOJOJMXHandler-Howtouseit">How to use it</a></li>
197 <li><a href="#iPOJOJMXHandler-JMXHandleroptions">JMX Handler options</a></li>
198 <li><a href="#iPOJOJMXHandler-Globalhandlerattributes">Global handler attributes</a></li>
199 <li><a href="#iPOJOJMXHandler-Propertiesattributes">Properties attributes</a></li>
200 <li><a href="#iPOJOJMXHandler-Methodsattributes">Methods attributes</a></li>
201 <li><a href="#iPOJOJMXHandler-Examples">Examples</a></li>
202<ul>
203 <li><a href="#iPOJOJMXHandler-ExposingAttributes">Exposing Attributes</a></li>
204 <li><a href="#iPOJOJMXHandler-ExposingMethods">Exposing Methods</a></li>
205 <li><a href="#iPOJOJMXHandler-AttributeNotifications%253A">Attribute Notifications:</a></li>
206</ul>
207 <li><a href="#iPOJOJMXHandler-Configuringthehandlerwithannotations">Configuring the handler with annotations</a></li>
208</ul></div>
Clement Escoffier130ca572008-10-13 07:33:03 +0000209
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000210<h2><a name="iPOJOJMXHandler-Features"></a>Features</h2>
Clement Escoffier130ca572008-10-13 07:33:03 +0000211
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000212<p>The handler allows to:</p>
213<ul>
214 <li>Expose attributes accessible via JMX (with rights management).</li>
215 <li>Expose methods to be called through JMX.</li>
216 <li>Get notifications when attributes are modified .</li>
217</ul>
Clement Escoffier130ca572008-10-13 07:33:03 +0000218
219
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000220<h2><a name="iPOJOJMXHandler-Prerequisites"></a>Prerequisites</h2>
Clement Escoffier130ca572008-10-13 07:33:03 +0000221
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000222<p>To be functional this handler must register on an MBean Server,thus
223you obviously need it. Several servers are currently supported : the
224standard platform MBean server (included in the JDK), MOSGi (provided
225with Felix), ...<br>
226To use MOSGi, you have to deploy at least the following three bundles of MOSGi:</p>
227<ul>
228 <li>org.apache.felix.mosgi.jmx.agent</li>
229 <li>org.apache.felix.mosgi.jmx.registry</li>
230 <li>org.apache.felix.mosgi.jmx.rmiconnector</li>
231</ul>
Clement Escoffier130ca572008-10-13 07:33:03 +0000232
233
Clement Escoffier580d1902009-07-21 12:06:46 +0000234<p>You can find MOSGi documentation on <a href="http://cwiki.apache.org/FELIX/mosgi-managed-osgi-framework.html" rel="nofollow">http://cwiki.apache.org/FELIX/mosgi-managed-osgi-framework.html</a></p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000235
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000236<h2><a name="iPOJOJMXHandler-Download"></a>Download</h2>
Clement Escoffier130ca572008-10-13 07:33:03 +0000237
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000238<p>The JMX handler is 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 +0000239
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000240<h2><a name="iPOJOJMXHandler-Howtouseit"></a>How to use it</h2>
Clement Escoffier130ca572008-10-13 07:33:03 +0000241
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000242<p>The handler needs to be added in the metadata.xml, you just add a namespace (e.g., jmx) :</p>
Clement Escoffier580d1902009-07-21 12:06:46 +0000243<div class="code">
244<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;xmlns:</span><span class="attribute">jmx</span><span>=</span><span class="attribute-value">"org.apache.felix.ipojo.handlers.jmx"</span><span>&gt;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;...&nbsp;</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 xmlns:jmx="org.apache.felix.ipojo.handlers.jmx"&gt;
Clement Escoffier130ca572008-10-13 07:33:03 +0000245 ...
Clement Escoffier580d1902009-07-21 12:06:46 +0000246&lt;/ipojo&gt;</textarea>
247<script class="javascript">
248 if(!window.newcodemacro_initialised)
249 {
250 window.newcodemacro_initialised = true;
251 window.oldonloadmethod = window.onload;
252 window.onload = function(){
253 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
254 if(window.oldonloadmethod)
255 {
256 window.oldonloadmethod();
257 }
258 }
259 }
260
261</script>
262</div>
263
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000264<p>So, you could now expose in JMX properties and methods of your component. They are surrounded by the &lt;jmx:config&gt;<br>
265tag.</p>
Clement Escoffier580d1902009-07-21 12:06:46 +0000266<div class="code">
267<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>jmx:config</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>jmx:property&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">"message"</span><span>&nbsp;</span><span class="attribute">field</span><span>=</span><span class="attribute-value">"m_msg"</span><span>&nbsp;</span><span class="attribute">rights</span><span>=</span><span class="attribute-value">"w"</span><span>&nbsp;</span><span class="attribute">notification</span><span>=</span><span class="attribute-value">"true"</span><span>/&gt;&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>jmx:method&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">"doSomethingBad"</span><span>/&gt;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>jmx:method&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">"doSomethingGood"</span><span>/&gt;&nbsp;</span></td></tr><tr><td class="line1"><span class="tag">&lt;/</span><span>jmx:config</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;jmx:config&gt;
268 &lt;jmx:property name="message" field="m_msg" rights="w" notification="true"/&gt;
269 &lt;jmx:method name="doSomethingBad"/&gt;
270 &lt;jmx:method name="doSomethingGood"/&gt;
271&lt;/jmx:config&gt;</textarea>
272<script class="javascript">
273 if(!window.newcodemacro_initialised)
274 {
275 window.newcodemacro_initialised = true;
276 window.oldonloadmethod = window.onload;
277 window.onload = function(){
278 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
279 if(window.oldonloadmethod)
280 {
281 window.oldonloadmethod();
282 }
283 }
284 }
285
286</script>
287</div>
288
289<div class="panelMacro"><table class="infoMacro"><colgroup><col width="24"><col></colgroup><tbody><tr><td valign="top"><img src="ipojo-jmx-handler_files/information.gif" alt="" border="0" align="absmiddle" height="16" width="16"></td><td><b>Serialization</b><br><p>Be
290careful that the argument and return type of methods must be
291serializable. In case of several methods have the same name, each of
292them will be exposed.</p></td></tr></tbody></table></div>
Clement Escoffier130ca572008-10-13 07:33:03 +0000293
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000294<h2><a name="iPOJOJMXHandler-JMXHandleroptions"></a>JMX Handler options</h2>
Clement Escoffier130ca572008-10-13 07:33:03 +0000295
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000296<p>Here you can find all configuration options of the JMX handler.
297There are two kinds of manageable elements : properties and methods.
298First is described the global configuration of the handler. Then
299elements can be configured, using several attributes, as described
300below.</p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000301
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000302<h2><a name="iPOJOJMXHandler-Globalhandlerattributes"></a>Global handler attributes</h2>
Clement Escoffier580d1902009-07-21 12:06:46 +0000303<div class="borderedTable"><table class="confluenceTable"><tbody>
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000304<tr>
305<th class="confluenceTh">Attribute name </th>
306<th class="confluenceTh"> Required </th>
307<th class="confluenceTh"> Description</th>
308</tr>
309<tr>
310<td class="confluenceTd">objectName</td>
311<td class="confluenceTd">NO</td>
312<td class="confluenceTd">The complete object name of the managed
313component. The syntax of this attribute must be compliant with the
314ObjectName syntax, detailed in the JMX specification.<br>
315If neither domain nor name attributes are specified, the default value
316is determined by the package, the type and the instance name of the
317component. This attribute overrides the domain and name attributes.<br>
318<em>Example:</em> "my.domain:type=myType,name=myName"</td>
319</tr>
320<tr>
321<td class="confluenceTd">domain</td>
322<td class="confluenceTd">NO</td>
323<td class="confluenceTd">The domain of the managed object (i.e., the
324left part of the object name). This attribute must be compliant with
325the domain syntax, as described in the JMX specification.<br>
326<em>Example:</em> "my.domain"</td>
327</tr>
328<tr>
329<td class="confluenceTd">name</td>
330<td class="confluenceTd">NO</td>
331<td class="confluenceTd">The name property of the managed object. The
332value of this attribute must comply with the ObjectName value syntax,
333as described in the JMX specification.</td>
334</tr>
335<tr>
336<td class="confluenceTd">usesMOSGi</td>
337<td class="confluenceTd">NO</td>
338<td class="confluenceTd">Determines if the component must be register on the MOSGi MBean server or not.</td>
339</tr>
340<tr>
341<td class="confluenceTd">preRegister <br>
342postRegister <br>
343preDeregister<br>
344postDeregister</td>
345<td class="confluenceTd">NO</td>
346<td class="confluenceTd">These attributes allow to specify methods to
347carry out operations before and after being registered or unregistered
348from the MBean server.</td>
349</tr>
Clement Escoffier580d1902009-07-21 12:06:46 +0000350</tbody></table></div>
Clement Escoffier130ca572008-10-13 07:33:03 +0000351
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000352<h2><a name="iPOJOJMXHandler-Propertiesattributes"></a>Properties attributes</h2>
Clement Escoffier580d1902009-07-21 12:06:46 +0000353<div class="borderedTable"><table class="confluenceTable"><tbody>
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000354<tr>
355<th class="confluenceTh">Attribute name</th>
356<th class="confluenceTh">Required</th>
357<th class="confluenceTh">Description</th>
358</tr>
359<tr>
360<td class="confluenceTd">field</td>
361<td class="confluenceTd">YES</td>
362<td class="confluenceTd">The name of the component's field to expose.</td>
363</tr>
364<tr>
365<td class="confluenceTd">name</td>
366<td class="confluenceTd">NO</td>
367<td class="confluenceTd">The name of the property as it will appear in JMX. If unspecified, the default value is the name of the exposed field.</td>
368</tr>
369<tr>
370<td class="confluenceTd">rights</td>
371<td class="confluenceTd">NO</td>
372<td class="confluenceTd">Specify the access permission of the exposed field. The accepted values are :
373<ul>
374 <li>"r" : read-only access, the default value.</li>
375 <li>"w" : read and write access.</li>
376</ul>
377</td>
378</tr>
379<tr>
380<td class="confluenceTd">notification</td>
381<td class="confluenceTd">NO</td>
382<td class="confluenceTd">Enable or disable attribute change
383notification sending for this property. If set to "true", a
384notification is sent each time the value of the field changes.</td>
385</tr>
Clement Escoffier580d1902009-07-21 12:06:46 +0000386</tbody></table></div>
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000387<h2><a name="iPOJOJMXHandler-Methodsattributes"></a>Methods attributes</h2>
Clement Escoffier580d1902009-07-21 12:06:46 +0000388<div class="borderedTable"><table class="confluenceTable"><tbody>
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000389<tr>
390<th class="confluenceTh">Attribute name</th>
391<th class="confluenceTh">Required</th>
392<th class="confluenceTh">Description</th>
393</tr>
394<tr>
395<td class="confluenceTd">name</td>
396<td class="confluenceTd">YES</td>
397<td class="confluenceTd">The name of the method to expose. If multiple methods have the same name, all of them are exposed.</td>
398</tr>
399<tr>
400<td class="confluenceTd">description</td>
401<td class="confluenceTd">NO</td>
402<td class="confluenceTd">The description of the exposed method, as it will appear in JMX.</td>
403</tr>
Clement Escoffier580d1902009-07-21 12:06:46 +0000404</tbody></table></div>
Clement Escoffier130ca572008-10-13 07:33:03 +0000405
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000406<h2><a name="iPOJOJMXHandler-Examples"></a>Examples</h2>
Clement Escoffier130ca572008-10-13 07:33:03 +0000407
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000408<p>In this part, we will give you a complete example of a component managed with JMX, using the JConsole provided by the SUN JDK.</p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000409
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000410<h3><a name="iPOJOJMXHandler-ExposingAttributes"></a>Exposing Attributes</h3>
Clement Escoffier130ca572008-10-13 07:33:03 +0000411
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000412<p>In first time we create a simple component named MyComponent. We have add two fields named m_level (int) and m_message (String).</p>
Clement Escoffier580d1902009-07-21 12:06:46 +0000413<div class="code">
414<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span></span><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">class</span><span>&nbsp;</span></td></tr><tr><td class="line2">MyComponent&nbsp;...&nbsp;{&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;Exposed&nbsp;attributes</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;String&nbsp;m_message;&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;int&nbsp;m_level;&nbsp;</span></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">public class
Clement Escoffier130ca572008-10-13 07:33:03 +0000415MyComponent ... {
Clement Escoffier580d1902009-07-21 12:06:46 +0000416 // Exposed attributes
417 private String m_message;
418 private int m_level;
419}</textarea>
420<script class="javascript">
421 if(!window.newcodemacro_initialised)
422 {
423 window.newcodemacro_initialised = true;
424 window.oldonloadmethod = window.onload;
425 window.onload = function(){
426 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
427 if(window.oldonloadmethod)
428 {
429 window.oldonloadmethod();
430 }
431 }
432 }
433
434</script>
435</div>
436
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000437<p>We expose now the attributes in the jmx:config<br>
438tag in the metadata :</p>
Clement Escoffier580d1902009-07-21 12:06:46 +0000439<div class="code">
440<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>xml&nbsp;</span><span class="attribute">version</span><span>=</span><span class="attribute-value">"1.0"</span><span>&nbsp;</span><span class="attribute">encoding</span><span>=</span><span class="attribute-value">"UTF-8"</span><span>?&gt;&nbsp;</span></td></tr><tr><td class="line2"><span class="tag">&lt;</span><span>iPOJO&nbsp;xmlns:</span><span class="attribute">jmx</span><span>=</span><span class="attribute-value">"org.apache.felix.ipojo.handlers.jmx"</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>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">architecture</span><span>=</span><span class="attribute-value">"true"</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">immediate</span><span>=</span><span class="attribute-value">"true"</span><span>&gt;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>provides</span><span class="tag">/&gt;</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>jmx:config</span><span class="tag">&gt;</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comments">&lt;!--&nbsp;Exposed&nbsp;properties&nbsp;--&gt;</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>jmx:property&nbsp;</span><span class="attribute">field</span><span>=</span><span class="attribute-value">"m_level"</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">name</span><span>=</span><span class="attribute-value">"The&nbsp;level"</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">rights</span><span>=</span><span class="attribute-value">"r"</span><span>/&gt;&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;</span><span>jmx:property&nbsp;</span><span class="attribute">field</span><span>=</span><span class="attribute-value">"m_message"</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">name</span><span>=</span><span class="attribute-value">"The&nbsp;message"</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">rights</span><span>=</span><span class="attribute-value">"w"</span><span>/&gt;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">&lt;/</span><span>jmx:config</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>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></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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;?xml version="1.0" encoding="UTF-8"?&gt;
441&lt;iPOJO xmlns:jmx="org.apache.felix.ipojo.handlers.jmx"&gt;
442 &lt;component className="...MyComponent"
443 architecture="true"
444 immediate="true"&gt;
Clement Escoffier130ca572008-10-13 07:33:03 +0000445
Clement Escoffier580d1902009-07-21 12:06:46 +0000446 &lt;provides/&gt;
447 &lt;jmx:config&gt;
448 &lt;!-- Exposed properties --&gt;
449 &lt;jmx:property field="m_level"
450 name="The level"
451 rights="r"/&gt;
452 &lt;jmx:property field="m_message"
453 name="The message"
454 rights="w"/&gt;
455 &lt;/jmx:config&gt;
456 &lt;/component&gt;
Clement Escoffier130ca572008-10-13 07:33:03 +0000457 &lt;instance
Clement Escoffier580d1902009-07-21 12:06:46 +0000458 component="...MyComponent"/&gt;
459&lt;/iPOJO&gt;</textarea>
460<script class="javascript">
461 if(!window.newcodemacro_initialised)
462 {
463 window.newcodemacro_initialised = true;
464 window.oldonloadmethod = window.onload;
465 window.onload = function(){
466 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
467 if(window.oldonloadmethod)
468 {
469 window.oldonloadmethod();
470 }
471 }
472 }
473
474</script>
475</div>
476
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000477<p>Now, we could get and write the properties in the JConsole :<br>
Clement Escoffier580d1902009-07-21 12:06:46 +0000478<img src="ipojo-jmx-handler_files/JMXHandler_1.png" border="0" align="absmiddle"></p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000479
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000480<h3><a name="iPOJOJMXHandler-ExposingMethods"></a>Exposing Methods</h3>
Clement Escoffier130ca572008-10-13 07:33:03 +0000481
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000482<p>We could now add methods in the initial class :</p>
Clement Escoffier580d1902009-07-21 12:06:46 +0000483<div class="code">
484<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span></span><span class="comment">/**</span></td></tr><tr><td class="line2"><span class="comment">Do&nbsp;something&nbsp;good</span></td></tr><tr><td class="line1"><span class="comment">*/</span><span>&nbsp;</span></td></tr><tr><td class="line2"><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;doSomethingGood()&nbsp;{&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...&nbsp;</td></tr><tr><td class="line2">}&nbsp;</td></tr><tr><td class="line1">&nbsp;</td></tr><tr><td class="line2"><span class="comment">/**</span></td></tr><tr><td class="line1"><span class="comment">Do&nbsp;something&nbsp;bad</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">void</span><span>&nbsp;doSomethingBad()&nbsp;{&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...&nbsp;</td></tr><tr><td class="line1">}&nbsp;</td></tr><tr><td class="line2">&nbsp;</td></tr><tr><td class="line1"><span class="comment">/**</span></td></tr><tr><td class="line2"><span class="comment">Do&nbsp;nothing</span></td></tr><tr><td class="line1"><span class="comment">*/</span><span>&nbsp;</span></td></tr><tr><td class="line2"><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;doNothing()&nbsp;{&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&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">/**
Clement Escoffier130ca572008-10-13 07:33:03 +0000485Do something good
486*/
Clement Escoffier580d1902009-07-21 12:06:46 +0000487public void doSomethingGood() {
Clement Escoffier130ca572008-10-13 07:33:03 +0000488 ...
489}
490
491/**
492Do something bad
493*/
Clement Escoffier580d1902009-07-21 12:06:46 +0000494public void doSomethingBad() {
Clement Escoffier130ca572008-10-13 07:33:03 +0000495 ...
496}
497
498/**
499Do nothing
500*/
Clement Escoffier580d1902009-07-21 12:06:46 +0000501public void doNothing() {
Clement Escoffier130ca572008-10-13 07:33:03 +0000502 ...
Clement Escoffier580d1902009-07-21 12:06:46 +0000503}</textarea>
504<script class="javascript">
505 if(!window.newcodemacro_initialised)
506 {
507 window.newcodemacro_initialised = true;
508 window.oldonloadmethod = window.onload;
509 window.onload = function(){
510 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
511 if(window.oldonloadmethod)
512 {
513 window.oldonloadmethod();
514 }
515 }
516 }
517
518</script>
519</div>
520
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000521<p>We add corresponding tags in the metadata to expose these methods:</p>
Clement Escoffier580d1902009-07-21 12:06:46 +0000522<div class="code">
523<div class="dp-highlighter"><table class="dp-xml" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span></span><span class="comments">&lt;!--&nbsp;Exposed&nbsp;methods&nbsp;--&gt;</span><span>&nbsp;</span></td></tr><tr><td class="line2"><span class="tag">&lt;</span><span>jmx:method&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">"doSomethingGood"</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">description</span><span>=</span><span class="attribute-value">"Do&nbsp;something&nbsp;good."</span><span>/&gt;&nbsp;</span></td></tr><tr><td class="line2"><span class="tag">&lt;</span><span>jmx:method&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">"doSomethingBad"</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">description</span><span>=</span><span class="attribute-value">"Do&nbsp;something&nbsp;bad."</span><span>/&gt;&nbsp;</span></td></tr><tr><td class="line2"><span class="tag">&lt;</span><span>jmx:method&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">"doNothing"</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">description</span><span>=</span><span class="attribute-value">"Do&nbsp;absolutely&nbsp;nothing."</span><span>/&gt;&nbsp;</span></td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly">&lt;!-- Exposed methods --&gt;
524&lt;jmx:method name="doSomethingGood"
525 description="Do something good."/&gt;
526&lt;jmx:method name="doSomethingBad"
527 description="Do something bad."/&gt;
528&lt;jmx:method name="doNothing"
529 description="Do absolutely nothing."/&gt;</textarea>
530<script class="javascript">
531 if(!window.newcodemacro_initialised)
532 {
533 window.newcodemacro_initialised = true;
534 window.oldonloadmethod = window.onload;
535 window.onload = function(){
536 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
537 if(window.oldonloadmethod)
538 {
539 window.oldonloadmethod();
540 }
541 }
542 }
543
544</script>
545</div>
546
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000547<p>Now the three methods are exposed in the operations tab of the JConsole. We can invoked these methods :</p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000548
Clement Escoffier580d1902009-07-21 12:06:46 +0000549<p><img src="ipojo-jmx-handler_files/JMXHandler_2.png" border="0" align="absmiddle"></p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000550
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000551<h3><a name="iPOJOJMXHandler-AttributeNotifications:"></a>Attribute Notifications:</h3>
Clement Escoffier130ca572008-10-13 07:33:03 +0000552
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000553<p>You could subscribe to attribute notification by adding the
554notification attribute in property tag. In our example if we want to be
555notified when m_level is modified, we change the property line in the
556metatada like this:</p>
Clement Escoffier580d1902009-07-21 12:06:46 +0000557<div class="code">
558<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>jmx:property&nbsp;</span><span class="attribute">field</span><span>=</span><span class="attribute-value">"m_level"</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">name</span><span>=</span><span class="attribute-value">"The&nbsp;level"</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">rights</span><span>=</span><span class="attribute-value">"r"</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">notification</span><span>=</span><span class="attribute-value">"true"</span><span>/&gt;&nbsp;</span></td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly">&lt;jmx:property field="m_level"
559 name="The level"
560 rights="r"
561 notification="true"/&gt;</textarea>
562<script class="javascript">
563 if(!window.newcodemacro_initialised)
564 {
565 window.newcodemacro_initialised = true;
566 window.oldonloadmethod = window.onload;
567 window.onload = function(){
568 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
569 if(window.oldonloadmethod)
570 {
571 window.oldonloadmethod();
572 }
573 }
574 }
575
576</script>
577</div>
578
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000579<p>So now if we change the string through JConsole or if the POJO is
580modified in other way, a notification will be sent to every listener.
581For example, we subscribe in the notification tab, and we get
582notification when the message changes :</p>
Clement Escoffier130ca572008-10-13 07:33:03 +0000583
Clement Escoffier580d1902009-07-21 12:06:46 +0000584<p><img src="ipojo-jmx-handler_files/JMXHandler_3.png" border="0" align="absmiddle"></p>
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000585
Clement Escoffier580d1902009-07-21 12:06:46 +0000586<h2><a name="iPOJOJMXHandler-Configuringthehandlerwithannotations"></a>Configuring the handler with annotations</h2>
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000587
Clement Escoffier580d1902009-07-21 12:06:46 +0000588<p>It is possible to configure the handler with simple annotations available with iPOJO annotations. Here is an example of usage:</p>
589<div class="code">
590<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.jmx.Config;&nbsp;</span></td></tr><tr><td class="line1"><span class="keyword">import</span><span>&nbsp;org.apache.felix.ipojo.handlers.jmx.Method;&nbsp;</span></td></tr><tr><td class="line2"><span class="keyword">import</span><span>&nbsp;org.apache.felix.ipojo.handlers.jmx.Property;&nbsp;</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="preprocessor">@Config(domain="my-domain",&nbsp;usesMOSGi=false)</span><span>&nbsp;</span></td></tr><tr><td class="line2"><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">class</span><span>&nbsp;JMXSimple&nbsp;{&nbsp;</span></td></tr><tr><td class="line1"><span class="preprocessor"></span></td></tr><tr><td class="line2"><span class="preprocessor">&nbsp;&nbsp;&nbsp;&nbsp;@Property(name="prop",&nbsp;notification=true,&nbsp;rights="w")&nbsp;//&nbsp;Field&nbsp;published&nbsp;in&nbsp;the&nbsp;MBean</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;m_foo;&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;@Method(description="set&nbsp;the&nbsp;foo&nbsp;prop")&nbsp;//&nbsp;Method&nbsp;published&nbsp;in&nbsp;the&nbsp;MBean</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;setFoo(String&nbsp;mes)&nbsp;{&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<span class="string">"Set&nbsp;foo&nbsp;to&nbsp;"</span><span>&nbsp;+&nbsp;mes);&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_foo&nbsp;=&nbsp;mes;&nbsp;</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;@Method(description="get&nbsp;the&nbsp;foo&nbsp;prop")&nbsp;//&nbsp;Method&nbsp;published&nbsp;in&nbsp;the&nbsp;MBean</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;String&nbsp;getFoo()&nbsp;{&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">return</span><span>&nbsp;m_foo;&nbsp;</span></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.annotations.Component;
591import org.apache.felix.ipojo.handlers.jmx.Config;
592import org.apache.felix.ipojo.handlers.jmx.Method;
593import org.apache.felix.ipojo.handlers.jmx.Property;
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000594
595@Component
Clement Escoffier580d1902009-07-21 12:06:46 +0000596@Config(domain="my-domain", usesMOSGi=false)
597public class JMXSimple {
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000598
Clement Escoffier580d1902009-07-21 12:06:46 +0000599 @Property(name="prop", notification=true, rights="w") // Field published in the MBean
600 String m_foo;
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000601
Clement Escoffier580d1902009-07-21 12:06:46 +0000602 @Method(description="set the foo prop") // Method published in the MBean
603 public void setFoo(String mes) {
604 System.out.println("Set foo to " + mes);
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000605 m_foo = mes;
606 }
607
Clement Escoffier580d1902009-07-21 12:06:46 +0000608 @Method(description="get the foo prop") // Method published in the MBean
609 public String getFoo() {
610 return m_foo;
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000611 }
Clement Escoffier580d1902009-07-21 12:06:46 +0000612}</textarea>
613<script class="javascript">
614 if(!window.newcodemacro_initialised)
615 {
616 window.newcodemacro_initialised = true;
617 window.oldonloadmethod = window.onload;
618 window.onload = function(){
619 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
620 if(window.oldonloadmethod)
621 {
622 window.oldonloadmethod();
623 }
624 }
625 }
626
627</script>
628</div>
629
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000630<p>The <tt>@org.apache.felix.ipojo.handlers.jmx.Config</tt> (<tt>@Config</tt> if the package it correctly imported) annotation is a type annotation (so placed on the <tt>class</tt> element. This annotation indicates that the instance will be exposed as an MBean. This annotation supports:</p>
631<ul>
632 <li>usesMOSGi: set to <tt>true</tt> to use MOSGi. Otherwise, the MBean will be exposed in the MBean Platform Server (default: <tt>false</tt>).</li>
633 <li>objectname: set the MBean objectname. The objectname must follow JMX specification. (default: <tt>package-name:factory-name:instance-name</tt>)</li>
634 <li>domain: set the MBean domain. (default: <tt>package-name</tt>)</li>
635 <li>name: set the MBean name. (default: <tt>instance-name</tt>).</li>
636</ul>
Clement Escoffier130ca572008-10-13 07:33:03 +0000637
638
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000639<p>The <tt>@org.apache.felix.ipojo.handlers.jmx.Property</tt> (<tt>@Property</tt>) annotation is a field annotation indicating that the field is exposed in the MBean. The supported attributes are:</p>
640<ul>
641 <li>name: set the property name</li>
642 <li>rights: set the access permission. Possible values are <tt>r</tt> (read only) and <tt>w</tt> (read and write). By default, properties are in read-only mode.</li>
643 <li>notification: enables notification on this property. By default notifications are disabled.</li>
644</ul>
Clement Escoffier130ca572008-10-13 07:33:03 +0000645
646
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000647<p>The <tt>@org.apache.felix.ipojo.handlers.jmx.Method</tt> (<tt>@Method</tt>) annotation is a method annotation indicating that the method is exposed in the MBean. Only one attribute can be customized:</p>
648<ul>
Clement Escoffier580d1902009-07-21 12:06:46 +0000649 <li>description: set the method description.
650<br clear="all">
651<br clear="all">
Clement Escoffier130ca572008-10-13 07:33:03 +0000652
Clement Escoffier580d1902009-07-21 12:06:46 +0000653 </li></ul></div>
654 <img src="ipojo-jmx-handler_files/footer.png" class="footer">
655</div>
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000656
657<script type="text/javascript">
658var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
659document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
660</script><script src="ipojo-jmx-handler_files/ga.js" type="text/javascript"></script>
661<script type="text/javascript">
Clement Escoffier580d1902009-07-21 12:06:46 +0000662try{
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000663var pageTracker = _gat._getTracker("UA-1518442-4");
664pageTracker._trackPageview();
Clement Escoffier580d1902009-07-21 12:06:46 +0000665} catch(err) {}
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000666</script>
Clement Escoffier580d1902009-07-21 12:06:46 +0000667
668
669
Clement Escoffier3e0db1e2009-01-15 15:35:17 +0000670 </div>
671 </body></html>