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()); } } }
Object resource = context.getAttribute("backOffContext"); backOffContext = backOffPolicy.start(context); if (backOffContext != null) { context.setAttribute("backOffContext", backOffContext); while (canRetry(retryPolicy, context) && !context.isExhaustedOnly()) { this.logger.debug("Retry: count=" + context.getRetryCount()); if (canRetry(retryPolicy, context) && !context.isExhaustedOnly()) { try { backOffPolicy.backOff(backOffContext); this.logger .debug("Abort retry because interrupted: count=" + context.getRetryCount()); "Checking for rethrow: count=" + context.getRetryCount()); if (this.logger.isDebugEnabled()) { this.logger.debug("Rethrow in retry for policy: count=" + context.getRetryCount()); if (state != null && context.hasAttribute(GLOBAL_STATE)) { break; "Retry failed last attempt: count=" + context.getRetryCount());
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; }
context.setAttribute(RetryContext.EXHAUSTED, true); if (state != null && !context.hasAttribute(GLOBAL_STATE)) { this.retryContextCache.remove(state.getKey()); context.setAttribute(RetryContext.RECOVERED, true); return recovered; rethrow(context, "Retry exhausted after last attempt with no recovery path"); throw wrapIfNecessary(context.getLastThrowable());
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 int getRetryCount() { return this.context.getRetryCount(); }
}, ctx -> { if (this.recoveryCallback != null) { ctx.setAttribute(SendRetryContextAccessor.MESSAGE, messageToSend); ctx.setAttribute(SendRetryContextAccessor.ADDRESS, replyTo); this.recoveryCallback.recover(ctx); return null; throw RabbitExceptionTranslator.convertRabbitAccessException(ctx.getLastThrowable());
Object value = retryContext.getRetryContext().getAttribute( name ); Object report = retryContext.getRetryContext().getAttribute( MetadataSyncJob.METADATA_SYNC_REPORT ); if ( retryContext.getRetryContext().getLastThrowable() != null ) text.append( retryContext.getRetryContext().getLastThrowable().getMessage() );
@Override public <T, E extends Throwable> void close(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) { Object mappingName = context.getAttribute(MAPPING_NAME_RETRY_ATTRIBUTE); if (mappingName != null) { if (throwable != null) { log.error("All {} attempts to forward HTTP request using '{}' mapping has failed. {}", context.getRetryCount(), mappingName, retrieveErrorMessage(throwable)); } else { log.debug("Attempt {} to forward HTTP request using '{}' mapping has succeeded", context.getRetryCount() + 1, mappingName); } } }
@Override public Object doWithRetry(RetryContext context) throws Exception { context.setAttribute(RetryContext.NAME, label); try { return this.invocation.proceed(); } catch (Exception e) { throw e; } catch (Error e) { throw e; } catch (Throwable e) { throw new IllegalStateException(e); } } }
if(!job.isRestartable()){ retryContext.setExhaustedOnly(); if(retryContext.getRetryCount() > 0){ logger.info("Job: [" + job + "] retrying/restarting with the following parameters: [" + jobParameters + "]"); retryContext.setExhaustedOnly(); //don't repeat if instance already complete or running rethrow(e);
private String getName(RetryContext context) { return (String) context.getAttribute(RetryContext.NAME); } }
for (String key : new String[] { CircuitBreakerRetryPolicy.CIRCUIT_OPEN, CircuitBreakerRetryPolicy.CIRCUIT_SHORT_COUNT }) { if (context.hasAttribute(key)) { accessor.setAttribute(key, context.getAttribute(key));
@Override public Object recover(RetryContext context) { return this.recoverer.recover(this.args, context.getLastThrowable()); }
private Acknowledgement doSendMsgs(final List<MessageExt> msgs, RetryContext context) { List<Acknowledgement> acknowledgements = new ArrayList<>(); msgs.forEach(msg -> { String retryInfo = context == null ? "" : "retryCount-" + String.valueOf(context.getRetryCount()) + "|"; logger.debug(retryInfo + "consuming msg:\n" + msg); logger.debug(retryInfo + "message body:\n" + new String(msg.getBody())); Acknowledgement acknowledgement = new Acknowledgement(); Message<byte[]> toChannel = convertMessagingFromRocketMQMsg(msg, acknowledgement); acknowledgements.add(acknowledgement); RocketMQInboundChannelAdapter.this.sendMessage(toChannel); }); return acknowledgements.get(0); }
context.setAttribute(RetryContext.EXHAUSTED, true); if (state != null && !context.hasAttribute(GLOBAL_STATE)) { this.retryContextCache.remove(state.getKey()); context.setAttribute(RetryContext.RECOVERED, true); return recovered; rethrow(context, "Retry exhausted after last attempt with no recovery path"); throw wrapIfNecessary(context.getLastThrowable());
}, ctx -> { if (this.recoveryCallback != null) { ctx.setAttribute(SendRetryContextAccessor.MESSAGE, messageToSend); ctx.setAttribute(SendRetryContextAccessor.ADDRESS, replyTo); this.recoveryCallback.recover(ctx); return null; throw RabbitExceptionTranslator.convertRabbitAccessException(ctx.getLastThrowable());
@Override public <T, E extends Throwable> void onError(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) { Object mappingName = context.getAttribute(MAPPING_NAME_RETRY_ATTRIBUTE); if (mappingName != null) { log.debug("Attempt {} to forward HTTP request using '{}' mapping has failed. {}", context.getRetryCount() + 1, mappingName, retrieveErrorMessage(throwable)); } }
public Object doWithRetry(RetryContext context) throws Exception { context.setAttribute(RetryContext.NAME, label); /* * If we don't copy the invocation carefully it won't keep a reference to * the other interceptors in the chain. We don't have a choice here but to * specialise to ReflectiveMethodInvocation (but how often would another * implementation come along?). */ if (invocation instanceof ProxyMethodInvocation) { try { return ((ProxyMethodInvocation) invocation).invocableClone().proceed(); } catch (Exception e) { throw e; } catch (Error e) { throw e; } catch (Throwable e) { throw new IllegalStateException(e); } } else { throw new IllegalStateException( "MethodInvocation of the wrong type detected - this should not happen with Spring AOP, " + "so please raise an issue if you see this exception"); } }
/** * Clean up the cache if necessary and close the context provided (if the flag * indicates that processing was successful). * * @param retryPolicy the {@link RetryPolicy} * @param context the {@link RetryContext} * @param state the {@link RetryState} * @param succeeded whether the close succeeded */ protected void close(RetryPolicy retryPolicy, RetryContext context, RetryState state, boolean succeeded) { if (state != null) { if (succeeded) { if (!context.hasAttribute(GLOBAL_STATE)) { this.retryContextCache.remove(state.getKey()); } retryPolicy.close(context); context.setAttribute(RetryContext.CLOSED, true); } } else { retryPolicy.close(context); context.setAttribute(RetryContext.CLOSED, true); } }