1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jdiagnose.remote.template;
17
18 import java.lang.reflect.InvocationHandler;
19 import java.lang.reflect.Method;
20
21 import org.jdiagnose.remote.Agent;
22 import org.jdiagnose.remote.RemoteResultListener;
23
24
25 /***
26 * @author jmccrindle
27 */
28 public class DiagnosticProxy extends DiagnosticServiceSupport implements InvocationHandler {
29
30 private Object delegate = null;
31 private String name = null;
32
33 public DiagnosticProxy() {
34 super();
35 }
36
37 public DiagnosticProxy(Agent agent, String name, Object delegate, RemoteResultListener listener, boolean filterSuccesses) {
38 super(agent, listener, filterSuccesses);
39 this.delegate = delegate;
40 this.name = name;
41 }
42
43
44
45
46 public Object invoke(Object proxy, final Method method, final Object[] args) throws Throwable {
47 return getDiagnosticTemplate().execute(name + "." + method.toString(), new DiagnosticCallback() {
48 public Object invoke() throws Throwable {
49 Method delegateMethod = delegate.getClass().getMethod(method.getName(), method.getParameterTypes());
50 return delegateMethod.invoke(delegate, args);
51 }
52 });
53 }
54
55 /***
56 * @param remoteResult The remoteResult to set.
57 */
58 public void setDelegate(Object delegate) {
59 this.delegate = delegate;
60 }
61 /***
62 * @param name The name to set.
63 */
64 public void setName(String name) {
65 this.name = name;
66 }
67 }