use of com.peterphi.std.guice.common.retry.retry.RetryManager in project stdlib by petergeneric.
the class RetryMethodInterceptor method invoke.
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable {
Timer.Context timer = this.calls.time();
try {
final Retry options = invocation.getMethod().getAnnotation(Retry.class);
final RetryManager mgr = buildRetryManager(options);
if (log.isTraceEnabled())
log.trace("Attempting retryable invoke of " + invocation.getMethod().toGenericString() + " on " + invocation.getThis() + " with " + Arrays.asList(invocation.getArguments()));
return mgr.run(new InvocationRetryable(invocation, options.on(), options.exceptOn(), options.exceptOnCore(), options.exceptOnRestExceptionCodes()));
} catch (Throwable t) {
totalFailures.mark();
if (log.isTraceEnabled())
log.trace("Retrying invoke of " + invocation.getMethod().toGenericString() + " on " + invocation.getThis() + " with " + Arrays.asList(invocation.getArguments()) + " failed.", t);
throw t;
} finally {
timer.stop();
}
}
use of com.peterphi.std.guice.common.retry.retry.RetryManager in project stdlib by petergeneric.
the class RetryMethodInterceptor method buildRetryManager.
private RetryManager buildRetryManager(Retry options) {
final Timeout initial = new Timeout(options.backoffTime(), options.backoffUnit());
ExponentialBackoff backoff = new ExponentialBackoff(initial, options.backoffExponent());
return new RetryManager(backoff, options.maxAttempts(), attempts, attemptFailures);
}
Aggregations