private void registerContext(RetryContext context, RetryState state) { if (state != null) { Object key = state.getKey(); if (key != null) { if (context.getRetryCount() > 1 && !this.retryContextCache.containsKey(key)) { throw new RetryException( "Inconsistent state for failed item key: cache key has changed. " + "Consider whether equals() or hashCode() for the key might be inconsistent, " + "or if you need to supply a better key"); } this.retryContextCache.put(key, context); } } }
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; }
/** * 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); } }
context.setAttribute(RetryContext.EXHAUSTED, true); if (state != null && !context.hasAttribute(GLOBAL_STATE)) { this.retryContextCache.remove(state.getKey());
Object key = state.getKey(); if (state.isForceRefresh()) { return doOpenInternal(retryPolicy, state);
@Test public void testBasicConfig() { RetryState state = configGenerator.determineRetryState(message); assertEquals("bar", state.getKey()); assertFalse(state.isForceRefresh()); assertTrue(state.rollbackFor(new RuntimeException())); }
@Test public void testForceRefreshFalse() { SpelExpressionRetryStateGenerator generator = new SpelExpressionRetryStateGenerator("headers['foo']", "headers['falseHeader']"); RetryState state = generator.determineRetryState(message); assertEquals("bar", state.getKey()); assertFalse(state.isForceRefresh()); assertTrue(state.rollbackFor(new RuntimeException())); }
@Test public void testForceRefreshTrue() { SpelExpressionRetryStateGenerator generator = new SpelExpressionRetryStateGenerator("headers['foo']", "headers['trueHeader']"); RetryState state = generator.determineRetryState(message); assertEquals("bar", state.getKey()); assertTrue(state.isForceRefresh()); assertTrue(state.rollbackFor(new RuntimeException())); }
@Test public void testBasic() { SpelExpressionRetryStateGenerator generator = new SpelExpressionRetryStateGenerator("headers['foo']"); RetryState state = generator.determineRetryState(message); assertEquals("bar", state.getKey()); assertFalse(state.isForceRefresh()); assertTrue(state.rollbackFor(new RuntimeException())); }
@Test public void testForceRefreshElvis() { SpelExpressionRetryStateGenerator generator = new SpelExpressionRetryStateGenerator("headers['foo']", "headers['noHeader']?:true"); RetryState state = generator.determineRetryState(message); assertEquals("bar", state.getKey()); assertTrue(state.isForceRefresh()); assertTrue(state.rollbackFor(new RuntimeException())); }
@Test public void testClassifier() { SpelExpressionRetryStateGenerator generator = new SpelExpressionRetryStateGenerator("headers['foo']"); generator.setClassifier(new ClassifierSupport<>(false)); RetryState state = generator.determineRetryState(message); assertEquals("bar", state.getKey()); assertFalse(state.isForceRefresh()); assertFalse(state.rollbackFor(new RuntimeException())); }
private void registerContext(RetryContext context, RetryState state) { if (state != null) { Object key = state.getKey(); if (key != null) { if (context.getRetryCount() > 1 && !this.retryContextCache.containsKey(key)) { throw new RetryException( "Inconsistent state for failed item key: cache key has changed. " + "Consider whether equals() or hashCode() for the key might be inconsistent, " + "or if you need to supply a better key"); } this.retryContextCache.put(key, context); } } }
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; }
/** * 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); } }
context.setAttribute(RetryContext.EXHAUSTED, true); if (state != null && !context.hasAttribute(GLOBAL_STATE)) { this.retryContextCache.remove(state.getKey());
Object key = state.getKey(); if (state.isForceRefresh()) { return doOpenInternal(retryPolicy, state);