blob: 6660722c5d883bea6dc959ecdb095c034ef2d30a [file] [log] [blame]
<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 Stylesheets V1.79.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"><link rel="up" href="jmx-chapter.html" title="Chapter&nbsp;14.&nbsp;Java Management Extensions (JMX)"><link rel="prev" href="jmx-chapter.html" title="Chapter&nbsp;14.&nbsp;Java Management Extensions (JMX)"><link rel="next" href="jetty-jconsole.html" title="Managing Jetty with JConsole and JMC"><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"><link rel="stylesheet" href="css/highlighter/foundation.css"><script src="js/highlight.pack.js"></script><script>
hljs.initHighlightingOnLoad();
</script><link type="text/css" rel="stylesheet" href="css/font-awesome/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.4.28-SNAPSHOT</span></td><td style="width: 50%"></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="jmx-chapter.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;14.&nbsp;Java Management Extensions (JMX)<br><a accesskey="p" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></th><td width="20%" align="right">&nbsp;<a accesskey="n" href="jetty-jconsole.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></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 for sponsored feature development
</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 class="toc"><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 <code class="literal">jetty-jmx</code> 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="literal">com.acme.Foo</code>:</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">All influences for <code class="literal">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="literal">com.acme.jmx.FooMBean</code>.
All super classes and their corresponding MBean representations are then used in the next step.</li><li class="listitem">Each potential influencing class is checked for the <code class="literal">@ManagedObject</code> annotation.
Should this annotation exist at any point in the chain of influencers then an MBran is created with the description of the version <code class="literal">@ManagedObject</code> discovered.</li><li class="listitem">Once a MBean has been created for an object then each potential influencing object is introspected for <code class="literal">@ManagedAttribute</code> and <code class="literal">@ManagedOperation</code> annotations and the corresponding type is exposed to the MBean.</li></ol></div><p>The convention of looking for <code class="literal">@ManagedObject</code> annotations on <code class="literal">.jmx.ClassMBean</code> allows for a normal POJOs 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 <code class="literal">@ManagedObject</code> 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 <code class="literal">@ManagedObject</code> 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 class="variablelist"><dt><span class="term">value</span></dt><dd>The description of the Managed Object.</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 <code class="literal">@ManagedAttribute</code> 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 <code class="literal">getFoo()</code> then a method called <code class="literal">setFoo()</code> 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 class="variablelist"><dt><span class="term">value</span></dt><dd>The description of the Managed Attribute.</dd><dt><span class="term">name</span></dt><dd>The name of the Managed Attribute.</dd><dt><span class="term">proxied</span></dt><dd>Value is true if the corresponding MBean for this object contains the method of this JMX attribute in question.</dd><dt><span class="term">readonly</span></dt><dd>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.</dd><dt><span class="term">setter</span></dt><dd>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.</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 <code class="literal">@ManagedOperation</code> 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 class="variablelist"><dt><span class="term">value</span></dt><dd>The description of the Managed Operation.</dd><dt><span class="term">impact</span></dt><dd>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.</dd><dt><span class="term">proxied</span></dt><dd>Value is true if the corresponding MBean for this object contains the method of this JMX operation in question.</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 conjunction 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 class="variablelist"><dt><span class="term">value</span></dt><dd>The name of the parameter.</dd><dt><span class="term">description</span></dt><dd>The description of the parameter.</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><pre 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"><code>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);
}
}</code></pre></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="jmx-chapter.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="jmx-chapter.html"><i class="fa fa-chevron-up" aria-hidden="true"></i> Top</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="jetty-jconsole.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&nbsp;14.&nbsp;Java Management Extensions (JMX)&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></td><td width="40%" align="right" valign="top">&nbsp;Managing Jetty with JConsole and JMC</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/eclipse/jetty.project">Contribute to this documentation at
<span class="website"><i class="fa fa-github" aria-hidden="true"></i> Github!</span></a></span><span style="float: right"><i>(Generated: 2020-03-10)</i></span></div></p></body></html>