comparison src/org/dancres/blitz/remote/debug/TimingInvocationHandler.java @ 0:3dc0c5604566

Initial checkin of blitz 2.0 fcs - no installer yet.
author Dan Creswell <dan.creswell@gmail.com>
date Sat, 21 Mar 2009 11:00:06 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:3dc0c5604566
1 package org.dancres.blitz.remote.debug;
2
3 import java.lang.reflect.Method;
4
5 import net.jini.jeri.BasicInvocationHandler;
6 import net.jini.jeri.ObjectEndpoint;
7
8 import net.jini.core.constraint.MethodConstraints;
9
10 /**
11 <p><code>TimingInvocationHandler</code>, dispatches all remote
12 invocations as normal whilst reporting the time taken to execute the call.
13 This can be used to locate "bottlenecks" in remote service configurations.
14 </p>
15
16 <p>NOTE: Using this handler in combination with clients which stipulate
17 verification when preparing proxies is doomed to failure because there
18 isn't currently a suitable <code>TrustVerifier</code>. You could, of
19 course, adopt the brute force approach of putting this code in all
20 client classpaths.....</p>
21
22 @todo Code up TrustVerifier for this InvocationHandler
23 */
24 public class TimingInvocationHandler extends BasicInvocationHandler {
25 public TimingInvocationHandler(ObjectEndpoint anEndpoint,
26 MethodConstraints aServerConstraints) {
27 super(anEndpoint, aServerConstraints);
28 }
29
30 public TimingInvocationHandler(BasicInvocationHandler aHandler,
31 MethodConstraints aClientConstraints) {
32 super(aHandler, aClientConstraints);
33 }
34
35 public Object invoke(Object aProxy, Method aMethod, Object[] anArgs)
36 throws Throwable {
37 long myStart = System.currentTimeMillis();
38
39 Object myResult = super.invoke(aProxy, aMethod, anArgs);
40
41 long myEnd = System.currentTimeMillis();
42
43 System.err.println("Method: " + aMethod + ": " + (myEnd - myStart) +
44 " ms (" + myStart + ")");
45
46 return myResult;
47 }
48 }