Search in sources :

Example 1 with RetryManager

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();
    }
}
Also used : Timer(com.codahale.metrics.Timer) RetryManager(com.peterphi.std.guice.common.retry.retry.RetryManager) Retry(com.peterphi.std.guice.common.retry.annotation.Retry)

Example 2 with RetryManager

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);
}
Also used : Timeout(com.peterphi.std.threading.Timeout) RetryManager(com.peterphi.std.guice.common.retry.retry.RetryManager) ExponentialBackoff(com.peterphi.std.guice.common.retry.retry.backoff.ExponentialBackoff)

Aggregations

RetryManager (com.peterphi.std.guice.common.retry.retry.RetryManager)2 Timer (com.codahale.metrics.Timer)1 Retry (com.peterphi.std.guice.common.retry.annotation.Retry)1 ExponentialBackoff (com.peterphi.std.guice.common.retry.retry.backoff.ExponentialBackoff)1 Timeout (com.peterphi.std.threading.Timeout)1