| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>Jetty JMX Annotations</title><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1"><meta name="keywords" content="jetty, servlet, servlet-api, cometd, http, websocket, eclipse, maven, java, server, software"><link rel="home" href="index.html" title="Jetty : The Definitive Reference"><link rel="up" href="jmx-chapter.html" title="Chapter 13. JMX"><link rel="prev" href="jetty-jconsole.html" title="Jetty JConsole"><link rel="next" href="alpn-chapter.html" title="Chapter 14. ALPN"><link xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" rel="shortcut icon" href="images/favicon.ico"><script type="text/javascript" src="js/shCore.js"></script><script type="text/javascript" src="js/shBrushJava.js"></script><script type="text/javascript" src="js/shBrushXml.js"></script><script type="text/javascript" src="js/shBrushBash.js"></script><script type="text/javascript" src="js/shBrushJScript.js"></script><script type="text/javascript" src="js/shBrushSql.js"></script><script type="text/javascript" src="js/shBrushProperties.js"></script><script type="text/javascript" src="js/shBrushPlain.js"></script><link type="text/css" rel="stylesheet" href="css/shCore.css"><link type="text/css" rel="stylesheet" href="css/shThemeEclipse.css"><link type="text/css" rel="stylesheet" href="css/font-awesome.min.css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><tr><td style="width: 25%"><a href="http://www.eclipse.org/jetty"><img src="images/jetty-header-logo.png" alt="Jetty Logo"></a><br><span style="font-size: small"> |
| Version: 9.3.0.v20150612</span></td><td style="width: 50%"><script type="text/javascript"> (function() { |
| var cx = '016459005284625897022:obd4lsai2ds'; |
| var gcse = document.createElement('script'); |
| gcse.type = 'text/javascript'; |
| gcse.async = true; |
| gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + |
| '//www.google.com/cse/cse.js?cx=' + cx; |
| var s = document.getElementsByTagName('script')[0]; |
| s.parentNode.insertBefore(gcse, s); |
| })(); |
| </script><gcse:search></gcse:search></td></tr></table><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Jetty JMX Annotations</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="jetty-jconsole.html"><i class="icon-chevron-left"></i> Previous</a> </td><th width="60%" align="center">Chapter 13. JMX<br><a accesskey="p" href="index.html"><i class="icon-home"></i> Home</a></th><td width="20%" align="right"> <a accesskey="n" href="alpn-chapter.html">Next <i class="icon-chevron-right"></i></a></td></tr></table><hr></div><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="jetty-callout"><h5 class="callout"><a href="http://www.webtide.com/">Contact the core Jetty developers at |
| <span class="website">www.webtide.com</span></a></h5><p> |
| private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... |
| scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery |
| </p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="jetty-jmx-annotations"></a>Jetty JMX Annotations</h2></div></div></div><div class="toc"><dl><dt><span class="section"><a href="jetty-jmx-annotations.html#jmx-annotation-introspection">Annotation Introspection</a></span></dt><dt><span class="section"><a href="jetty-jmx-annotations.html#jmx-managed-object">@ManagedObject</a></span></dt><dt><span class="section"><a href="jetty-jmx-annotations.html#jmx-managed-attribute">@ManagedAttribute</a></span></dt><dt><span class="section"><a href="jetty-jmx-annotations.html#jmx-managed-operation">@ManagedOperation</a></span></dt><dt><span class="section"><a href="jetty-jmx-annotations.html#jmx-name-annotation">@Name</a></span></dt><dt><span class="section"><a href="jetty-jmx-annotations.html#jmx-annotation-example">Example</a></span></dt></dl></div><p> |
| When the jetty-jmx libraries are present on startup and the wiring is enabled for exposing jetty mbeans to jmx, there are three annotations that govern when and how mbeans are created and exposed. |
| </p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="jmx-annotation-introspection"></a>Annotation Introspection</h3></div></div></div><p> |
| When jmx is configured and enabled in jetty any time an object is registered with the Server it is introspected as a potential mbean to be exposed. This introspection proceeds as follows assuming the class is named <code class="code">com.acme.Foo</code>: |
| </p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><p> |
| All influences for <code class="code">com.acme.Foo</code> determined. These include each class in the chain of super classes, and by convention each of these classes following a form of <code class="code">com.acme.jmx.FooMBean</code>. All super classes and their corresponding MBean representations are then used in the next step. |
| </p></li><li class="listitem"><p> |
| Each potential influencing class is checked for the @ManagedObject annotation, should this annotation exist at any point in the chain of influencers then a mbean is created with the description of the version @ManageObject discovered. |
| </p></li><li class="listitem"><p> |
| Once an mbean has been created for an object then each potential influencing object is introspected for @ManagedAttribute and @ManagedOperation annotations and the corresponding type is exposed to the mbean. |
| </p></li></ol></div><p> |
| The convention of looking for @ManageObject annotations on <code class="code">.jmx.<span class="emphasis"><em>Class</em></span>MBean</code> allows for a normal POJO to be wrapped in an mbean without itself without requiring it being marked up with annotations. Since the pojo is passed to these wrapped derived Mbean instances and is an internal variable then the MBean can be used to better expose a set of attributes and operations that may not have been anticipated when the original object was created. |
| </p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="jmx-managed-object"></a>@ManagedObject</h3></div></div></div><p> |
| The @ManagedObject annotation is used on a class at the top level to indicate that it should be exposed as an mbean. It has only one attribute to it which is used as the description of the MBean. Should multiple @ManagedObject annotations be found in the chain of influence then the first description is used. |
| </p><p> |
| The list of attributes available are: |
| </p><div class="variablelist"><dl><dt><span class="term">value</span></dt><dd><p> |
| The description of the Managed Object. |
| </p></dd></dl></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="jmx-managed-attribute"></a>@ManagedAttribute</h3></div></div></div><p> |
| The @ManagedAttribute annotation is used to indicate that a given method exposes a JMX attribute. This annotation is placed always on the reader method of a given attribute. Unless it is marked as read-only in the configuration of the annotation a corresponding setter is looked for following normal naming conventions. For example if this annotation is on a method called getFoo() then a method called setFoo() would be looked for and if found wired automatically into the jmx attribute. |
| </p><p> |
| The list of attributes available are: |
| </p><div class="variablelist"><dl><dt><span class="term">value</span></dt><dd><p> |
| The description of the Managed Attribute. |
| </p></dd><dt><span class="term">name</span></dt><dd><p> |
| The name of the Managed Attribute. |
| </p></dd><dt><span class="term">proxied</span></dt><dd><p> |
| Value is true if the corresponding mbean for this object contains the method of this JMX attribute in question. |
| </p></dd><dt><span class="term">readonly</span></dt><dd><p> |
| By default this value is false which means that a corresponding setter will be looked for an wired into the attribute should one be found. Setting this to true make the jmx attribute read only. |
| </p></dd><dt><span class="term">setter</span></dt><dd><p> |
| This attribute can be used when the corresponding setter for a JMX attribute follows a non-standard naming convention and it should still be exposed as the setter for the attribute. |
| </p></dd></dl></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="jmx-managed-operation"></a>@ManagedOperation</h3></div></div></div><p> |
| The @ManagedOperation annotation is used to indicate that a given method should be considered a JMX operation. |
| </p><p> |
| The list of attributes available are: |
| </p><div class="variablelist"><dl><dt><span class="term">value</span></dt><dd><p> |
| The description of the Managed Operation. |
| </p></dd><dt><span class="term">impact</span></dt><dd><p> |
| The impact of an operation. By default this value is "UNKNOWN" and acceptable values are "ACTION", "INFO", "ACTION_INFO" and should be used according to their definitions with JMX. |
| </p></dd><dt><span class="term">proxied</span></dt><dd><p> |
| Value is true if the corresponding mbean for this object contains the method of this JMX operation in question. |
| </p></dd></dl></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="jmx-name-annotation"></a>@Name</h3></div></div></div><p> |
| A fourth annotation is often used in conjuction with the JMX annotations mentioned above. This annotation is used to describe variables in method signatures so that when rendered into tools like JConsole it is clear what the parameters are. For example: |
| </p><p> |
| The list of attributes available are: |
| </p><div class="variablelist"><dl><dt><span class="term">value</span></dt><dd><p> |
| The name of the parameter. |
| </p></dd><dt><span class="term">description</span></dt><dd><p> |
| The description of the parameter. |
| </p></dd></dl></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="jmx-annotation-example"></a>Example</h3></div></div></div><p> |
| The following is an example of each of the annotations mentioned above in practice. |
| </p><div class="informalexample"><script type="syntaxhighlighter" class="brush: java;toolbar: false; highlight: [8, 13, 24, 25]"> |
| <![CDATA[ |
| |
| package com.acme; |
| |
| import org.eclipse.jetty.util.annotation.ManagedAttribute; |
| import org.eclipse.jetty.util.annotation.ManagedObject; |
| import org.eclipse.jetty.util.annotation.ManagedOperation; |
| import org.eclipse.jetty.util.annotation.Name; |
| |
| @ManagedObject("Test MBean Annotations") |
| public class Derived extends Base implements Signature |
| { |
| String fname="Full Name"; |
| |
| @ManagedAttribute(value="The full name of something", name="fname") |
| public String getFullName() |
| { |
| return fname; |
| } |
| |
| public void setFullName(String name) |
| { |
| fname=name; |
| } |
| |
| @ManagedOperation("Doodle something") |
| public void doodle(@Name(value="doodle", description="A description of the argument") String doodle) |
| { |
| System.err.println("doodle "+doodle); |
| } |
| } |
| |
| |
| ]]> |
| </script></div></div></div><script type="text/javascript"> |
| SyntaxHighlighter.all() |
| </script><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="jetty-jconsole.html"><i class="icon-chevron-left"></i> Previous</a> </td><td width="20%" align="center"><a accesskey="u" href="jmx-chapter.html"><i class="icon-chevron-up"></i> Top</a></td><td width="40%" align="right"> <a accesskey="n" href="alpn-chapter.html">Next <i class="icon-chevron-right"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Jetty JConsole </td><td width="20%" align="center"><a accesskey="h" href="index.html"><i class="icon-home"></i> Home</a></td><td width="40%" align="right" valign="top"> Chapter 14. ALPN</td></tr></table></div><p xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><div class="jetty-callout"> |
| See an error or something missing? |
| <span class="callout"><a href="http://github.com/jetty-project/jetty-documentation">Contribute to this documentation at |
| <span class="website"><i class="icon-github"></i> Github!</span></a></span><span style="float: right"><i>(Generated: 2015-06-15T13:18:22-05:00)</i></span></div></p><script xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" type="text/javascript"> |
| var _gaq = _gaq || []; |
| _gaq.push(['_setAccount', 'UA-1149868-7']); |
| _gaq.push(['_trackPageview']); |
| |
| (function() { |
| var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; |
| ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; |
| var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); |
| })(); |
| </script></body></html> |