blob: 44519847be07b2605f8e0140ecd694aee3be5467 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE- 2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<head>
<title>Apache Felix - iPOJO JMX Handler</title>
<link rel="icon" href="/res/favicon.ico">
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="The most powerful component model for OSGi">
<link href="/ipojo/web/bootstrap/css/bootstrap-cerulean.css" rel="stylesheet">
<link href="/ipojo/web/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<link href="/ipojo/web/bootstrap/css/font-awesome.min.css" rel="stylesheet">
<link href="/ipojo/web/style.css" rel="stylesheet">
<!-- Overide alert's colors -->
<link href="/ipojo/web/bootstrap/css/alert.css" rel="stylesheet">
<link rel="stylesheet" href="/ipojo/web/github.css" type="text/css" media="all">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="/ipojo/web/bootstrap/js/bootstrap.min.js"></script>
</head>
<body data-spy="scroll" data-target=".subnav">
<div class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="/documentation/subprojects/apache-felix-ipojo.html">Apache Felix iPOJO</a>
<div class="nav-collapse" id="main-menu">
<ul class="nav" id="main-menu-left">
<li><a href="/documentation/subprojects/apache-felix-ipojo/ipojo-news.html">News</a></li>
<li><a href="http://felix.apache.org/downloads.cgi">Downloads</a></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Tutorials <b class="caret"></b></a>
<ul class="dropdown-menu" id="tutorials-menu">
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-why-choose-ipojo.html">Why choose iPOJO</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-successstories.html">Success stories</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-feature-overview.html">Features</a></li>
<li class="divider"></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-gettingstarted/ipojo-in-10-minutes.html">iPOJO in 10 minutes</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-gettingstarted/how-to-use-ipojo-annotations.html">Using Annotations</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-gettingstarted/ipojo-hello-word-maven-based-tutorial.html">Maven tutorial</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-gettingstarted/ipojo-advanced-tutorial.html">Advanced tutorial</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-gettingstarted/apache-felix-ipojo-dosgi.html">Using Distributed OSGi</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-gettingstarted/ipojo-composition-tutorial.html">Application Composition</a></li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Documentation <b class="caret"></b></a>
<ul class="dropdown-menu" id="user-guide-menu">
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/service-requirement-handler.html">Requiring a service</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/providing-osgi-services.html">Providing a service</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/lifecycle-callback-handler.html">Lifecycle management</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/configuration-handler.html">Configuration</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/architecture-handler.html">Introspection</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/controller-lifecycle-handler.html">Impacting the lifecycle</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/injecting-bundle-context.html">Accessing the Bundle Context</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/apache-felix-ipojo-instances.html">Creating instances</a></li>
<li class="divider"></li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">External <em>handlers</em></a>
<ul class="dropdown-menu">
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/event-admin-handlers.html">Asynchronous communication</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/ipojo-jmx-handler.html">JMX management</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/extender-pattern-handler.html">Extender pattern</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/white-board-pattern-handler.html">Whiteboard pattern</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/temporal-service-dependency.html">Temporal dependencies</a></li>
</ul>
</li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Configuration Admin &amp; Factories</a>
<ul class="dropdown-menu">
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/combining-ipojo-and-configuration-admin.html">iPOJO and config admin</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/ipojo-factory-service.html">Using the iPOJO Factory service</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/how-to-use-ipojo-factories.html">Factories and Instances</a></li>
</ul>
</li>
<li class="divider"></li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Advanced topics</a>
<ul class="dropdown-menu">
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/instance-vs-service-controller.html">Instance vs. Service Controllers</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/service-binding-interceptors.html">Service Binding Interceptors</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/using-xml-schemas.html">XML Schemas</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/apache-felix-ipojo-api.html">Using the iPOJO API</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/constructing-pojo-objects-with-factory-methods.html">Constructing service objects with factory methods</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/using-ipojo-introspection-api.html">Using the introspection API</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-testing-components.html">Testing components</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/using-stereotypes.html">Using @Stereotypes</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-eclipse-integration.html">Eclipse Integration</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/ipojo-extender-configuration.html">Configuring iPOJO's Extender</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-faq.html">FAQ</a></li>
<li class="divider"></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-devguide/how-to-write-your-own-handler.html">Handler development</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-devguide/how-to-use-ipojo-manipulation-metadata.html">Manipulation Metadata </a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-devguide/dive-into-the-ipojo-manipulation-depths.html">Dive into the iPOJO Manipulation depths</a></li>
<li><a href="http://felix.apache.org/ipojo/api/1.12.1">Javadoc</a></li>
</ul>
</li>
</ul>
</li>
<li class="dropdown" id="tools-menu">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Tools <b class="caret"></b></a>
<ul class="dropdown-menu" id="swatch-menu">
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/ipojo-ant-task.html">Ant Task</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/ipojo-maven-plug-in.html">Maven Plugin</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/ipojo-arch-command.html">Architecture commands</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/apache-felix-ipojo-online-manipulator.html">Online Manipulator</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/ipojo-webconsole-plugin.html">Webconsole plugin</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/ipojo-karaf-feature.html">Apache Karaf Features</a></li>
</ul>
</li>
<li class="dropdown" id="community-menu">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Community <b class="caret"></b></a>
<ul class="dropdown-menu" id="swatch-menu">
<li><a href="/documentation/subprojects/apache-felix-ipojo/ipojo-support.html">Support</a></li>
<li><a href="http://www.apache.org/">ASF</a></li>
<li><a href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li>
<li><a href="http://www.apache.org/foundation/thanks.html">Sponsors</a></li>
</ul>
</li>
<li class="dropdown" id="misc-menu">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Misc <b class="caret"></b></a>
<ul class="dropdown-menu" id="swatch-menu">
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-supportedvms.html">Supported JVMs</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-supportedosgi.html">Supported OSGi Implementations</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/articles-and-presentations.html">Article & Presentations</a></li>
<li><a href="/documentation/subprojects/apache-felix-ipojo/developing-camel-mediators-with-ipojo.html">Developping Camel mediators with iPOJO</a></li>
</ul>
</li>
</ul>
<ul class="nav pull-right" id="main-menu-right">
<li><a rel="tooltip" target="_blank" href="http://felix.apache.org">Apache Felix <i class="icon-share-alt"></i></a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="container">
<div class="content">
<style type="text/css">
/* The following code is added by mdx_elementid.py
It was originally lifted from http://subversion.apache.org/style/site.css */
/*
* Hide class="elementid-permalink", except when an enclosing heading
* has the :hover property.
*/
.headerlink, .elementid-permalink {
visibility: hidden;
}
h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style>
<h1 id="ipojo-jmx-handler">iPOJO JMX Handler<a class="headerlink" href="#ipojo-jmx-handler" title="Permanent link">&para;</a></h1>
<p><em>This handler provides JMX management of component instance. It could be useful to manage instance remotely. As the handler exposes MBeans, you must have a MBean server running on your platform (as the platform MBean server or the MOSGi MBean Server).</em></p>
<div class="toc">
<ul>
<li><a href="#ipojo-jmx-handler">iPOJO JMX Handler</a><ul>
<li><a href="#features">Features</a></li>
<li><a href="#prerequisites">Prerequisites</a></li>
<li><a href="#download">Download</a></li>
<li><a href="#how-to-use-it">How to use it</a></li>
<li><a href="#jmx-handler-options">JMX Handler options</a></li>
<li><a href="#global-handler-attributes">Global handler attributes</a></li>
<li><a href="#properties-attributes">Properties attributes</a></li>
<li><a href="#methods-attributes">Methods attributes</a></li>
<li><a href="#examples">Examples</a><ul>
<li><a href="#exposing-attributes">Exposing Attributes</a></li>
<li><a href="#exposing-methods">Exposing Methods</a></li>
<li><a href="#attribute-notifications">Attribute Notifications:</a></li>
</ul>
</li>
<li><a href="#configuring-the-handler-with-annotations">Configuring the handler with annotations</a></li>
</ul>
</li>
</ul>
</div>
<h2 id="features">Features<a class="headerlink" href="#features" title="Permanent link">&para;</a></h2>
<p>The handler allows to:</p>
<ul>
<li>Expose attributes accessible via JMX (with right management).</li>
<li>Expose methods to be called through JMX.</li>
<li>Get notifications when attributes are modified .</li>
</ul>
<h2 id="prerequisites">Prerequisites<a class="headerlink" href="#prerequisites" title="Permanent link">&para;</a></h2>
<p>To be functional this handler must register on an MBean Server,thus you obviously need it. Several servers are currently supported : the standard platform MBean server (included in the Java Virtual Machine since version 5), MOSGi (Apache Felix sub-project), ...</p>
<h2 id="download">Download<a class="headerlink" href="#download" title="Permanent link">&para;</a></h2>
<p>The JMX handler is available in the Felix trunk in the iPOJO project. See the <a href="/documentation/subprojects/apache-felix-ipojo/download.html">Download</a> page to download and compile these sources.</p>
<h2 id="how-to-use-it">How to use it<a class="headerlink" href="#how-to-use-it" title="Permanent link">&para;</a></h2>
<p>The handler needs to be added in the metadata.xml, you just add a namespace (e.g., jmx) :</p>
<div class="codehilite"><pre><span class="nt">&lt;ipojo</span> <span class="na">xmlns:jmx=</span><span class="s">&quot;org.apache.felix.ipojo.handlers.jmx&quot;</span><span class="nt">&gt;</span>
...
<span class="nt">&lt;/ipojo&gt;</span>
</pre></div>
<p>So, you could now expose in JMX properties and methods of your component. They are surrounded by the <jmx:config>
tag.</p>
<div class="codehilite"><pre><span class="nt">&lt;jmx:config&gt;</span>
<span class="nt">&lt;jmx:property</span> <span class="na">name=</span><span class="s">&quot;message&quot;</span> <span class="na">field=</span><span class="s">&quot;m_msg&quot;</span> <span class="na">rights=</span><span class="s">&quot;w&quot;</span> <span class="na">notification=</span><span class="s">&quot;true&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;jmx:method</span> <span class="na">name=</span><span class="s">&quot;doSomethingBad&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;jmx:method</span> <span class="na">name=</span><span class="s">&quot;doSomethingGood&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;/jmx:config&gt;</span>
</pre></div>
<div class="alert alert-info info" markdown="1">
<h4>Serialization</h4>
<p>Be careful that the argument and return type of methods must be serializable. In case of several methods have the same name, each of them will be exposed.</p>
</div>
<h2 id="jmx-handler-options">JMX Handler options<a class="headerlink" href="#jmx-handler-options" title="Permanent link">&para;</a></h2>
<p>Here you can find all configuration options of the JMX handler. There are two kinds of manageable elements : properties and methods. First is described the global configuration of the handler. Then elements can be configured, using several attributes, as described below.</p>
<h2 id="global-handler-attributes">Global handler attributes<a class="headerlink" href="#global-handler-attributes" title="Permanent link">&para;</a></h2>
<table class="table table-bordered">
<thead>
<tr>
<th>Attribute name</th>
<th>Required</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>objectName</td>
<td>No</td>
<td>The complete object name of the managed component. The syntax of this attribute must be compliant with the ObjectName syntax, detailed in the JMX specification. If neither domain nor name attributes are specified, the default value is determined by the package, the type and the instance name of the component. This attribute overrides the domain and name attributes. <em>Example:</em> <code>"my.domain:type=myType,name=myName"</code></td>
</tr>
<tr>
<td>domain</td>
<td>No</td>
<td>The domain of the managed object (i.e., the left part of the object name). This attribute must be compliant with the domain syntax, as described in the JMX specification. <em>Example:</em> <code>"my.domain:type=myType,name=my.domain"</code></td>
</tr>
<tr>
<td>name</td>
<td>No</td>
<td>The name property of the managed object. The value of this attribute must comply with the ObjectName value syntax, as described in the JMX specification.</td>
</tr>
<tr>
<td>usesMOSGi</td>
<td>No</td>
<td>Determines if the component must be register on the MOSGi MBean server or not.</td>
</tr>
<tr>
<td>preRegister, postRegister, preDeregister, postDeregister</td>
<td>No</td>
<td>These attributes allow to specify methods to carry out operations before and after being registered or unregistered from the MBean server.</td>
</tr>
</tbody>
</table>
<h2 id="properties-attributes">Properties attributes<a class="headerlink" href="#properties-attributes" title="Permanent link">&para;</a></h2>
<table class="table table-bordered">
<thead>
<tr>
<th>Attribute name</th>
<th>Required</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>field</td>
<td>Yes</td>
<td>The name of the component's field to expose.</td>
</tr>
<tr>
<td>rights</td>
<td>No</td>
<td>The domain of the managed object (i.e., the left part of the object name). This attribute must be compliant with the domain syntax, as described in the JMX specification. <em>Example:</em> <code>"my.domain:type=myType,name=my.domain"</code></td>
</tr>
<tr>
<td>name</td>
<td>No</td>
<td>Specify the access permission of the exposed field. The accepted values are :
<ul>
<li>"r" : read-only access, the default value.</li>
<li>"w" : read and write access.</li>
</ul>
</td>
</tr>
<tr>
<td>notification</td>
<td>No</td>
<td>Enable or disable attribute change notification sending for this property. If set to `true`, a notification is sent each time the value of the field changes.</td>
</tr>
</tbody>
</table>
<h2 id="methods-attributes">Methods attributes<a class="headerlink" href="#methods-attributes" title="Permanent link">&para;</a></h2>
<table class="table table-bordered">
<thead>
<tr>
<th>Attribute name</th>
<th>Required</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>Yes</td>
<td>The name of the method to expose. If multiple methods have the same name, all of them are exposed.</td>
</tr>
<tr>
<td>description</td>
<td>No</td>
<td>The description of the exposed method, as it will appear in JMX.</td>
</tr>
</tbody>
</table>
<h2 id="examples">Examples<a class="headerlink" href="#examples" title="Permanent link">&para;</a></h2>
<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>
<h3 id="exposing-attributes">Exposing Attributes<a class="headerlink" href="#exposing-attributes" title="Permanent link">&para;</a></h3>
<p>In first time we create a simple component named MyComponent. We have add two fields named m<em>level (int) and m</em>message (String).</p>
<div class="codehilite"><pre><span class="kd">public</span> <span class="kd">class</span> <span class="nc">MyComponent</span> <span class="o">...</span> <span class="o">{</span>
<span class="c1">// Exposed attributes</span>
<span class="kd">private</span> <span class="n">String</span> <span class="n">m_message</span><span class="o">;</span>
<span class="kd">private</span> <span class="kt">int</span> <span class="n">m_level</span><span class="o">;</span>
<span class="o">}</span>
</pre></div>
<p>We expose now the attributes in the jmx:config
tag in the metadata :</p>
<div class="codehilite"><pre><span class="cp">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="nt">&lt;iPOJO</span> <span class="na">xmlns:jmx=</span><span class="s">&quot;org.apache.felix.ipojo.handlers.jmx&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;component</span> <span class="na">className=</span><span class="s">&quot;...MyComponent&quot;</span>
<span class="na">architecture=</span><span class="s">&quot;true&quot;</span>
<span class="na">immediate=</span><span class="s">&quot;true&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;provides/&gt;</span>
<span class="nt">&lt;jmx:config&gt;</span>
<span class="c">&lt;!-- Exposed properties --&gt;</span>
<span class="nt">&lt;jmx:property</span> <span class="na">field=</span><span class="s">&quot;m_level&quot;</span>
<span class="na">name=</span><span class="s">&quot;The level&quot;</span>
<span class="na">rights=</span><span class="s">&quot;r&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;jmx:property</span> <span class="na">field=</span><span class="s">&quot;m_message&quot;</span>
<span class="na">name=</span><span class="s">&quot;The message&quot;</span>
<span class="na">rights=</span><span class="s">&quot;w&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;/jmx:config&gt;</span>
<span class="nt">&lt;/component&gt;</span>
<span class="nt">&lt;instance</span>
<span class="na">component=</span><span class="s">&quot;...MyComponent&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;/iPOJO&gt;</span>
</pre></div>
<p>Now, we could get and write the properties in the JConsole :</p>
<p><img src="JMXHandler_1.png"></p>
<h3 id="exposing-methods">Exposing Methods<a class="headerlink" href="#exposing-methods" title="Permanent link">&para;</a></h3>
<p>We could now add methods in the initial class :</p>
<div class="codehilite"><pre><span class="cm">/**</span>
<span class="cm">Do something good</span>
<span class="cm">*/</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">doSomethingGood</span><span class="o">()</span> <span class="o">{</span>
<span class="o">...</span>
<span class="o">}</span>
<span class="cm">/**</span>
<span class="cm">Do something bad</span>
<span class="cm">*/</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">doSomethingBad</span><span class="o">()</span> <span class="o">{</span>
<span class="o">...</span>
<span class="o">}</span>
<span class="cm">/**</span>
<span class="cm">Do nothing</span>
<span class="cm">*/</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">doNothing</span><span class="o">()</span> <span class="o">{</span>
<span class="o">...</span>
<span class="o">}</span>
</pre></div>
<p>We add corresponding tags in the metadata to expose these methods:</p>
<div class="codehilite"><pre><span class="c">&lt;!-- Exposed methods --&gt;</span>
<span class="nt">&lt;jmx:method</span> <span class="na">name=</span><span class="s">&quot;doSomethingGood&quot;</span>
<span class="na">description=</span><span class="s">&quot;Do something good.&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;jmx:method</span> <span class="na">name=</span><span class="s">&quot;doSomethingBad&quot;</span>
<span class="na">description=</span><span class="s">&quot;Do something bad.&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;jmx:method</span> <span class="na">name=</span><span class="s">&quot;doNothing&quot;</span>
<span class="na">description=</span><span class="s">&quot;Do absolutely nothing.&quot;</span><span class="nt">/&gt;</span>
</pre></div>
<p>Now the three methods are exposed in the operations tab of the JConsole. We can invoked these methods :</p>
<p><img src="JMXHandler_2.png"></p>
<h3 id="attribute-notifications">Attribute Notifications:<a class="headerlink" href="#attribute-notifications" title="Permanent link">&para;</a></h3>
<p>You could subscribe to attribute notification by adding the notification attribute in property tag. In our example if we want to be notified when m_level is modified, we change the property line in the metatada like this:</p>
<div class="codehilite"><pre><span class="nt">&lt;jmx:property</span> <span class="na">field=</span><span class="s">&quot;m_level&quot;</span>
<span class="na">name=</span><span class="s">&quot;The level&quot;</span>
<span class="na">rights=</span><span class="s">&quot;r&quot;</span>
<span class="na">notification=</span><span class="s">&quot;true&quot;</span><span class="nt">/&gt;</span>
</pre></div>
<p>So now if we change the string through JConsole (or in the VisualVM) or if the POJO is modified in other way, a notification will be sent to every listener. For example, we subscribe in the notification tab, and we get notification when the message changes :</p>
<p><img src="JMXHandler_3.png"></p>
<h2 id="configuring-the-handler-with-annotations">Configuring the handler with annotations<a class="headerlink" href="#configuring-the-handler-with-annotations" title="Permanent link">&para;</a></h2>
<p>It is possible to configure the handler with simple annotations available with iPOJO annotations. Here is an example of usage:</p>
<div class="codehilite"><pre><span class="kn">import</span> <span class="nn">org.apache.felix.ipojo.annotations.Component</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.apache.felix.ipojo.handlers.jmx.Config</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.apache.felix.ipojo.handlers.jmx.Method</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.apache.felix.ipojo.handlers.jmx.Property</span><span class="o">;</span>
<span class="nd">@Component</span>
<span class="nd">@Config</span><span class="o">(</span><span class="n">domain</span><span class="o">=</span><span class="s">&quot;my-domain&quot;</span><span class="o">,</span> <span class="n">usesMOSGi</span><span class="o">=</span><span class="kc">false</span><span class="o">)</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">JMXSimple</span> <span class="o">{</span>
<span class="nd">@Property</span><span class="o">(</span><span class="n">name</span><span class="o">=</span><span class="s">&quot;prop&quot;</span><span class="o">,</span> <span class="n">notification</span><span class="o">=</span><span class="kc">true</span><span class="o">,</span> <span class="n">rights</span><span class="o">=</span><span class="s">&quot;w&quot;</span><span class="o">)</span> <span class="c1">// Field published in the MBean</span>
<span class="n">String</span> <span class="n">m_foo</span><span class="o">;</span>
<span class="nd">@Method</span><span class="o">(</span><span class="n">description</span><span class="o">=</span><span class="s">&quot;set the foo prop&quot;</span><span class="o">)</span> <span class="c1">// Method published in the MBean</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">setFoo</span><span class="o">(</span><span class="n">String</span> <span class="n">mes</span><span class="o">)</span> <span class="o">{</span>
<span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">&quot;Set foo to &quot;</span> <span class="o">+</span> <span class="n">mes</span><span class="o">);</span>
<span class="n">m_foo</span> <span class="o">=</span> <span class="n">mes</span><span class="o">;</span>
<span class="o">}</span>
<span class="nd">@Method</span><span class="o">(</span><span class="n">description</span><span class="o">=</span><span class="s">&quot;get the foo prop&quot;</span><span class="o">)</span> <span class="c1">// Method published in the MBean</span>
<span class="kd">public</span> <span class="n">String</span> <span class="nf">getFoo</span><span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="n">m_foo</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">}</span>
</pre></div>
<p>The <code>@org.apache.felix.ipojo.handlers.jmx.Config</code> (<code>@Config</code> if the package it correctly imported) annotation is a type annotation (so placed on the <code>class</code> element. This annotation indicates that the instance will be exposed as an MBean. This annotation supports:</p>
<ul>
<li>usesMOSGi: set to <code>true</code> to use MOSGi. Otherwise, the MBean will be exposed in the MBean Platform Server (default: <code>false</code>).</li>
<li>objectname: set the MBean objectname. The objectname must follow JMX specification. (default: <code>package-name:factory-name:instance-name</code>)</li>
<li>domain: set the MBean domain. (default: <code>package-name</code>)</li>
<li>name: set the MBean name. (default: <code>instance-name</code>).</li>
</ul>
<p>The <code>@org.apache.felix.ipojo.handlers.jmx.Property</code> (<code>@Property</code>) annotation is a field annotation indicating that the field is exposed in the MBean. The supported attributes are:</p>
<ul>
<li>name: set the property name</li>
<li>rights: set the access permission. Possible values are <code>r</code> (read only) and <code>w</code> (read and write). By default, properties are in read-only mode.<ul>
<li>notification: enables notification on this property. By default notifications are disabled.</li>
</ul>
</li>
</ul>
<p>The <code>@org.apache.felix.ipojo.handlers.jmx.Method</code> annotation is a method annotation indicating that the method is exposed in the MBean. Only one attribute can be customized:</p>
<ul>
<li>description: set the method description.</li>
</ul>
</div>
</div>
<hr/>
<div class="container">
<footer id="footer">
<div class="row">
<div class="trademarkFooter span7">
Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project
logo are trademarks of The Apache Software Foundation. All other marks mentioned
may be trademarks or registered trademarks of their respective owners.
</div>
<div class="timestamp span3 offset2">
Rev. 1700393 by cziegeler on Tue, 1 Sep 2015 06:04:06 +0000
</div>
</div>
</footer>
</div>
</body>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("UA-1518442-4");
pageTracker._trackPageview();
} catch(err) {}
</script>
</html>