/** * Method for registering a context - should only be used by * {@link RetryOperations} implementations to ensure that * {@link #getContext()} always returns the correct value. * * @param context the new context to register * @return the old context if there was one */ public static RetryContext register(RetryContext context) { RetryContext oldContext = getContext(); RetrySynchronizationManager.context.set(context); return oldContext; }
/** * Clear the current context at the end of a batch - should only be used by * {@link RetryOperations} implementations. * * @return the old value if there was one. */ public static RetryContext clear() { RetryContext value = getContext(); RetryContext parent = value == null ? null : value.getParent(); RetrySynchronizationManager.context.set(parent); return value; }
@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); }
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; }
/** * If there's a retry template, it will set the attributes holder via the listener. If * there's no retry template, but there's an error channel, we create a new attributes * holder here. If an attributes holder exists (by either method), we set the * attributes for use by the * {@link org.springframework.integration.support.ErrorMessageStrategy}. * @param amqpMessage the AMQP message to use. * @param message the Spring Messaging message to use. * @since 4.3.10 */ private void setAttributesIfNecessary(Message amqpMessage, org.springframework.messaging.Message<?> message) { boolean needHolder = getErrorChannel() != null && this.retryTemplate == null; boolean needAttributes = needHolder || this.retryTemplate != null; if (needHolder) { attributesHolder.set(ErrorMessageUtils.getAttributeAccessor(null, null)); } if (needAttributes) { AttributeAccessor attributes = this.retryTemplate != null ? RetrySynchronizationManager.getContext() : attributesHolder.get(); if (attributes != null) { attributes.setAttribute(ErrorMessageUtils.INPUT_MESSAGE_CONTEXT_KEY, message); attributes.setAttribute(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE, amqpMessage); } } }
/** * If there's a retry template, it will set the attributes holder via the listener. If * there's no retry template, but there's an error channel, we create a new attributes * holder here. If an attributes holder exists (by either method), we set the * attributes for use by the * {@link org.springframework.integration.support.ErrorMessageStrategy}. * @param amqpMessage the AMQP message to use. * @param message the Spring Messaging message to use. * @since 4.3.10 */ private void setAttributesIfNecessary(Message amqpMessage, org.springframework.messaging.Message<?> message) { boolean needHolder = getErrorChannel() != null && this.retryTemplate == null; boolean needAttributes = needHolder || this.retryTemplate != null; if (needHolder) { attributesHolder.set(ErrorMessageUtils.getAttributeAccessor(null, null)); } if (needAttributes) { AttributeAccessor attributes = this.retryTemplate != null ? RetrySynchronizationManager.getContext() : attributesHolder.get(); if (attributes != null) { attributes.setAttribute(ErrorMessageUtils.INPUT_MESSAGE_CONTEXT_KEY, message); attributes.setAttribute(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE, amqpMessage); } } }
/** * Returns whenever there is already a proxy running inside this thread execution. To avoid multiple retries in the * case if this bean is called by another bean which already has a RetryOperationsInterceptor. * * @return <code>true</code> if there is a {@link org.springframework.retry.RetryContext} available inside the {@link * RetrySynchronizationManager} or <code>false</code> otherwise. */ protected boolean isRetryContextOperationActive() { return RetrySynchronizationManager.getContext() != null; }
/** * Returns whenever there is already a proxy running inside this thread execution. To avoid multiple retries in the * case if this bean is called by another bean which already has a RetryOperationsInterceptor. * * @return <code>true</code> if there is a {@link org.springframework.retry.RetryContext} available inside the {@link * RetrySynchronizationManager} or <code>false</code> otherwise. */ protected boolean isRetryContextOperationActive() { return RetrySynchronizationManager.getContext() != null; }
/** * Method for registering a context - should only be used by * {@link RetryOperations} implementations to ensure that * {@link #getContext()} always returns the correct value. * * @param context the new context to register * @return the old context if there was one */ public static RetryContext register(RetryContext context) { RetryContext oldContext = getContext(); RetrySynchronizationManager.context.set(context); return oldContext; }
/** * Clear the current context at the end of a batch - should only be used by * {@link RetryOperations} implementations. * * @return the old value if there was one. */ public static RetryContext clear() { RetryContext value = getContext(); RetryContext parent = value == null ? null : value.getParent(); RetrySynchronizationManager.context.set(parent); return value; }
@Override protected RetryContext open(RetryPolicy retryPolicy, RetryState state) { BatchRetryState batchState = (BatchRetryState) state; Collection<RetryContext> contexts = new ArrayList<RetryContext>(); for (RetryState retryState : batchState.keys) { contexts.add(super.open(retryPolicy, retryState)); } return new BatchRetryContext(RetrySynchronizationManager.getContext(), contexts); }
@Override protected RetryContext open(RetryPolicy retryPolicy, RetryState state) { BatchRetryState batchState = (BatchRetryState) state; Collection<RetryContext> contexts = new ArrayList<RetryContext>(); for (RetryState retryState : batchState.keys) { contexts.add(super.open(retryPolicy, retryState)); } return new BatchRetryContext(RetrySynchronizationManager.getContext(), contexts); }
@Override protected RetryContext open(RetryPolicy retryPolicy, RetryState state) { BatchRetryState batchState = (BatchRetryState) state; Collection<RetryContext> contexts = new ArrayList<RetryContext>(); for (RetryState retryState : batchState.keys) { contexts.add(super.open(retryPolicy, retryState)); } return new BatchRetryContext(RetrySynchronizationManager.getContext(), contexts); }
/** * If there's a retry template, it will set the attributes holder via the listener. If * there's no retry template, but there's an error channel, we create a new attributes * holder here. If an attributes holder exists (by either method), we set the * attributes for use by the * {@link org.springframework.integration.support.ErrorMessageStrategy}. * @param amqpMessage the AMQP message to use. * @param message the Spring Messaging message to use. * @since 4.3.10 */ private void setAttributesIfNecessary(Message amqpMessage, org.springframework.messaging.Message<?> message) { boolean needHolder = getErrorChannel() != null && this.retryTemplate == null; boolean needAttributes = needHolder || this.retryTemplate != null; if (needHolder) { attributesHolder.set(ErrorMessageUtils.getAttributeAccessor(null, null)); } if (needAttributes) { AttributeAccessor attributes = this.retryTemplate != null ? RetrySynchronizationManager.getContext() : attributesHolder.get(); if (attributes != null) { attributes.setAttribute(ErrorMessageUtils.INPUT_MESSAGE_CONTEXT_KEY, message); attributes.setAttribute(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE, amqpMessage); } } }
/** * If there's a retry template, it will set the attributes holder via the listener. If * there's no retry template, but there's an error channel, we create a new attributes * holder here. If an attributes holder exists (by either method), we set the * attributes for use by the * {@link org.springframework.integration.support.ErrorMessageStrategy}. * @param amqpMessage the AMQP message to use. * @param message the Spring Messaging message to use. * @since 4.3.10 */ private void setAttributesIfNecessary(Message amqpMessage, org.springframework.messaging.Message<?> message) { boolean needHolder = getErrorChannel() != null && this.retryTemplate == null; boolean needAttributes = needHolder || this.retryTemplate != null; if (needHolder) { attributesHolder.set(ErrorMessageUtils.getAttributeAccessor(null, null)); } if (needAttributes) { AttributeAccessor attributes = this.retryTemplate != null ? RetrySynchronizationManager.getContext() : attributesHolder.get(); if (attributes != null) { attributes.setAttribute(ErrorMessageUtils.INPUT_MESSAGE_CONTEXT_KEY, message); attributes.setAttribute(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE, amqpMessage); } } }
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; }