KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > jmx > CounterHistoryAdvice


1 /*
2 @COPYRIGHT@
3 */

4 package demo.jmx;
5
6 import java.util.HashMap JavaDoc;
7 import java.util.Map JavaDoc;
8 import org.aopalliance.intercept.MethodInterceptor;
9 import org.aopalliance.intercept.MethodInvocation;
10
11 /**
12 * Advice bean used to capture performance metrics
13 * per time interval and to expose collected data trough JMX
14 */

15 public class CounterHistoryAdvice
16 implements MethodInterceptor
17 {
18    private Map JavaDoc queues = new HashMap JavaDoc();
19
20    public void setQueues(Map JavaDoc queues)
21    {
22       this.queues = queues;
23    }
24
25    /**
26    * Advice method updating perfrormance metrics
27    * @see org.aopalliance.intercept.MethodInterceptor#invoke(MethodInvocation invocation)
28    */

29    public Object JavaDoc invoke(MethodInvocation invocation)
30    throws Throwable JavaDoc
31    {
32       String JavaDoc error = null;
33       try
34       {
35          return invocation.proceed();
36
37       }
38       catch(Throwable JavaDoc t)
39       {
40          error = t.toString();
41          throw t;
42
43       }
44       finally
45       {
46          String JavaDoc name = ((ICounter) invocation.getThis()).getName();
47          HistoryQueue historyQueue = (HistoryQueue) queues.get(name);
48          if(historyQueue!=null) historyQueue.updateHistory(0, error);
49       }
50    }
51 }
52
Popular Tags