Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
AWare
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<h2>Purpose</h2> <p>The purpose of this aspect is to report arbitrary method execution response time to a JMX server.<br /> It is easily configurable to gather the metrics on a per class, package, application, etc basis and thus report averages metrics as well.</p> <p>This aspect has been demonstrated during JavaOne 2004 in the "AOP in J2EE environments with AspectWerkz" session.<br /> <a href="http://aspectwerkz.codehaus.org/downloads/papers/JavaOne2004-TS1391-J2EEAOP.pdf">Download the JavaOne 2004 slides</a>.</p> <h2>Usage</h2> <p>In order to be able to use this aspect, you need to declare it in your <strong>META-INF/aop.xml</strong> file and bind the advice named <strong>"monitor"</strong> of type <strong>"around"</strong> to any method execution pointcuts (actually it can work for any pointcut type if you want to).</p> <p>One JMX mbean will be created per target method/constructor/field signature by default. See the next section for more configuration about the aspect parameter <strong>"granularity"</strong>.</p> <p>The mbeans will be registered <em>lazyly</em> in the default (local) JMX server. For use with BEA WebLogic Server 6, 7 and 8 and for other schemes, see the next section about the aspect parameter <strong>"mbeanServer"</strong>.</p> <p>Here is a sample <em>META-INF/aop.xml</em> file:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="xml" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6eG1sfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <!DOCTYPE aspectwerkz PUBLIC "-//AspectWerkz//DTD//EN" "http://aspectwerkz.codehaus.org/dtd/aspectwerkz.dtd"> <aspectwerkz> <system id="aware-jmx"> <!-- make use of defaults granularity and server --> <aspect class="org.codehaus.aware.jmx.ResponseTimeAspect"> <advice name="monitor" type="around" bind-to="execution(!static * test.jmx.ResponseTimeObject.*(..)) AND !execution(* *..*.freeze(..))"/> </aspect> </system> </aspectwerkz> </pre></td></tr></table> <h2>Reporting response time averages</h2> <p>To change the granularity of the reported metrics, which defaults to <em>one mbean per target method/constructor/field signature</em> you need to use the <em>aspect parameter</em> <strong>"granularity"</strong>.</p> <p>This parameter will specify a class that implements the <em>org.codehaus.aware.jmx.ResponseTimeAspect.IGranularity</em> interface below:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="java" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6amF2YX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> public class ResponseTimeAspect { /** * Granularity interface to determine which mbean to update given a specific joinpoint signature. * */ public static interface IGranularity { /** * Compute a suitable key given a signature. The mbeans will be register on a per key basis, and it is thus * advised to have suitable hashcode(), equals() and toString() implementation for it. * * @param signature * @return */ public Object getKeyFor(Signature signature); } } </pre></td></tr></table> <p>AWare provides an implementation which is able to compute a global average. Here is how it has been written. You can refer to AspectWerkz documentation about the <em>org.codehaus.aspectwerkz.joinpoint.Signature</em> interface to write your own:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="java" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6amF2YX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> public class AverageGranularity implements IGranularity { public Object getKeyFor(Signature signature) { // to compute a global average, just always return the same value return "Average"; } } </pre></td></tr></table> <p>This class is provided in AWare as org.codehaus.aware.jmx.ResponseTimeAspect.AverageGranularity. Since it is a static inner class, we will have to use it under the name "org.codehaus.aware.jmx.ResponseTimeAspect$AverageGranularity" (with a <strong>$</strong> sign) :</p> <p>To use your custom granularity the <em>META-INF/aop.xml</em> file will look like the following. Note that we are using the ResponseTimeAspect twice, once with default granularity and once with average granularity, and thus we specify an aspect <strong>"name"</strong>.</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="xml" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6eG1sfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <!DOCTYPE aspectwerkz PUBLIC "-//AspectWerkz//DTD//EN" "http://aspectwerkz.codehaus.org/dtd/aspectwerkz.dtd"> <aspectwerkz> <system id="aware-jmx"> <!-- make use of defaults granularity and server --> <aspect class="org.codehaus.aware.jmx.ResponseTimeAspect"> <advice name="monitor" type="around" bind-to="execution(!static * test.jmx.ResponseTimeObject.*(..)) AND !execution(* *..*.freeze(..))"/> </aspect> <!-- make use of custom granularity --> <aspect class="org.codehaus.aware.jmx.ResponseTimeAspect" name="MyAverageResponseTimeAspect"> <param name="granularity" value="org.codehaus.aware.jmx.ResponseTimeAspect$AverageGranularity"/> <advice name="monitor" type="around" bind-to="execution(!static * test.jmx.ResponseTimeObject.*(..)) AND !execution(* *..*.freeze(..))"/> </aspect> </system> </aspectwerkz> </pre></td></tr></table> <h2>Using a specific JMX mbean server</h2> <p>The default AWare implementation is using the default JMX API to retrieve the local JMX server and register the mbeans:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="java" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6amF2YX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> public class JMXHelper { /** * Default driver interface using javax.management.MBeanServerFactory. * See MX4JAspect if using it with MX4J jmx server. * */ public static class StandardMBeanServerDriver implements IMBeanServerDriver { public MBeanServer findMBeanServer() throws Throwable { return javax.management.MBeanServerFactory.createMBeanServer(); } } } </pre></td></tr></table> <p>This might not be convenient in your environment. For example in BEA WebLogic, you have several JMX server available when you are running in a cluster or in a managed server environment.</p> <p>AWare allows you to use the mbean server you like.<br /> For such use the aspect parameter <strong>"mbeanServer"</strong> and specify a class that implements the <em>org.codehaus.aware.jmx.JMXHelper.IMBeanServerDriver</em> interface:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="java" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6amF2YX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> public interface IMBeanServerDriver { public MBeanServer findMBeanServer() throws Throwable; } </pre></td></tr></table> <p>AWare provides a BEA Weblogic implementation of it thru <strong>org.codehaus.aware.jmx.JMXHelper.WebLogicMBeanServerDriver</strong>.</p> <p>To use it, the <em>META-INF/aop.xml</em> will looks like:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="xml" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6eG1sfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <aspectwerkz> <system id="aware-jmx"> <!-- make use of defaults granularity and use WebLogic mbean server custom lookup --> <aspect class="org.codehaus.aware.jmx.ResponseTimeAspect"> <param name="mbeanServer" value="org.codehaus.aware.jmx.JMXHelper$WebLogicMBeanServerDriver"/> <advice name="monitor" type="around" bind-to="execution(!static * test.jmx.ResponseTimeObject.*(..)) AND !execution(* *..*.freeze(..))"/> </aspect> </system> </aspectwerkz> </pre></td></tr></table>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced