01: package com.jamonapi.aop;
02:
03: import javax.interceptor.AroundInvoke;
04: import javax.interceptor.InvocationContext;
05: import com.jamonapi.MonitorFactory;
06: import com.jamonapi.Monitor;
07: import com.jamonapi.MonKeyImp;
08: import com.jamonapi.utils.Misc;
09:
10: public class JAMonEJBInterceptor {
11: private static final String EXCEPTION_STR = "JAMonEJBInterceptor.EJBException";
12: private static final int EXCEPTION = 1;
13:
14: @AroundInvoke
15: public Object intercept(InvocationContext ctx) throws Exception {
16: Object[] details = null;
17: Monitor mon = null;
18: String label = null;
19:
20: try {
21: label = new StringBuffer("JAMonEJBInterceptor: ").append(
22: ctx.getTarget().getClass().getName()).append(".")
23: .append(ctx.getMethod().getName()).toString();
24: details = new Object[] { label, "" };
25: mon = MonitorFactory.start(new MonKeyImp(label, details,
26: "ms."));
27: return ctx.proceed();
28: } catch (Exception e) {
29: details[EXCEPTION] = Misc.getExceptionTrace(e);
30: MonitorFactory.add(new MonKeyImp(EXCEPTION_STR, details,
31: "Exception"), 1);
32: MonitorFactory.add(new MonKeyImp(
33: MonitorFactory.EXCEPTIONS_LABEL, details,
34: "Exception"), 1);
35: throw e;
36: } finally {
37: mon.stop();
38: }
39: }
40:
41: public String delme(String hello) throws Exception {
42: return "hello";
43: }
44:
45: public static void main(String[] args) throws Exception {
46: JAMonEJBInterceptor o = new JAMonEJBInterceptor();
47: System.out.println(o.getClass().getMethod("delme",
48: new Class[] { String.class }));
49: }
50:
51: }
|