ryantenney/metrics-spring — pull request #95 by rajuky (2014-11-21 18:38:19+00:00)
Title: Update AbstractMetricMethodInterceptor.java

Would like to create a custom interceptor so that it can be integrated with MetricsFramework.
I want to count a set of exceptions as client exceptions ->(SocketTimeOutException,OutofMemoryException, IOException)
would like to create a custom interceptor like the following and integrate it with a new custom annotation public @interface SystemExceptionMetered and apply it on methods.
1.SystemExceptionMeteredInterceptor extends AbstractMetricMethodInterceptor implements Ordered
2.implement the invoke method as follows
@Override
protected Object invoke(MethodInvocation invocation, Meter meter, SystemExceptionMetered annotation) throws Throwable {
try {
return invocation.proceed();
}
catch (SocketTimeOutException t) {
if (annotation.cause().isAssignableFrom(t.getClass())) {
meter.mark();
}
throw t;
}
catch (OutofMemoryException t) {
if (annotation.cause().isAssignableFrom(t.getClass())) {
meter.mark();
}
throw t;
}
catch (IOException t) {
if (annotation.cause().isAssignableFrom(t.getClass())) {
meter.mark();
}
throw t;
}
}