class MonitoredMethodCall {
private static final Logger LOG = LoggerFactory.getLogger(MonitoredMethodCall.class);
public Object call(ProceedingJoinPoint pjp, PassiveMethodMonitor monitor) throws Throwable {
ErrorCountingPolicy errorCountingPolicy = monitor.getErrorCountingPolicy();
Throwable error = null;
Object ret = null;
try {
ret = pjp.proceed();
return ret;
} catch (Throwable t) {
error = t;
throw t;
} finally {
if (error != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Got a Throwable in monitor: " + monitor.getName(), error);
}
if (errorCountingPolicy.countsAsError(error)) {
monitor.failure(error);
} else {
monitor.success();
}
} else {
if (errorCountingPolicy.countsAsError(ret)) {
monitor.failure("Got return value which is considered an error: " + ret);
} else {
monitor.success();
}
}