1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jdiagnose.library.aop;
17
18 import java.lang.reflect.Method;
19
20 import org.aopalliance.intercept.MethodInterceptor;
21 import org.aopalliance.intercept.MethodInvocation;
22 import org.jdiagnose.remote.Agent;
23 import org.jdiagnose.remote.RemoteResultListener;
24 import org.jdiagnose.remote.template.DiagnosticCallback;
25 import org.jdiagnose.remote.template.DiagnosticServiceSupport;
26
27 /***
28 * @author jmccrindle
29 */
30 public class DiagnosticInterceptor extends DiagnosticServiceSupport implements MethodInterceptor {
31
32 private String name = null;
33 private Agent remoteResultFactory;
34
35 public DiagnosticInterceptor(Agent agent, String name, RemoteResultListener listener, boolean filterSuccesses) {
36 super(agent, listener, filterSuccesses);
37 this.name = name;
38 this.remoteResultFactory = agent;
39 }
40
41 public DiagnosticInterceptor(Agent agent, RemoteResultListener listener) {
42 super(agent, listener);
43 this.remoteResultFactory = agent;
44 }
45
46
47
48
49 public Object invoke(final MethodInvocation methodInvocation) throws Throwable {
50 Method method = methodInvocation.getMethod();
51 if(name == null) {
52 name = method.getDeclaringClass().getName();
53 }
54 return getDiagnosticTemplate().execute(name + "." + method.toString(), new DiagnosticCallback() {
55 public Object invoke() throws Throwable {
56 return methodInvocation.proceed();
57 }
58 });
59 }
60
61 }