Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 2 | <html><head> |
| 3 | |
| 4 | |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 5 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 6 | <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> |
| 15 | <li><span class="nobr"><a href="http://felix.apache.org/site/downloads.cgi" title="Visit page outside Confluence" rel="nofollow">downloads<sup><img class="rendericon" src="ipojo-jmx-handler_files/linkext7.gif" alt="" align="absmiddle" border="0" width="7" height="7"></sup></a></span></li> |
| 16 | <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> |
| 19 | <li><span class="nobr"><a href="http://www.apache.org/" title="Visit page outside Confluence" rel="nofollow">asf<sup><img class="rendericon" src="ipojo-jmx-handler_files/linkext7.gif" alt="" align="absmiddle" border="0" width="7" height="7"></sup></a></span></li> |
| 20 | <li><span class="nobr"><a href="http://www.apache.org/foundation/sponsorship.html" title="Visit page outside Confluence" rel="nofollow">sponsorship<sup><img class="rendericon" src="ipojo-jmx-handler_files/linkext7.gif" alt="" align="absmiddle" border="0" width="7" height="7"></sup></a></span></li> |
| 21 | <li><span class="nobr"><a href="http://www.apache.org/foundation/thanks.html" title="Visit page outside Confluence" rel="nofollow">sponsors<sup><img class="rendericon" src="ipojo-jmx-handler_files/linkext7.gif" alt="" align="absmiddle" border="0" width="7" height="7"></sup></a></span> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 22 | <!-- ApacheCon Ad --> |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 23 | <iframe src="ipojo-jmx-handler_files/button.html" style="border-width: 0pt; float: left;" scrolling="no" width="135" frameborder="0" height="135"></iframe> |
| 24 | <p style="height: 100px;"> |
| 25 | <!-- ApacheCon Ad --> |
| 26 | </p></li></ul> </div> |
| 27 | <div class="main"> |
| 28 | <table class="sectionMacro" border="0" cellpadding="5" cellspacing="0" width="100%"><tbody><tr> |
| 29 | <td class="confluenceTd" valign="top" width="80%"> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 30 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 31 | <h1><a name="iPOJOJMXHandler-iPOJOJMXHandler"></a>iPOJO JMX Handler</h1> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 32 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 33 | <p>This handler provides JMX management of component instance. It could |
| 34 | be useful to manage instance remotely. As the handler exposes MBeans, |
| 35 | you must have a MBean server running on your platform (as the platform |
| 36 | MBean server or the MOSGi MBean Server).</p> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 37 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 38 | <h2><a name="iPOJOJMXHandler-Features"></a>Features</h2> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 39 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 40 | <p>The handler allows to:</p> |
| 41 | <ul> |
| 42 | <li>Expose attributes accessible via JMX (with rights management).</li> |
| 43 | <li>Expose methods to be called through JMX.</li> |
| 44 | <li>Get notifications when attributes are modified .</li> |
| 45 | </ul> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 46 | |
| 47 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 48 | <h2><a name="iPOJOJMXHandler-Prerequisites"></a>Prerequisites</h2> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 49 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 50 | <p>To be functional this handler must register on an MBean Server,thus |
| 51 | you obviously need it. Several servers are currently supported : the |
| 52 | standard platform MBean server (included in the JDK), MOSGi (provided |
| 53 | with Felix), ...<br> |
| 54 | To use MOSGi, you have to deploy at least the following three bundles of MOSGi:</p> |
| 55 | <ul> |
| 56 | <li>org.apache.felix.mosgi.jmx.agent</li> |
| 57 | <li>org.apache.felix.mosgi.jmx.registry</li> |
| 58 | <li>org.apache.felix.mosgi.jmx.rmiconnector</li> |
| 59 | </ul> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 60 | |
| 61 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 62 | <p>You can find MOSGi documentation on <span class="nobr"><a href="http://cwiki.apache.org/FELIX/mosgi-managed-osgi-framework.html" title="Visit page outside Confluence" rel="nofollow">http://cwiki.apache.org/FELIX/mosgi-managed-osgi-framework.html<sup><img class="rendericon" src="ipojo-jmx-handler_files/linkext7.gif" alt="" align="absmiddle" border="0" width="7" height="7"></sup></a></span></p> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 63 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 64 | <h2><a name="iPOJOJMXHandler-Download"></a>Download</h2> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 65 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 66 | <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 Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 67 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 68 | <h2><a name="iPOJOJMXHandler-Howtouseit"></a>How to use it</h2> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 69 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 70 | <p>The handler needs to be added in the metadata.xml, you just add a namespace (e.g., jmx) :</p> |
| 71 | <div class="code"><div class="codeContent"> |
| 72 | <pre class="code-xml"><span class="code-tag"><ipojo <span class="code-keyword">xmlns:jmx</span>=<span class="code-quote">"org.apache.felix.ipojo.handlers.jmx"</span>></span> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 73 | ... |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 74 | <span class="code-tag"></ipojo></span></pre> |
| 75 | </div></div> |
| 76 | <p>So, you could now expose in JMX properties and methods of your component. They are surrounded by the <jmx:config><br> |
| 77 | tag.</p> |
| 78 | <div class="code"><div class="codeContent"> |
| 79 | <pre class="code-xml"><span class="code-tag"><jmx:config></span> |
| 80 | <span class="code-tag"><jmx:property name=<span class="code-quote">"message"</span> field=<span class="code-quote">"m_msg"</span> rights=<span class="code-quote">"w"</span> notification=<span class="code-quote">"true"</span>/></span> |
| 81 | <span class="code-tag"><jmx:method name=<span class="code-quote">"doSomethingBad"</span>/></span> |
| 82 | <span class="code-tag"><jmx:method name=<span class="code-quote">"doSomethingGood"</span>/></span> |
| 83 | <span class="code-tag"></jmx:config></span></pre> |
| 84 | </div></div> |
| 85 | <p><em>Note:</em> Be careful that the argument and return type of |
| 86 | methods must be serializable. In case of several methods have the same |
| 87 | name, each of them will be exposed.</p> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 88 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 89 | <h2><a name="iPOJOJMXHandler-JMXHandleroptions"></a>JMX Handler options</h2> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 90 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 91 | <p>Here you can find all configuration options of the JMX handler. |
| 92 | There are two kinds of manageable elements : properties and methods. |
| 93 | First is described the global configuration of the handler. Then |
| 94 | elements can be configured, using several attributes, as described |
| 95 | below.</p> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 96 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 97 | <h2><a name="iPOJOJMXHandler-Globalhandlerattributes"></a>Global handler attributes</h2> |
| 98 | <table class="confluenceTable"><tbody> |
| 99 | <tr> |
| 100 | <th class="confluenceTh">Attribute name </th> |
| 101 | <th class="confluenceTh"> Required </th> |
| 102 | <th class="confluenceTh"> Description</th> |
| 103 | </tr> |
| 104 | <tr> |
| 105 | <td class="confluenceTd">objectName</td> |
| 106 | <td class="confluenceTd">NO</td> |
| 107 | <td class="confluenceTd">The complete object name of the managed |
| 108 | component. The syntax of this attribute must be compliant with the |
| 109 | ObjectName syntax, detailed in the JMX specification.<br> |
| 110 | If neither domain nor name attributes are specified, the default value |
| 111 | is determined by the package, the type and the instance name of the |
| 112 | component. This attribute overrides the domain and name attributes.<br> |
| 113 | <em>Example:</em> "my.domain:type=myType,name=myName"</td> |
| 114 | </tr> |
| 115 | <tr> |
| 116 | <td class="confluenceTd">domain</td> |
| 117 | <td class="confluenceTd">NO</td> |
| 118 | <td class="confluenceTd">The domain of the managed object (i.e., the |
| 119 | left part of the object name). This attribute must be compliant with |
| 120 | the domain syntax, as described in the JMX specification.<br> |
| 121 | <em>Example:</em> "my.domain"</td> |
| 122 | </tr> |
| 123 | <tr> |
| 124 | <td class="confluenceTd">name</td> |
| 125 | <td class="confluenceTd">NO</td> |
| 126 | <td class="confluenceTd">The name property of the managed object. The |
| 127 | value of this attribute must comply with the ObjectName value syntax, |
| 128 | as described in the JMX specification.</td> |
| 129 | </tr> |
| 130 | <tr> |
| 131 | <td class="confluenceTd">usesMOSGi</td> |
| 132 | <td class="confluenceTd">NO</td> |
| 133 | <td class="confluenceTd">Determines if the component must be register on the MOSGi MBean server or not.</td> |
| 134 | </tr> |
| 135 | <tr> |
| 136 | <td class="confluenceTd">preRegister <br> |
| 137 | postRegister <br> |
| 138 | preDeregister<br> |
| 139 | postDeregister</td> |
| 140 | <td class="confluenceTd">NO</td> |
| 141 | <td class="confluenceTd">These attributes allow to specify methods to |
| 142 | carry out operations before and after being registered or unregistered |
| 143 | from the MBean server.</td> |
| 144 | </tr> |
| 145 | </tbody></table> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 146 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 147 | <h2><a name="iPOJOJMXHandler-Propertiesattributes"></a>Properties attributes</h2> |
| 148 | <table class="confluenceTable"><tbody> |
| 149 | <tr> |
| 150 | <th class="confluenceTh">Attribute name</th> |
| 151 | <th class="confluenceTh">Required</th> |
| 152 | <th class="confluenceTh">Description</th> |
| 153 | </tr> |
| 154 | <tr> |
| 155 | <td class="confluenceTd">field</td> |
| 156 | <td class="confluenceTd">YES</td> |
| 157 | <td class="confluenceTd">The name of the component's field to expose.</td> |
| 158 | </tr> |
| 159 | <tr> |
| 160 | <td class="confluenceTd">name</td> |
| 161 | <td class="confluenceTd">NO</td> |
| 162 | <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> |
| 163 | </tr> |
| 164 | <tr> |
| 165 | <td class="confluenceTd">rights</td> |
| 166 | <td class="confluenceTd">NO</td> |
| 167 | <td class="confluenceTd">Specify the access permission of the exposed field. The accepted values are : |
| 168 | <ul> |
| 169 | <li>"r" : read-only access, the default value.</li> |
| 170 | <li>"w" : read and write access.</li> |
| 171 | </ul> |
| 172 | </td> |
| 173 | </tr> |
| 174 | <tr> |
| 175 | <td class="confluenceTd">notification</td> |
| 176 | <td class="confluenceTd">NO</td> |
| 177 | <td class="confluenceTd">Enable or disable attribute change |
| 178 | notification sending for this property. If set to "true", a |
| 179 | notification is sent each time the value of the field changes.</td> |
| 180 | </tr> |
| 181 | </tbody></table> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 182 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 183 | <h2><a name="iPOJOJMXHandler-Methodsattributes"></a>Methods attributes</h2> |
| 184 | <table class="confluenceTable"><tbody> |
| 185 | <tr> |
| 186 | <th class="confluenceTh">Attribute name</th> |
| 187 | <th class="confluenceTh">Required</th> |
| 188 | <th class="confluenceTh">Description</th> |
| 189 | </tr> |
| 190 | <tr> |
| 191 | <td class="confluenceTd">name</td> |
| 192 | <td class="confluenceTd">YES</td> |
| 193 | <td class="confluenceTd">The name of the method to expose. If multiple methods have the same name, all of them are exposed.</td> |
| 194 | </tr> |
| 195 | <tr> |
| 196 | <td class="confluenceTd">description</td> |
| 197 | <td class="confluenceTd">NO</td> |
| 198 | <td class="confluenceTd">The description of the exposed method, as it will appear in JMX.</td> |
| 199 | </tr> |
| 200 | </tbody></table> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 201 | |
| 202 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 203 | <h2><a name="iPOJOJMXHandler-Examples"></a>Examples</h2> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 204 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 205 | <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 Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 206 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 207 | <h3><a name="iPOJOJMXHandler-ExposingAttributes"></a>Exposing Attributes</h3> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 208 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 209 | <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> |
| 210 | <div class="code"><div class="codeContent"> |
| 211 | <pre class="code-java"><span class="code-keyword">public</span> class |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 212 | MyComponent ... { |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 213 | <span class="code-comment">// Exposed attributes |
| 214 | </span> <span class="code-keyword">private</span> <span class="code-object">String</span> m_message; |
| 215 | <span class="code-keyword">private</span> <span class="code-object">int</span> m_level; |
| 216 | }</pre> |
| 217 | </div></div> |
| 218 | <p>We expose now the attributes in the jmx:config<br> |
| 219 | tag in the metadata :</p> |
| 220 | <div class="code"><div class="codeContent"> |
| 221 | <pre class="code-xml"><span class="code-tag"><?xml version=<span class="code-quote">"1.0"</span> encoding=<span class="code-quote">"UTF-8"</span>?></span> |
| 222 | <span class="code-tag"><iPOJO <span class="code-keyword">xmlns:jmx</span>=<span class="code-quote">"org.apache.felix.ipojo.handlers.jmx"</span>></span> |
| 223 | <component className=<span class="code-quote">"...MyComponent"</span> |
| 224 | architecture=<span class="code-quote">"true"</span> |
| 225 | immediate=<span class="code-quote">"true"</span>> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 226 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 227 | <span class="code-tag"><provides/></span> |
| 228 | <span class="code-tag"><jmx:config></span> |
| 229 | <span class="code-tag"><span class="code-comment"><!-- Exposed properties --></span></span> |
| 230 | <jmx:property field=<span class="code-quote">"m_level"</span> |
| 231 | name=<span class="code-quote">"The level"</span> |
| 232 | rights=<span class="code-quote">"r"</span>/> |
| 233 | <jmx:property field=<span class="code-quote">"m_message"</span> |
| 234 | name=<span class="code-quote">"The message"</span> |
| 235 | rights=<span class="code-quote">"w"</span>/> |
| 236 | <span class="code-tag"></jmx:config></span> |
| 237 | <span class="code-tag"></component></span> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 238 | <instance |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 239 | component=<span class="code-quote">"...MyComponent"</span>/> |
| 240 | <span class="code-tag"></iPOJO></span></pre> |
| 241 | </div></div> |
| 242 | <p>Now, we could get and write the properties in the JConsole :<br> |
| 243 | <img src="ipojo-jmx-handler_files/JMXHandler_1.png" align="absmiddle" border="0"></p> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 244 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 245 | <h3><a name="iPOJOJMXHandler-ExposingMethods"></a>Exposing Methods</h3> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 246 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 247 | <p>We could now add methods in the initial class :</p> |
| 248 | <div class="code"><div class="codeContent"> |
| 249 | <pre class="code-java">/** |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 250 | Do something good |
| 251 | */ |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 252 | <span class="code-keyword">public</span> void doSomethingGood() { |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 253 | ... |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | Do something bad |
| 258 | */ |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 259 | <span class="code-keyword">public</span> void doSomethingBad() { |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 260 | ... |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | Do nothing |
| 265 | */ |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 266 | <span class="code-keyword">public</span> void doNothing() { |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 267 | ... |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 268 | }</pre> |
| 269 | </div></div> |
| 270 | <p>We add corresponding tags in the metadata to expose these methods:</p> |
| 271 | <div class="code"><div class="codeContent"> |
| 272 | <pre class="code-xml"><span class="code-tag"><span class="code-comment"><!-- Exposed methods --></span></span> |
| 273 | <jmx:method name=<span class="code-quote">"doSomethingGood"</span> |
| 274 | description=<span class="code-quote">"Do something good."</span>/> |
| 275 | <jmx:method name=<span class="code-quote">"doSomethingBad"</span> |
| 276 | description=<span class="code-quote">"Do something bad."</span>/> |
| 277 | <jmx:method name=<span class="code-quote">"doNothing"</span> |
| 278 | description=<span class="code-quote">"Do absolutely nothing."</span>/></pre> |
| 279 | </div></div> |
| 280 | <p>Now the three methods are exposed in the operations tab of the JConsole. We can invoked these methods :</p> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 281 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 282 | <p><img src="ipojo-jmx-handler_files/JMXHandler_2.png" align="absmiddle" border="0"></p> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 283 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 284 | <h3><a name="iPOJOJMXHandler-AttributeNotifications:"></a>Attribute Notifications:</h3> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 285 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 286 | <p>You could subscribe to attribute notification by adding the |
| 287 | notification attribute in property tag. In our example if we want to be |
| 288 | notified when m_level is modified, we change the property line in the |
| 289 | metatada like this:</p> |
| 290 | <div class="code"><div class="codeContent"> |
| 291 | <pre class="code-xml"><jmx:property field=<span class="code-quote">"m_level"</span> |
| 292 | name=<span class="code-quote">"The level"</span> |
| 293 | rights=<span class="code-quote">"r"</span> |
| 294 | notification=<span class="code-quote">"true"</span>/></pre> |
| 295 | </div></div> |
| 296 | <p>So now if we change the string through JConsole or if the POJO is |
| 297 | modified in other way, a notification will be sent to every listener. |
| 298 | For example, we subscribe in the notification tab, and we get |
| 299 | notification when the message changes :</p> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 300 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 301 | <p><img src="ipojo-jmx-handler_files/JMXHandler_3.png" align="absmiddle" border="0"></p> |
| 302 | |
| 303 | <h2><a name="iPOJOJMXHandler-Configuringthehandlerwithannotations\Newin1.1.0SNAPSHOT\"></a>Configuring the handler with annotations [New in 1.1.0-SNAPSHOT]</h2> |
| 304 | |
| 305 | <p>It is possible to configure the handler with simple annotations |
| 306 | available in the annotation pack ('annotation' project in the iPOJO |
| 307 | trunk). Here is an example of usage:</p> |
| 308 | <div class="code"><div class="codeContent"> |
| 309 | <pre class="code-java"><span class="code-keyword">import</span> org.apache.felix.ipojo.annotations.Component; |
| 310 | <span class="code-keyword">import</span> org.apache.felix.ipojo.handlers.jmx.Config; |
| 311 | <span class="code-keyword">import</span> org.apache.felix.ipojo.handlers.jmx.Method; |
| 312 | <span class="code-keyword">import</span> org.apache.felix.ipojo.handlers.jmx.Property; |
| 313 | |
| 314 | @Component |
| 315 | @Config(domain=<span class="code-quote">"my-domain"</span>, usesMOSGi=<span class="code-keyword">false</span>) |
| 316 | <span class="code-keyword">public</span> class JMXSimple { |
| 317 | |
| 318 | @Property(name=<span class="code-quote">"prop"</span>, notification=<span class="code-keyword">true</span>, rights=<span class="code-quote">"w"</span>) <span class="code-comment">// Field published in the MBean |
| 319 | </span> <span class="code-object">String</span> m_foo; |
| 320 | |
| 321 | @Method(description=<span class="code-quote">"set the foo prop"</span>) <span class="code-comment">// Method published in the MBean |
| 322 | </span> <span class="code-keyword">public</span> void setFoo(<span class="code-object">String</span> mes) { |
| 323 | <span class="code-object">System</span>.out.println(<span class="code-quote">"Set foo to "</span> + mes); |
| 324 | m_foo = mes; |
| 325 | } |
| 326 | |
| 327 | @Method(description=<span class="code-quote">"get the foo prop"</span>) <span class="code-comment">// Method published in the MBean |
| 328 | </span> <span class="code-keyword">public</span> <span class="code-object">String</span> getFoo() { |
| 329 | <span class="code-keyword">return</span> m_foo; |
| 330 | } |
| 331 | }</pre> |
| 332 | </div></div> |
| 333 | <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> |
| 334 | <ul> |
| 335 | <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> |
| 336 | <li>objectname: set the MBean objectname. The objectname must follow JMX specification. (default: <tt>package-name:factory-name:instance-name</tt>)</li> |
| 337 | <li>domain: set the MBean domain. (default: <tt>package-name</tt>)</li> |
| 338 | <li>name: set the MBean name. (default: <tt>instance-name</tt>).</li> |
| 339 | </ul> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 340 | |
| 341 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 342 | <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> |
| 343 | <ul> |
| 344 | <li>name: set the property name</li> |
| 345 | <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> |
| 346 | <li>notification: enables notification on this property. By default notifications are disabled.</li> |
| 347 | </ul> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 348 | |
| 349 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 350 | <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> |
| 351 | <ul> |
| 352 | <li>description: set the method description.</li> |
| 353 | </ul> |
| 354 | </td> |
| 355 | <td class="confluenceTd" valign="top" width="20%"> |
| 356 | <h6><a name="iPOJOJMXHandler-Overview"></a><b>Overview</b></h6> |
| 357 | <ul> |
| 358 | <li><a href="http://felix.apache.org/site/apache-felix-ipojo.html" title="Apache Felix iPOJO">Home Page</a></li> |
| 359 | <li><a href="http://felix.apache.org/site/apache-felix-ipojo-feature-overview.html" title="Apache Felix iPOJO Feature Overview">iPOJO Feature Overview</a></li> |
| 360 | <li><a href="http://felix.apache.org/site/download.html" title="Download">Download & Install </a></li> |
| 361 | </ul> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 362 | |
| 363 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 364 | <h6><a name="iPOJOJMXHandler-GettingStarted"></a><b>Getting Started</b></h6> |
| 365 | <ul> |
| 366 | <li><a href="http://felix.apache.org/site/ipojo-in-10-minutes.html" title="iPOJO in 10 minutes">iPOJO in 10 minutes</a></li> |
| 367 | <li><a href="http://felix.apache.org/site/how-to-use-ipojo-annotations.html" title="How to use iPOJO Annotations">How to use iPOJO Annotations</a></li> |
| 368 | <li><a href="http://felix.apache.org/site/ipojo-hello-word-maven-based-tutorial.html" title="iPOJO Hello Word (Maven-Based) tutorial">iPOJO Hello Word (Maven-Based) tutorial</a></li> |
| 369 | <li><a href="http://felix.apache.org/site/ipojo-advanced-tutorial.html" title="iPOJO Advanced Tutorial">iPOJO Advanced Tutorial</a></li> |
| 370 | <li><a href="http://felix.apache.org/site/ipojo-composition-tutorial.html" title="iPOJO Composition Tutorial">iPOJO Composition Tutorial</a></li> |
| 371 | </ul> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 372 | |
| 373 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 374 | <h6><a name="iPOJOJMXHandler-UserGuide"></a><b>User Guide</b></h6> |
| 375 | <ul> |
| 376 | <li><a href="http://felix.apache.org/site/describing-components.html" title="Describing components">Describing components (handler list) </a></li> |
| 377 | <li><a href="http://felix.apache.org/site/using-xml-schemas.html" title="Using XML Schemas">Using XML Schemas</a></li> |
| 378 | <li><a href="http://felix.apache.org/site/apache-felix-ipojo-testing-components.html" title="apache-felix-ipojo-testing-components">Testing components</a></li> |
| 379 | <li><a href="http://felix.apache.org/site/ipojo-advanced-topics.html" title="iPOJO Advanced Topics">Advanced Topics</a></li> |
| 380 | <li><a href="http://felix.apache.org/site/ipojo-faq.html" title="iPOJO FAQ">FAQ</a></li> |
| 381 | </ul> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 382 | |
| 383 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 384 | <h6><a name="iPOJOJMXHandler-Tools"></a><b>Tools</b></h6> |
| 385 | <ul> |
| 386 | <li><a href="http://felix.apache.org/site/ipojo-eclipse-plug-in.html" title="iPOJO Eclipse Plug-in">iPOJO Eclipse Plug-in</a></li> |
| 387 | <li><a href="http://felix.apache.org/site/ipojo-ant-task.html" title="iPOJO Ant Task">iPOJO Ant Task</a></li> |
| 388 | <li><a href="http://felix.apache.org/site/ipojo-maven-plug-in.html" title="iPOJO Maven Plug-in">iPOJO Maven Plug-in</a></li> |
| 389 | <li><a href="http://felix.apache.org/site/apache-felix-ipojo-junit4osgi.html" title="apache-felix-ipojo-junit4osgi">Junit4OSGi</a></li> |
| 390 | <li><a href="http://felix.apache.org/site/ipojo-concepts-overview.html" title="iPOJO Concepts Overview">iPOJO concepts overview</a></li> |
| 391 | </ul> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 392 | |
| 393 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 394 | <h6><a name="iPOJOJMXHandler-DeveloperGuide"></a><b>Developer Guide</b></h6> |
| 395 | <ul> |
| 396 | <li>API: <span class="nobr"><a href="http://people.apache.org/%7Eclement/ipojo/api/1.0/" title="Visit page outside Confluence" rel="nofollow">1.0<sup><img class="rendericon" src="ipojo-jmx-handler_files/linkext7.gif" alt="" align="absmiddle" border="0" width="7" height="7"></sup></a></span></li> |
| 397 | <li><a href="http://felix.apache.org/site/how-to-write-your-own-handler.html" title="How to write your own handler">How to write your own handler</a></li> |
| 398 | <li><a href="http://felix.apache.org/site/how-to-use-ipojo-manipulation-metadata.html" title="How to use iPOJO Manipulation Metadata">How to use iPOJO Manipulation Metadata</a></li> |
| 399 | <li><a 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> |
| 400 | </ul> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 401 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 402 | |
| 403 | <h6><a name="iPOJOJMXHandler-Misc&Contact"></a><b>Misc & Contact</b></h6> |
| 404 | <ul> |
| 405 | <li><a href="http://felix.apache.org/site/apache-felix-ipojo-issuestracker.html" title="apache-felix-ipojo-issuestracker">Issues Tracker</a></li> |
| 406 | <li><a href="http://felix.apache.org/site/apache-felix-ipojo-supportedvms.html" title="apache-felix-ipojo-supportedVMs">Supported JVMs</a></li> |
| 407 | <li><a href="http://felix.apache.org/site/apache-felix-ipojo-supportedosgi.html" title="apache-felix-ipojo-supportedOSGi">Supported OSGi Implementations</a></li> |
| 408 | <li><span class="nobr"><a href="http://ipojo-dark-side.blogspot.com/" title="Visit page outside Confluence" rel="nofollow">iPOJO's Dark Side Blog<sup><img class="rendericon" src="ipojo-jmx-handler_files/linkext7.gif" alt="" align="absmiddle" border="0" width="7" height="7"></sup></a></span></li> |
| 409 | <li><a href="http://felix.apache.org/site/future-ideas.html" title="Future Ideas">Future Ideas</a></li> |
| 410 | <li><a href="http://felix.apache.org/site/contact.html" title="Contact">Contact</a></li> |
| 411 | <li><a href="http://felix.apache.org/site/related-works.html" title="Related Works">Related Works</a></li> |
| 412 | <li><a href="http://felix.apache.org/site/article-presentations.html" title="Article & Presentations">Article & Presentations</a></li> |
| 413 | </ul> |
| 414 | |
| 415 | |
| 416 | <hr> |
| 417 | <div class="" align="center"> |
| 418 | <p><span class="nobr"><a href="http://cwiki.apache.org/confluence/createrssfeed.action?types=blogpost&statuses=created&statuses=modified&spaces=FELIX&labelString=iPOJO&rssType=atom&maxResults=10&timeSpan=5&publicFeed=true&title=iPOJO%20Atom%20Feed" title="Stay tuned!" rel="nofollow"><img src="ipojo-jmx-handler_files/feed-icon-32x32.png" align="absmiddle" border="0"><sup><img class="rendericon" src="ipojo-jmx-handler_files/linkext7.gif" alt="" align="absmiddle" border="0" width="7" height="7"></sup></a></span></p></div> |
| 419 | |
| 420 | <script type="text/javascript"> |
| 421 | var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); |
| 422 | document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); |
| 423 | </script><script src="ipojo-jmx-handler_files/ga.js" type="text/javascript"></script> |
| 424 | <script type="text/javascript"> |
| 425 | var pageTracker = _gat._getTracker("UA-1518442-4"); |
| 426 | pageTracker._trackPageview(); |
| 427 | </script> |
| 428 | </td></tr></tbody></table> |
| 429 | </div> |
| 430 | </body></html> |