public class BenchmarkProxyConfigurator
implements ProxyConfigurator {
@Override
public <T> T wrapWithPoxy(T t, Class<? extends T> type) {
boolean isProxyNeeded = type.isAnnotationPresent(Benchmark.class)
|| !ReflectionUtils.getAllMethods(type, method ->
method.isAnnotationPresent(Benchmark.class)).isEmpty();
if (isProxyNeeded) {
return (T) Proxy.newProxyInstance(type.getClassLoader(),
type.getInterfaces(),
(proxy, method, args) -> {
Method classMethod = type.getMethod(method.getName(),
method.getParameterTypes());
return invoke(t, type, method, args, classMethod);
});
}
return t;
}}