1
2
3
4
5 package net.sf.crispy.interceptor;
6
7 import net.sf.crispy.Interceptor;
8 import net.sf.crispy.InterceptorContext;
9
10 /**
11 * Mini stopwatch.
12 *
13 * @author Linke
14 *
15 */
16 public class StopWatchInterceptor implements Interceptor {
17
18 private long startTimeNewInstance = 0;
19 private long endTimeNewInstance = -1;
20 private long startTimeInvokeMethod = 0;
21 private long endTimeInvokeMethod = -1;
22
23 private int onErrorCounter = 0;
24
25 /**
26 * @see net.sf.crispy.Interceptor#beforeNewInstance(java.lang.Class)
27 */
28 public void beforeNewInstance(Class pvInterfaceClass) {
29 startTimeNewInstance = System.currentTimeMillis();
30 }
31
32 /**
33 * @see net.sf.crispy.Interceptor#afterNewInstance(java.lang.Class, java.lang.Object)
34 */
35 public void afterNewInstance(Class pvInterfaceClass, Object pvProxyObject) {
36 endTimeNewInstance = System.currentTimeMillis() - startTimeNewInstance;
37 }
38
39
40
41 /**
42 * @see net.sf.crispy.Interceptor#beforeMethodInvocation(net.sf.crispy.InterceptorContext)
43 */
44 public void beforeMethodInvocation(InterceptorContext pvInterceptorContext) {
45 startTimeInvokeMethod = System.currentTimeMillis();
46 }
47
48 /**
49 * @see net.sf.crispy.Interceptor#afterMethodInvocation(net.sf.crispy.InterceptorContext)
50 */
51 public void afterMethodInvocation(InterceptorContext pvInterceptorContext) {
52 endTimeInvokeMethod = System.currentTimeMillis() - startTimeInvokeMethod;
53 }
54
55 /**
56 * @see net.sf.crispy.Interceptor#onError(java.lang.Throwable)
57 */
58 public void onError(Throwable pvThrowable) { ++onErrorCounter; }
59
60 public long getStopTimeNewInstance() { return endTimeNewInstance; }
61 public long getStopTimeInvokeMethod() { return endTimeInvokeMethod; }
62
63 public int getOnErrorCounter() { return onErrorCounter; }
64
65 public void clearStopTimeInvokeMethod() { endTimeInvokeMethod = 0; }
66 public void clearStopTimeNewInstance() { endTimeNewInstance = 0; }
67 }