protected <E extends Throwable> void rethrow(RetryContext context, String message) throws E { if (this.throwLastExceptionOnExhausted) { @SuppressWarnings("unchecked") E rethrow = (E) context.getLastThrowable(); throw rethrow; } else { throw new ExhaustedRetryException(message, context.getLastThrowable()); } }
/** * Extension point for subclasses to decide on behaviour after catching an exception * in a {@link RetryCallback}. Normal stateless behaviour is not to rethrow, and if * there is state we rethrow. * * @param retryPolicy the retry policy * @param context the current context * @param state the current retryState * @return true if the state is not null but subclasses might choose otherwise */ protected boolean shouldRethrow(RetryPolicy retryPolicy, RetryContext context, RetryState state) { return state != null && state.rollbackFor(context.getLastThrowable()); }
private <T, E extends Throwable> boolean doOpenInterceptors( RetryCallback<T, E> callback, RetryContext context) { boolean result = true; for (RetryListener listener : this.listeners) { result = result && listener.open(context, callback); } return result; }
private void registerContext(RetryContext context, RetryState state) { if (state != null) { Object key = state.getKey(); if (key != null) { if (context.getRetryCount() > 1 && !this.retryContextCache.containsKey(key)) { throw new RetryException( "Inconsistent state for failed item key: cache key has changed. " + "Consider whether equals() or hashCode() for the key might be inconsistent, " + "or if you need to supply a better key"); } this.retryContextCache.put(key, context); } } }
private RetryContext doOpenInternal(RetryPolicy retryPolicy, RetryState state) { RetryContext context = retryPolicy.open(RetrySynchronizationManager.getContext()); if (state != null) { context.setAttribute(RetryContext.STATE_KEY, state.getKey()); } if (context.hasAttribute(GLOBAL_STATE)) { registerContext(context, state); } return context; }
@Override public int getRetryCount() { return this.context.getRetryCount(); }
/** * Decide whether to proceed with the ongoing retry attempt. This method is called * before the {@link RetryCallback} is executed, but after the backoff and open * interceptors. * * @param retryPolicy the policy to apply * @param context the current retry context * @return true if we can continue with the attempt */ protected boolean canRetry(RetryPolicy retryPolicy, RetryContext context) { return retryPolicy.canRetry(context); }
private String getName(RetryContext context) { return (String) context.getAttribute(RetryContext.NAME); } }
@Override public void close(RetryContext context) { CircuitBreakerRetryContext circuit = (CircuitBreakerRetryContext) context; this.delegate.close(circuit.context); }
private boolean isGlobal(RetryContext context) { return context.hasAttribute("state.global"); }
private <T, E extends Throwable> void doOnErrorInterceptors( RetryCallback<T, E> callback, RetryContext context, Throwable throwable) { for (int i = this.listeners.length; i-- > 0;) { this.listeners[i].onError(context, callback, throwable); } }
private <T, E extends Throwable> void doCloseInterceptors( RetryCallback<T, E> callback, RetryContext context, Throwable lastException) { for (int i = this.listeners.length; i-- > 0;) { this.listeners[i].close(context, callback, lastException); } }
/** * Delegate to the policy currently activated in the context. * * @see org.springframework.retry.RetryPolicy#canRetry(org.springframework.retry.RetryContext) */ public boolean canRetry(RetryContext context) { RetryPolicy policy = (RetryPolicy) context; return policy.canRetry(context); }
/** * Delegate to the policy currently activated in the context. * * @see org.springframework.retry.RetryPolicy#close(org.springframework.retry.RetryContext) */ public void close(RetryContext context) { RetryPolicy policy = (RetryPolicy) context; policy.close(context); }
private boolean isExhausted(RetryContext context) { return context.hasAttribute(RetryContext.EXHAUSTED); }
public boolean canRetry(RetryContext context) { return context==null ? true : retryPolicy.canRetry(context); }
private boolean isClosed(RetryContext context) { return context.hasAttribute(RetryContext.CLOSED); }
public boolean canRetry(RetryContext context) { return this.context == null || policy.canRetry(this.context); }
private boolean hasState(RetryContext context) { return context.hasAttribute(RetryContext.STATE_KEY); }
private boolean isRecovered(RetryContext context) { return context.hasAttribute(RetryContext.RECOVERED); }