01 /**
02 *
03 * All content copyright (c) 2003-2008 Terracotta, Inc.,
04 * except as may otherwise be noted in a separate copyright notice.
05 * All rights reserved.
06 *
07 */
08 package demo.jmx;
09
10 import java.util.HashMap;
11 import java.util.Map;
12 import org.aopalliance.intercept.MethodInterceptor;
13 import org.aopalliance.intercept.MethodInvocation;
14
15 /**
16 * Advice bean used to capture performance metrics per time interval and to
17 * expose collected data trough JMX
18 *
19 *@author Terracotta, Inc.
20 */
21 public class CounterHistoryAdvice
22 implements MethodInterceptor {
23 private Map queues = new HashMap();
24
25 public void setQueues(Map queues) {
26 this.queues = queues;
27 }
28
29 /**
30 * Advice method updating perfrormance metrics
31 *
32 *@param invocation Description of Parameter
33 *@return Description of the Returned Value
34 *@exception Throwable Description of Exception
35 *@see org.aopalliance.intercept.MethodInterceptor#invoke(MethodInvocation
36 * invocation)
37 */
38 public Object invoke(MethodInvocation invocation)
39 throws Throwable {
40 String error = null;
41 try {
42 return invocation.proceed();
43 }
44 catch (Throwable t) {
45 error = t.toString();
46 throw t;
47 }
48 finally {
49 String name = ((ICounter) invocation.getThis()).getName();
50 HistoryQueue historyQueue = (HistoryQueue) queues.get(name);
51 if (historyQueue != null) {
52 historyQueue.updateHistory(0, error);
53 }
54 }
55 }
56 }
|