1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.maxur.perfmodel.backend.service;
17
18 import com.ecyrd.speed4j.StopWatch;
19 import com.ecyrd.speed4j.StopWatchFactory;
20 import org.aopalliance.intercept.MethodInterceptor;
21 import org.aopalliance.intercept.MethodInvocation;
22
23 import java.lang.reflect.Method;
24
25
26
27
28
29
30
31
32
33
34
35
36 public class BenchmarkMethodInterceptor implements MethodInterceptor {
37
38 private final StopWatchFactory stopWatchFactory = StopWatchFactory.getInstance("loggingFactory");
39
40
41
42
43
44
45 @Override
46 public Object invoke(MethodInvocation invocation) throws Throwable {
47 final Method method = invocation.getMethod();
48 final StopWatch stopWatch = stopWatchFactory.getStopWatch();
49 final String className = method.getDeclaringClass().getSimpleName();
50 final String methodName = method.getName();
51 try {
52 Object result = invocation.proceed();
53 stopWatch.stop(className + " " + methodName + " : success");
54 return result;
55 } catch (Exception e) {
56 stopWatch.stop(className + " " + methodName + " : error");
57 throw e;
58 }
59 }
60
61 }