/** * Execute the simulator for a give # of iterations. * * @param numSimulations Number of simulations to run * @return the outcome of all simulations */ public RetrySimulation executeSimulation(int numSimulations) { RetrySimulation simulation = new RetrySimulation(); for (int i=0; i<numSimulations; i++) { simulation.addSequence(executeSingleSimulation()); } return simulation; }
@Override protected boolean canRetry(RetryPolicy retryPolicy, RetryContext context) { BatchRetryContext batchContext = (BatchRetryContext) context; for (RetryContext nextContext : batchContext.contexts) { if (!super.canRetry(retryPolicy, nextContext)) { return false; } } return true; }
@Override public final <T, E extends Throwable> T execute(RetryCallback<T, E> retryCallback, RecoveryCallback<T> recoveryCallback, RetryState retryState) throws E { return regular.execute(retryCallback, recoveryCallback, retryState); }
public StatefulRetryOperationsInterceptor() { RetryTemplate retryTemplate = new RetryTemplate(); retryTemplate.setRetryPolicy(new NeverRetryPolicy()); this.retryOperations = retryTemplate; }
private RetryTemplate createTemplate(String[] listenersBeanNames) { RetryTemplate template = new RetryTemplate(); if (listenersBeanNames.length > 0) { template.setListeners(getListenersBeans(listenersBeanNames)); } else if (globalListeners !=null) { template.setListeners(globalListeners); } return template; }
@Override public String doInTransaction(TransactionStatus status) { try { return retryTemplate.execute(callback, recoveryCallback, new DefaultRetryState(item)); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } } });
public void setRetryPolicy(RetryPolicy retryPolicy) { this.retryPolicy = retryPolicy; delegate.setRetryPolicy(retryPolicy); regular.setRetryPolicy(retryPolicy); }
@Override protected RetryContext open(RetryPolicy retryPolicy, RetryState state) { BatchRetryState batchState = (BatchRetryState) state; Collection<RetryContext> contexts = new ArrayList<>(); for (RetryState retryState : batchState.keys) { contexts.add(super.open(retryPolicy, retryState)); } return new BatchRetryContext(RetrySynchronizationManager.getContext(), contexts); }
/** * Execute the callback once if the policy dictates that we can, re-throwing any * exception encountered so that clients can re-present the same task later. * * @see RetryOperations#execute(RetryCallback, RetryState) * @param retryCallback the {@link RetryCallback} * @param retryState the {@link RetryState} * @throws ExhaustedRetryException if the retry has been exhausted. */ @Override public final <T, E extends Throwable> T execute(RetryCallback<T, E> retryCallback, RetryState retryState) throws E, ExhaustedRetryException { return doExecute(retryCallback, null, retryState); }
/** * @return the longest total time slept by a retry sequence. */ public SleepSequence getLongestTotalSleepSequence() { SleepSequence longest = null; for (SleepSequence sequence : sleepSequences) { if (longest == null || sequence.getTotalSleep() > longest.getTotalSleep()) { longest = sequence; } } return longest; }
public Object doWithRetry(RetryContext context) throws Exception { throw new FailingRetryException(); } }
private RetryContext doOpenInternal(RetryPolicy retryPolicy) { return doOpenInternal(retryPolicy, null); }
/** * Add a sequence of sleeps to the simulation. * @param sleeps the times to be created as a {@link SleepSequence} */ public void addSequence(List<Long> sleeps) { sleepHistogram.addAll(sleeps); sleepSequences.add(new SleepSequence(sleeps)); }
protected void registerThrowable(RetryPolicy retryPolicy, RetryState state, RetryContext context, Throwable e) { retryPolicy.registerThrowable(context, e); registerContext(context, state); }
@Override public final <T, E extends Throwable> T execute(RetryCallback<T, E> retryCallback, RetryState retryState) throws E, ExhaustedRetryException { return regular.execute(retryCallback, retryState); }
/** * Keep executing the callback until it either succeeds or the policy dictates that we * stop, in which case the recovery callback will be executed. * * @see RetryOperations#execute(RetryCallback, RecoveryCallback) * @param retryCallback the {@link RetryCallback} * @param recoveryCallback the {@link RecoveryCallback} * @throws TerminatedRetryException if the retry has been manually terminated by a * listener. */ @Override public final <T, E extends Throwable> T execute(RetryCallback<T, E> retryCallback, RecoveryCallback<T> recoveryCallback) throws E { return doExecute(retryCallback, recoveryCallback, null); }
@Override public final <T, E extends Throwable> T execute(RetryCallback<T, E> retryCallback, RecoveryCallback<T> recoveryCallback) throws E { return regular.execute(retryCallback, recoveryCallback); }
/** * Execute the callback once if the policy dictates that we can, re-throwing any * exception encountered so that clients can re-present the same task later. * * @see RetryOperations#execute(RetryCallback, RetryState) * @param retryCallback the {@link RetryCallback} * @param recoveryCallback the {@link RecoveryCallback} * @param retryState the {@link RetryState} */ @Override public final <T, E extends Throwable> T execute(RetryCallback<T, E> retryCallback, RecoveryCallback<T> recoveryCallback, RetryState retryState) throws E, ExhaustedRetryException { return doExecute(retryCallback, recoveryCallback, retryState); }
@Override public final <T, E extends Throwable> T execute(RetryCallback<T, E> retryCallback) throws E { return regular.execute(retryCallback); }
/** * Keep executing the callback until it either succeeds or the policy dictates that we * stop, in which case the most recent exception thrown by the callback will be * rethrown. * * @see RetryOperations#execute(RetryCallback) * @param retryCallback the {@link RetryCallback} * * @throws TerminatedRetryException if the retry has been manually terminated by a * listener. */ @Override public final <T, E extends Throwable> T execute(RetryCallback<T, E> retryCallback) throws E { return doExecute(retryCallback, null, null); }