/** * Create an active context that proxies a retry policy by choosing a target * from the policy map. * * @see org.springframework.retry.RetryPolicy#open(RetryContext) */ public RetryContext open(RetryContext parent) { return new ExceptionClassifierRetryContext(parent, exceptionClassifier).open(parent); }
/** * Returns false after the first exception. So there is always one try, and * then the retry is prevented. * * @see org.springframework.retry.RetryPolicy#canRetry(org.springframework.retry.RetryContext) */ public boolean canRetry(RetryContext context) { return !((NeverRetryContext) context).isFinished(); }
/** * Only permits a retry if the timeout has not expired. Does not check the * exception at all. * * @see org.springframework.retry.RetryPolicy#canRetry(org.springframework.retry.RetryContext) */ public boolean canRetry(RetryContext context) { return ((TimeoutRetryContext) context).isAlive(); }
public CircuitBreakerRetryPolicy() { this(new SimpleRetryPolicy()); }
/** * Setter for policy map used to create a classifier. Either this property * or the exception classifier directly should be set, but not both. * * @param policyMap a map of Throwable class to {@link RetryPolicy} that * will be used to create a {@link Classifier} to locate a policy. */ public void setPolicyMap(Map<Class<? extends Throwable>, RetryPolicy> policyMap) { this.exceptionClassifier = new SubclassClassifier<Throwable, RetryPolicy>(policyMap, new NeverRetryPolicy()); }
@Override public boolean canRetry(RetryContext context) { CircuitBreakerRetryContext circuit = (CircuitBreakerRetryContext) context; if (circuit.isOpen()) { circuit.incrementShortCircuitCount(); return false; } else { circuit.reset(); } return this.delegate.canRetry(circuit.context); }
public CircuitBreakerRetryContext(RetryContext parent, RetryPolicy policy, long timeout, long openWindow) { super(parent); this.policy = policy; this.timeout = timeout; this.openWindow = openWindow; this.context = createDelegateContext(policy, parent); setAttribute("state.global", true); }
/** * Get a status object that can be used to track the current operation * according to this policy. Has to be aware of the latest exception and the * number of attempts. * * @see org.springframework.retry.RetryPolicy#open(RetryContext) */ @Override public RetryContext open(RetryContext parent) { return new SimpleRetryContext(parent); }
/** * Update the status with another attempted retry and the latest exception. * * @see RetryPolicy#registerThrowable(RetryContext, Throwable) */ @Override public void registerThrowable(RetryContext context, Throwable throwable) { SimpleRetryContext simpleContext = ((SimpleRetryContext) context); simpleContext.registerThrowable(throwable); }
@Override public RetryContext open(RetryContext parent) { return new CircuitBreakerRetryContext(parent, this.delegate, this.resetTimeout, this.openTimeout); }
/** * Return a context that can respond to early termination requests, but does * nothing else. * * @see org.springframework.retry.RetryPolicy#open(RetryContext) */ public RetryContext open(RetryContext parent) { return new NeverRetryContext(parent); }
public ExpressionRetryPolicy withBeanFactory(BeanFactory beanFactory) { setBeanFactory(beanFactory); return this; }
public RetryContext open(RetryContext parent) { return new TimeoutRetryContext(parent, timeout); }
public void put(Object key, RetryContext context) { if (map.size() >= capacity) { throw new RetryCacheCapacityExceededException("Retry cache capacity limit breached. " + "Do you need to re-consider the implementation of the key generator, " + "or the equals and hashCode of the items that failed?"); } map.put(key, context); }
public void reset() { shortCircuitCount.set(0); setAttribute(CIRCUIT_SHORT_COUNT, shortCircuitCount.get()); }
/** * Make the throwable available for downstream use through the context. * @see org.springframework.retry.RetryPolicy#registerThrowable(org.springframework.retry.RetryContext, * Throwable) */ public void registerThrowable(RetryContext context, Throwable throwable) { ((NeverRetryContext) context).setFinished(); ((RetryContextSupport) context).registerThrowable(throwable); }
private RetryContext createDelegateContext(RetryPolicy policy, RetryContext parent) { RetryContext context = policy.open(parent); reset(); return context; }
@Override public void registerThrowable(RetryContext context, Throwable throwable) { CircuitBreakerRetryContext circuit = (CircuitBreakerRetryContext) context; circuit.registerThrowable(throwable); this.delegate.registerThrowable(circuit.context, throwable); }
/** * Test for retryable operation based on the status. * * @see org.springframework.retry.RetryPolicy#canRetry(org.springframework.retry.RetryContext) * * @return true if the last exception was retryable and the number of * attempts so far is less than the limit. */ @Override public boolean canRetry(RetryContext context) { Throwable t = context.getLastThrowable(); return (t == null || retryForException(t)) && context.getRetryCount() < maxAttempts; }
public StatefulRetryOperationsInterceptor() { RetryTemplate retryTemplate = new RetryTemplate(); retryTemplate.setRetryPolicy(new NeverRetryPolicy()); this.retryOperations = retryTemplate; }