01: /*
02: @COPYRIGHT@
03: */
04: package demo.jmx;
05:
06: import java.util.HashMap;
07: import java.util.Map;
08: import org.aopalliance.intercept.MethodInterceptor;
09: 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 implements MethodInterceptor {
16: private Map queues = new HashMap();
17:
18: public void setQueues(Map queues) {
19: this .queues = queues;
20: }
21:
22: /**
23: * Advice method updating perfrormance metrics
24: * @see org.aopalliance.intercept.MethodInterceptor#invoke(MethodInvocation invocation)
25: */
26: public Object invoke(MethodInvocation invocation) throws Throwable {
27: String error = null;
28: try {
29: return invocation.proceed();
30:
31: } catch (Throwable t) {
32: error = t.toString();
33: throw t;
34:
35: } finally {
36: String name = ((ICounter) invocation.getThis()).getName();
37: HistoryQueue historyQueue = (HistoryQueue) queues.get(name);
38: if (historyQueue != null)
39: historyQueue.updateHistory(0, error);
40: }
41: }
42: }
|