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()); } }
@Override public Object recover(RetryContext context) { return this.recoverer.recover(this.args, 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()); }
public Object recover(RetryContext context) { return recoverer.recover(args, context.getLastThrowable()); }
@Override public boolean canRetry(RetryContext context) { Throwable lastThrowable = context.getLastThrowable(); if (lastThrowable == null) { return super.canRetry(context); } else { return super.canRetry(context) && this.expression.getValue(this.evaluationContext, lastThrowable, Boolean.class); } }
@Override public Object recover(RetryContext context) throws Exception { /* * If the last exception was not skippable we don't need to * do any scanning. We can just bomb out with a retry * exhausted. */ if (!shouldSkip(itemWriteSkipPolicy, context.getLastThrowable(), -1)) { throw new ExhaustedRetryException( "Retry exhausted after last attempt in recovery path, but exception is not skippable.", context.getLastThrowable()); } inputs.setBusy(true); data.scanning(true); scan(contribution, inputs, outputs, chunkMonitor, true); return null; }
public BatchRetryContext(RetryContext parent, Collection<RetryContext> contexts) { super(parent); this.contexts = contexts; int count = 0; for (RetryContext context : contexts) { int retryCount = context.getRetryCount(); if (retryCount > count) { count = retryCount; registerThrowable(context.getLastThrowable()); } } }
/** * 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; }
@Override public O recover(RetryContext context) throws Exception { Throwable e = context.getLastThrowable(); if (shouldSkip(skipPolicy, e, contribution.getStepSkipCount())) { contribution.incrementWriteSkipCount(); logger.debug("Skipping after failed write", e); return null; } else { if (rollbackClassifier.classify(e)) { // Default is to rollback unless the classifier // allows us to continue throw new RetryException("Non-skippable exception in recoverer while write", e); } return null; } }
@Override public I recover(RetryContext context) throws Exception { Throwable e = context.getLastThrowable(); if (shouldSkip(skipPolicy, e, contribution.getStepSkipCount())) { contribution.incrementReadSkipCount(); logger.debug("Skipping after failed process", e); return null; } else { if (rollbackClassifier.classify(e)) { // Default is to rollback unless the classifier // allows us to continue throw new RetryException("Non-skippable exception in recoverer while reading", e); } throw new BatchRuntimeException(e); } }
@Override public O recover(RetryContext context) throws Exception { Throwable e = context.getLastThrowable(); if (shouldSkip(skipPolicy, e, contribution.getStepSkipCount())) { contribution.incrementProcessSkipCount(); logger.debug("Skipping after failed process", e); return null; } else { if (rollbackClassifier.classify(e)) { // Default is to rollback unless the classifier // allows us to continue throw new RetryException("Non-skippable exception in recoverer while processing", e); } throw new BatchRuntimeException(e); } } };
@Override public O recover(RetryContext context) throws Exception { Throwable e = context.getLastThrowable(); if (shouldSkip(itemProcessSkipPolicy, e, contribution.getStepSkipCount())) { iterator.remove(e); contribution.incrementProcessSkipCount(); logger.debug("Skipping after failed process", e); return null; } else { if (rollbackClassifier.classify(e)) { // Default is to rollback unless the classifier // allows us to continue throw new RetryException("Non-skippable exception in recoverer while processing", e); } iterator.remove(e); return null; } }
rethrow(context, "Retry exhausted after last attempt with no recovery path"); throw wrapIfNecessary(context.getLastThrowable());
@Override public Object recover(RetryContext context) throws Exception { Throwable e = context.getLastThrowable(); if (outputs.size() > 1 && !rollbackClassifier.classify(e)) { throw new RetryException("Invalid retry state during write caused by " + "exception that does not classify for rollback: ", e); } Chunk<I>.ChunkIterator inputIterator = inputs.iterator(); for (Chunk<O>.ChunkIterator outputIterator = outputs.iterator(); outputIterator.hasNext();) { inputIterator.next(); outputIterator.next(); checkSkipPolicy(inputIterator, outputIterator, e, contribution, true); if (!rollbackClassifier.classify(e)) { throw new RetryException( "Invalid retry state during recovery caused by exception that does not classify for rollback: ", e); } } return null; }
@Override public Object recover(RetryContext context) throws Exception { publish(context.getLastThrowable(), context); return null; }
@Override public T recover(RetryContext context) throws Exception { Throwable lastThrowable = context.getLastThrowable(); if (lastThrowable != null) { if (lastThrowable instanceof RetryableStatusCodeException) { RetryableStatusCodeException ex = (RetryableStatusCodeException) lastThrowable; return createResponse((R) ex.getResponse(), ex.getUri()); } else if (lastThrowable instanceof Exception){ throw (Exception)lastThrowable; } } throw new RetryException("Could not recover", lastThrowable); } }
@Override public Object recover(RetryContext context) throws Exception { logger.error("Failed to perform redis operation.", context.getLastThrowable()); return null; } }
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()); } }
public void setRecoveryCallback(RecoveryCallback<Object> recoveryCallback) { this.recoveryCallback = context -> { if (!shouldRequeue((MessagingException) context.getLastThrowable())) { return recoveryCallback.recover(context); } throw (MessagingException) context.getLastThrowable(); }; }
public BatchRetryContext(RetryContext parent, Collection<RetryContext> contexts) { super(parent); this.contexts = contexts; int count = 0; for (RetryContext context : contexts) { int retryCount = context.getRetryCount(); if (retryCount > count) { count = retryCount; registerThrowable(context.getLastThrowable()); } } }