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> |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 15 | <li><a href="http://felix.apache.org/site/downloads.cgi" rel="nofollow">downloads</a></li> |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 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> |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 19 | <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 Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 22 | <!-- ApacheCon Ad --> |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 23 | <iframe src="ipojo-jmx-handler_files/button.html" style="border-width: 0pt; float: left;" scrolling="no" frameborder="0" height="135" width="135"></iframe> |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 24 | <p style="height: 100px;"> |
| 25 | <!-- ApacheCon Ad --> |
| 26 | </p></li></ul> </div> |
| 27 | <div class="main"> |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 28 | <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 & Presentations">Article & 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 Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 183 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 184 | <h1><a name="iPOJOJMXHandler-iPOJOJMXHandler"></a>iPOJO JMX Handler</h1> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 185 | |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 186 | <p><em>This handler provides JMX management of component instance. It |
| 187 | could be useful to manage instance remotely. As the handler exposes |
| 188 | MBeans, you must have a MBean server running on your platform (as the |
| 189 | platform 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 Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 209 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 210 | <h2><a name="iPOJOJMXHandler-Features"></a>Features</h2> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 211 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 212 | <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 Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 218 | |
| 219 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 220 | <h2><a name="iPOJOJMXHandler-Prerequisites"></a>Prerequisites</h2> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 221 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 222 | <p>To be functional this handler must register on an MBean Server,thus |
| 223 | you obviously need it. Several servers are currently supported : the |
| 224 | standard platform MBean server (included in the JDK), MOSGi (provided |
| 225 | with Felix), ...<br> |
| 226 | To 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 Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 232 | |
| 233 | |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 234 | <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 Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 235 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 236 | <h2><a name="iPOJOJMXHandler-Download"></a>Download</h2> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 237 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 238 | <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] | 239 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 240 | <h2><a name="iPOJOJMXHandler-Howtouseit"></a>How to use it</h2> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 241 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 242 | <p>The handler needs to be added in the metadata.xml, you just add a namespace (e.g., jmx) :</p> |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 243 | <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"><</span><span>ipojo xmlns:</span><span class="attribute">jmx</span><span>=</span><span class="attribute-value">"org.apache.felix.ipojo.handlers.jmx"</span><span>> </span></td></tr><tr><td class="line2"> ... </td></tr><tr><td class="line1"><span class="tag"></</span><span>ipojo</span><span class="tag">></span><span> </span></td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly"><ipojo xmlns:jmx="org.apache.felix.ipojo.handlers.jmx"> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 245 | ... |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 246 | </ipojo></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 Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 264 | <p>So, you could now expose in JMX properties and methods of your component. They are surrounded by the <jmx:config><br> |
| 265 | tag.</p> |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 266 | <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"><</span><span>jmx:config</span><span class="tag">></span><span> </span></td></tr><tr><td class="line2"> <span class="tag"><</span><span>jmx:property </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"message"</span><span> </span><span class="attribute">field</span><span>=</span><span class="attribute-value">"m_msg"</span><span> </span><span class="attribute">rights</span><span>=</span><span class="attribute-value">"w"</span><span> </span><span class="attribute">notification</span><span>=</span><span class="attribute-value">"true"</span><span>/> </span></td></tr><tr><td class="line1"> <span class="tag"><</span><span>jmx:method </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"doSomethingBad"</span><span>/> </span></td></tr><tr><td class="line2"> <span class="tag"><</span><span>jmx:method </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"doSomethingGood"</span><span>/> </span></td></tr><tr><td class="line1"><span class="tag"></</span><span>jmx:config</span><span class="tag">></span><span> </span></td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly"><jmx:config> |
| 268 | <jmx:property name="message" field="m_msg" rights="w" notification="true"/> |
| 269 | <jmx:method name="doSomethingBad"/> |
| 270 | <jmx:method name="doSomethingGood"/> |
| 271 | </jmx:config></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 |
| 290 | careful that the argument and return type of methods must be |
| 291 | serializable. In case of several methods have the same name, each of |
| 292 | them will be exposed.</p></td></tr></tbody></table></div> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 293 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 294 | <h2><a name="iPOJOJMXHandler-JMXHandleroptions"></a>JMX Handler options</h2> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 295 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 296 | <p>Here you can find all configuration options of the JMX handler. |
| 297 | There are two kinds of manageable elements : properties and methods. |
| 298 | First is described the global configuration of the handler. Then |
| 299 | elements can be configured, using several attributes, as described |
| 300 | below.</p> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 301 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 302 | <h2><a name="iPOJOJMXHandler-Globalhandlerattributes"></a>Global handler attributes</h2> |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 303 | <div class="borderedTable"><table class="confluenceTable"><tbody> |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 304 | <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 |
| 313 | component. The syntax of this attribute must be compliant with the |
| 314 | ObjectName syntax, detailed in the JMX specification.<br> |
| 315 | If neither domain nor name attributes are specified, the default value |
| 316 | is determined by the package, the type and the instance name of the |
| 317 | component. 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 |
| 324 | left part of the object name). This attribute must be compliant with |
| 325 | the 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 |
| 332 | value of this attribute must comply with the ObjectName value syntax, |
| 333 | as 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> |
| 342 | postRegister <br> |
| 343 | preDeregister<br> |
| 344 | postDeregister</td> |
| 345 | <td class="confluenceTd">NO</td> |
| 346 | <td class="confluenceTd">These attributes allow to specify methods to |
| 347 | carry out operations before and after being registered or unregistered |
| 348 | from the MBean server.</td> |
| 349 | </tr> |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 350 | </tbody></table></div> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 351 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 352 | <h2><a name="iPOJOJMXHandler-Propertiesattributes"></a>Properties attributes</h2> |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 353 | <div class="borderedTable"><table class="confluenceTable"><tbody> |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 354 | <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 |
| 383 | notification sending for this property. If set to "true", a |
| 384 | notification is sent each time the value of the field changes.</td> |
| 385 | </tr> |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 386 | </tbody></table></div> |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 387 | <h2><a name="iPOJOJMXHandler-Methodsattributes"></a>Methods attributes</h2> |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 388 | <div class="borderedTable"><table class="confluenceTable"><tbody> |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 389 | <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 Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 404 | </tbody></table></div> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 405 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 406 | <h2><a name="iPOJOJMXHandler-Examples"></a>Examples</h2> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 407 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 408 | <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] | 409 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 410 | <h3><a name="iPOJOJMXHandler-ExposingAttributes"></a>Exposing Attributes</h3> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 411 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 412 | <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 Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 413 | <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> </span><span class="keyword">class</span><span> </span></td></tr><tr><td class="line2">MyComponent ... { </td></tr><tr><td class="line1"> <span class="comment">// Exposed attributes</span><span> </span></td></tr><tr><td class="line2"> <span class="keyword">private</span><span> String m_message; </span></td></tr><tr><td class="line1"> <span class="keyword">private</span><span> int m_level; </span></td></tr><tr><td class="line2">} </td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">public class |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 415 | MyComponent ... { |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 416 | // 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 Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 437 | <p>We expose now the attributes in the jmx:config<br> |
| 438 | tag in the metadata :</p> |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 439 | <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"><?</span><span>xml </span><span class="attribute">version</span><span>=</span><span class="attribute-value">"1.0"</span><span> </span><span class="attribute">encoding</span><span>=</span><span class="attribute-value">"UTF-8"</span><span>?> </span></td></tr><tr><td class="line2"><span class="tag"><</span><span>iPOJO xmlns:</span><span class="attribute">jmx</span><span>=</span><span class="attribute-value">"org.apache.felix.ipojo.handlers.jmx"</span><span>> </span></td></tr><tr><td class="line1"> <span class="tag"><</span><span>component </span><span class="attribute">className</span><span>=</span><span class="attribute-value">"...MyComponent"</span><span> </span></td></tr><tr><td class="line2"> <span class="attribute">architecture</span><span>=</span><span class="attribute-value">"true"</span><span> </span></td></tr><tr><td class="line1"> <span class="attribute">immediate</span><span>=</span><span class="attribute-value">"true"</span><span>> </span></td></tr><tr><td class="line2"> </td></tr><tr><td class="line1"> <span class="tag"><</span><span>provides</span><span class="tag">/></span><span> </span></td></tr><tr><td class="line2"> <span class="tag"><</span><span>jmx:config</span><span class="tag">></span><span> </span></td></tr><tr><td class="line1"> <span class="comments"><!-- Exposed properties --></span><span> </span></td></tr><tr><td class="line2"> <span class="tag"><</span><span>jmx:property </span><span class="attribute">field</span><span>=</span><span class="attribute-value">"m_level"</span><span> </span></td></tr><tr><td class="line1"> <span class="attribute">name</span><span>=</span><span class="attribute-value">"The level"</span><span> </span></td></tr><tr><td class="line2"> <span class="attribute">rights</span><span>=</span><span class="attribute-value">"r"</span><span>/> </span></td></tr><tr><td class="line1"> <span class="tag"><</span><span>jmx:property </span><span class="attribute">field</span><span>=</span><span class="attribute-value">"m_message"</span><span> </span></td></tr><tr><td class="line2"> <span class="attribute">name</span><span>=</span><span class="attribute-value">"The message"</span><span> </span></td></tr><tr><td class="line1"> <span class="attribute">rights</span><span>=</span><span class="attribute-value">"w"</span><span>/> </span></td></tr><tr><td class="line2"> <span class="tag"></</span><span>jmx:config</span><span class="tag">></span><span> </span></td></tr><tr><td class="line1"> <span class="tag"></</span><span>component</span><span class="tag">></span><span> </span></td></tr><tr><td class="line2"> <span class="tag"><</span><span>instance </span></td></tr><tr><td class="line1"> <span class="attribute">component</span><span>=</span><span class="attribute-value">"...MyComponent"</span><span>/> </span></td></tr><tr><td class="line2"><span class="tag"></</span><span>iPOJO</span><span class="tag">></span><span> </span></td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly"><?xml version="1.0" encoding="UTF-8"?> |
| 441 | <iPOJO xmlns:jmx="org.apache.felix.ipojo.handlers.jmx"> |
| 442 | <component className="...MyComponent" |
| 443 | architecture="true" |
| 444 | immediate="true"> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 445 | |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 446 | <provides/> |
| 447 | <jmx:config> |
| 448 | <!-- Exposed properties --> |
| 449 | <jmx:property field="m_level" |
| 450 | name="The level" |
| 451 | rights="r"/> |
| 452 | <jmx:property field="m_message" |
| 453 | name="The message" |
| 454 | rights="w"/> |
| 455 | </jmx:config> |
| 456 | </component> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 457 | <instance |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 458 | component="...MyComponent"/> |
| 459 | </iPOJO></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 Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 477 | <p>Now, we could get and write the properties in the JConsole :<br> |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 478 | <img src="ipojo-jmx-handler_files/JMXHandler_1.png" border="0" align="absmiddle"></p> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 479 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 480 | <h3><a name="iPOJOJMXHandler-ExposingMethods"></a>Exposing Methods</h3> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 481 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 482 | <p>We could now add methods in the initial class :</p> |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 483 | <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 something good</span></td></tr><tr><td class="line1"><span class="comment">*/</span><span> </span></td></tr><tr><td class="line2"><span class="keyword">public</span><span> </span><span class="keyword">void</span><span> doSomethingGood() { </span></td></tr><tr><td class="line1"> ... </td></tr><tr><td class="line2">} </td></tr><tr><td class="line1"> </td></tr><tr><td class="line2"><span class="comment">/**</span></td></tr><tr><td class="line1"><span class="comment">Do something bad</span></td></tr><tr><td class="line2"><span class="comment">*/</span><span> </span></td></tr><tr><td class="line1"><span class="keyword">public</span><span> </span><span class="keyword">void</span><span> doSomethingBad() { </span></td></tr><tr><td class="line2"> ... </td></tr><tr><td class="line1">} </td></tr><tr><td class="line2"> </td></tr><tr><td class="line1"><span class="comment">/**</span></td></tr><tr><td class="line2"><span class="comment">Do nothing</span></td></tr><tr><td class="line1"><span class="comment">*/</span><span> </span></td></tr><tr><td class="line2"><span class="keyword">public</span><span> </span><span class="keyword">void</span><span> doNothing() { </span></td></tr><tr><td class="line1"> ... </td></tr><tr><td class="line2">} </td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">/** |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 485 | Do something good |
| 486 | */ |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 487 | public void doSomethingGood() { |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 488 | ... |
| 489 | } |
| 490 | |
| 491 | /** |
| 492 | Do something bad |
| 493 | */ |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 494 | public void doSomethingBad() { |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 495 | ... |
| 496 | } |
| 497 | |
| 498 | /** |
| 499 | Do nothing |
| 500 | */ |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 501 | public void doNothing() { |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 502 | ... |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 503 | }</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 Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 521 | <p>We add corresponding tags in the metadata to expose these methods:</p> |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 522 | <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"><!-- Exposed methods --></span><span> </span></td></tr><tr><td class="line2"><span class="tag"><</span><span>jmx:method </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"doSomethingGood"</span><span> </span></td></tr><tr><td class="line1"> <span class="attribute">description</span><span>=</span><span class="attribute-value">"Do something good."</span><span>/> </span></td></tr><tr><td class="line2"><span class="tag"><</span><span>jmx:method </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"doSomethingBad"</span><span> </span></td></tr><tr><td class="line1"> <span class="attribute">description</span><span>=</span><span class="attribute-value">"Do something bad."</span><span>/> </span></td></tr><tr><td class="line2"><span class="tag"><</span><span>jmx:method </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"doNothing"</span><span> </span></td></tr><tr><td class="line1"> <span class="attribute">description</span><span>=</span><span class="attribute-value">"Do absolutely nothing."</span><span>/> </span></td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly"><!-- Exposed methods --> |
| 524 | <jmx:method name="doSomethingGood" |
| 525 | description="Do something good."/> |
| 526 | <jmx:method name="doSomethingBad" |
| 527 | description="Do something bad."/> |
| 528 | <jmx:method name="doNothing" |
| 529 | description="Do absolutely nothing."/></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 Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 547 | <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] | 548 | |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 549 | <p><img src="ipojo-jmx-handler_files/JMXHandler_2.png" border="0" align="absmiddle"></p> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 550 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 551 | <h3><a name="iPOJOJMXHandler-AttributeNotifications:"></a>Attribute Notifications:</h3> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 552 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 553 | <p>You could subscribe to attribute notification by adding the |
| 554 | notification attribute in property tag. In our example if we want to be |
| 555 | notified when m_level is modified, we change the property line in the |
| 556 | metatada like this:</p> |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 557 | <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"><</span><span>jmx:property </span><span class="attribute">field</span><span>=</span><span class="attribute-value">"m_level"</span><span> </span></td></tr><tr><td class="line2"> <span class="attribute">name</span><span>=</span><span class="attribute-value">"The level"</span><span> </span></td></tr><tr><td class="line1"> <span class="attribute">rights</span><span>=</span><span class="attribute-value">"r"</span><span> </span></td></tr><tr><td class="line2"> <span class="attribute">notification</span><span>=</span><span class="attribute-value">"true"</span><span>/> </span></td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="xml:nocontrols:nogutter" rows="10" readonly="readonly"><jmx:property field="m_level" |
| 559 | name="The level" |
| 560 | rights="r" |
| 561 | notification="true"/></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 Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 579 | <p>So now if we change the string through JConsole or if the POJO is |
| 580 | modified in other way, a notification will be sent to every listener. |
| 581 | For example, we subscribe in the notification tab, and we get |
| 582 | notification when the message changes :</p> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 583 | |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 584 | <p><img src="ipojo-jmx-handler_files/JMXHandler_3.png" border="0" align="absmiddle"></p> |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 585 | |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 586 | <h2><a name="iPOJOJMXHandler-Configuringthehandlerwithannotations"></a>Configuring the handler with annotations</h2> |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 587 | |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 588 | <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> org.apache.felix.ipojo.annotations.Component; </span></td></tr><tr><td class="line2"><span class="keyword">import</span><span> org.apache.felix.ipojo.handlers.jmx.Config; </span></td></tr><tr><td class="line1"><span class="keyword">import</span><span> org.apache.felix.ipojo.handlers.jmx.Method; </span></td></tr><tr><td class="line2"><span class="keyword">import</span><span> org.apache.felix.ipojo.handlers.jmx.Property; </span></td></tr><tr><td class="line1"><span class="preprocessor"></span></td></tr><tr><td class="line2"><span class="preprocessor">@Component</span><span> </span></td></tr><tr><td class="line1"><span class="preprocessor">@Config(domain="my-domain", usesMOSGi=false)</span><span> </span></td></tr><tr><td class="line2"><span class="keyword">public</span><span> </span><span class="keyword">class</span><span> JMXSimple { </span></td></tr><tr><td class="line1"><span class="preprocessor"></span></td></tr><tr><td class="line2"><span class="preprocessor"> @Property(name="prop", notification=true, rights="w") // Field published in the MBean</span><span> </span></td></tr><tr><td class="line1"> String m_foo; </td></tr><tr><td class="line2"><span class="preprocessor"> </span></td></tr><tr><td class="line1"><span class="preprocessor"> @Method(description="set the foo prop") // Method published in the MBean</span><span> </span></td></tr><tr><td class="line2"> <span class="keyword">public</span><span> </span><span class="keyword">void</span><span> setFoo(String mes) { </span></td></tr><tr><td class="line1"> System.out.println(<span class="string">"Set foo to "</span><span> + mes); </span></td></tr><tr><td class="line2"> m_foo = mes; </td></tr><tr><td class="line1"> } </td></tr><tr><td class="line2"><span class="preprocessor"> </span></td></tr><tr><td class="line1"><span class="preprocessor"> @Method(description="get the foo prop") // Method published in the MBean</span><span> </span></td></tr><tr><td class="line2"> <span class="keyword">public</span><span> String getFoo() { </span></td></tr><tr><td class="line1"> <span class="keyword">return</span><span> m_foo; </span></td></tr><tr><td class="line2"> } </td></tr><tr><td class="line1">} </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; |
| 591 | import org.apache.felix.ipojo.handlers.jmx.Config; |
| 592 | import org.apache.felix.ipojo.handlers.jmx.Method; |
| 593 | import org.apache.felix.ipojo.handlers.jmx.Property; |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 594 | |
| 595 | @Component |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 596 | @Config(domain="my-domain", usesMOSGi=false) |
| 597 | public class JMXSimple { |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 598 | |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 599 | @Property(name="prop", notification=true, rights="w") // Field published in the MBean |
| 600 | String m_foo; |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 601 | |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 602 | @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 Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 605 | m_foo = mes; |
| 606 | } |
| 607 | |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 608 | @Method(description="get the foo prop") // Method published in the MBean |
| 609 | public String getFoo() { |
| 610 | return m_foo; |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 611 | } |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 612 | }</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 Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 630 | <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 Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 637 | |
| 638 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 639 | <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 Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 645 | |
| 646 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 647 | <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 Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 649 | <li>description: set the method description. |
| 650 | <br clear="all"> |
| 651 | <br clear="all"> |
Clement Escoffier | 8350751 | 2008-10-13 07:33:03 +0000 | [diff] [blame] | 652 | |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 653 | </li></ul></div> |
| 654 | <img src="ipojo-jmx-handler_files/footer.png" class="footer"> |
| 655 | </div> |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 656 | |
| 657 | <script type="text/javascript"> |
| 658 | var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); |
| 659 | document.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 Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 662 | try{ |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 663 | var pageTracker = _gat._getTracker("UA-1518442-4"); |
| 664 | pageTracker._trackPageview(); |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 665 | } catch(err) {} |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 666 | </script> |
Clement Escoffier | 373a57d | 2009-07-21 12:06:46 +0000 | [diff] [blame] | 667 | |
| 668 | |
| 669 | |
Clement Escoffier | 8251f60 | 2009-01-15 15:35:17 +0000 | [diff] [blame] | 670 | </div> |
| 671 | </body></html> |