public static List<RetryState> createState(List<?> keys) { List<RetryState> states = new ArrayList<>(); for (Object key : keys) { states.add(new DefaultRetryState(key)); } return states; }
public static List<RetryState> createState(List<?> keys, Classifier<? super Throwable, Boolean> classifier) { List<RetryState> states = new ArrayList<>(); for (Object key : keys) { states.add(new DefaultRetryState(key, classifier)); } return states; }
@Override public String doInTransaction(TransactionStatus status) { try { return retryTemplate.execute(callback, recoveryCallback, new DefaultRetryState(item)); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } } });
RetryState retryState = new DefaultRetryState(key, this.newMethodArgumentsIdentifier != null && this.newMethodArgumentsIdentifier.isNew(args),
@Override public Object doInTransaction(TransactionStatus status) { try { final Object item = provider.read(); RetryCallback<Object, Exception> callback = new RetryCallback<Object, Exception>() { @Override public Object doWithRetry(RetryContext context) throws Exception { writer.write(Collections.singletonList(item)); return null; } }; return retryTemplate.execute(callback, new DefaultRetryState(item)); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } } });
@Override public Object doInTransaction(TransactionStatus status) { try { final String item = provider.read(); RetryCallback<Object, Exception> callback = new RetryCallback<Object, Exception>() { @Override public Object doWithRetry(RetryContext context) throws Exception { writer.write(Collections.singletonList(item)); return null; } }; return retryTemplate.execute(callback, new DefaultRetryState(item)); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } } });
@Test public void testSuccessfulAttempt() throws Exception { BatchRetryTemplate template = new BatchRetryTemplate(); String result = template.execute(new RetryCallback<String, Exception>() { @Override public String doWithRetry(RetryContext context) throws Exception { assertTrue("Wrong context type: " + context.getClass().getSimpleName(), context.getClass() .getSimpleName().contains("Batch")); return "2"; } }, Arrays.<RetryState> asList(new DefaultRetryState("1"))); assertEquals("2", result); }
batchRetryTemplate.execute(retryCallback, recoveryCallback, new DefaultRetryState(inputs, rollbackClassifier));
retryTemplate.execute(callback, recoveryCallback, new DefaultRetryState(msg.getJMSMessageID()));
@Test public void testUnSuccessfulAttemptAndRetry() throws Exception { BatchRetryTemplate template = new BatchRetryTemplate(); RetryCallback<String[], Exception> retryCallback = new RetryCallback<String[], Exception>() { @Override public String[] doWithRetry(RetryContext context) throws Exception { assertEquals(count, context.getRetryCount()); if (count++ == 0) { throw new RecoverableException("Recoverable"); } return new String[] { "a", "b" }; } }; List<RetryState> states = Arrays.<RetryState> asList(new DefaultRetryState("1"), new DefaultRetryState("2")); try { template.execute(retryCallback, states); fail("Expected RecoverableException"); } catch (RecoverableException e) { assertEquals("Recoverable", e.getMessage()); } String[] result = template.execute(retryCallback, states); assertEquals("[a, b]", Arrays.toString(result)); }
O output = batchRetryTemplate.execute(retryCallback, recoveryCallback, new DefaultRetryState( getInputKey(item), rollbackClassifier)); if (output != null) {
@Override public RetryState determineRetryState(Message<?> message) { Boolean forceRefresh = this.forceRefreshExpression == null ? Boolean.FALSE : this.forceRefreshExpression.getValue(this.evaluationContext, message, Boolean.class); return new DefaultRetryState(this.keyExpression.getValue(this.evaluationContext, message), forceRefresh == null ? false : forceRefresh, this.classifier); }
@Test public void defaultStatefulRetryRecoverAfterThirdTry() { final AtomicInteger counter = new AtomicInteger(3); AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() { @Override protected Object handleRequestMessage(Message<?> requestMessage) { if (counter.getAndDecrement() > 0) { throw new RuntimeException("foo"); } return "bar"; } }; QueueChannel replies = new QueueChannel(); handler.setOutputChannel(replies); RequestHandlerRetryAdvice advice = new RequestHandlerRetryAdvice(); advice.setRetryStateGenerator(message -> new DefaultRetryState(message.getHeaders().getId())); defaultStatefulRetryRecoverAfterThirdTryGuts(counter, handler, replies, advice); }
public static List<RetryState> createState(List<?> keys) { List<RetryState> states = new ArrayList<RetryState>(); for (Object key : keys) { states.add(new DefaultRetryState(key)); } return states; }
@Override public RetryState determineRetryState(Message<?> message) { Boolean forceRefresh = this.forceRefreshExpression == null ? Boolean.FALSE : this.forceRefreshExpression.getValue(this.evaluationContext, message, Boolean.class); return new DefaultRetryState(this.keyExpression.getValue(this.evaluationContext, message), forceRefresh == null ? false : forceRefresh, this.classifier); }
public static List<RetryState> createState(List<?> keys, Classifier<? super Throwable, Boolean> classifier) { List<RetryState> states = new ArrayList<RetryState>(); for (Object key : keys) { states.add(new DefaultRetryState(key, classifier)); } return states; }
public static List<RetryState> createState(List<?> keys) { List<RetryState> states = new ArrayList<RetryState>(); for (Object key : keys) { states.add(new DefaultRetryState(key)); } return states; }
RequestHandlerRetryAdvice advice = new RequestHandlerRetryAdvice(); advice.setRetryStateGenerator(message -> new DefaultRetryState(message.getHeaders().getId()));
public static List<RetryState> createState(List<?> keys) { List<RetryState> states = new ArrayList<RetryState>(); for (Object key : keys) { states.add(new DefaultRetryState(key)); } return states; }
public static List<RetryState> createState(List<?> keys, Classifier<? super Throwable, Boolean> classifier) { List<RetryState> states = new ArrayList<RetryState>(); for (Object key : keys) { states.add(new DefaultRetryState(key, classifier)); } return states; }