Class ThreadStatePropagationChannelInterceptor<S>

java.lang.Object
org.springframework.integration.channel.interceptor.ThreadStatePropagationChannelInterceptor<S>
Type Parameters:
S - the propagated state object type.
All Implemented Interfaces:
org.springframework.messaging.support.ChannelInterceptor, org.springframework.messaging.support.ExecutorChannelInterceptor
Direct Known Subclasses:
ObservationPropagationChannelInterceptor

public abstract class ThreadStatePropagationChannelInterceptor<S> extends Object implements org.springframework.messaging.support.ExecutorChannelInterceptor
The ExecutorChannelInterceptor implementation responsible for the Thread (any?) state propagation from one message flow's thread to another through the MessageChannels involved in the flow.

The propagation is done from the preSend(Message, MessageChannel) implementation using some internal Message extension which keeps the message to send and the state to propagate.

The propagated state context extraction and population is done from the postReceive(org.springframework.messaging.Message<?>, org.springframework.messaging.MessageChannel) implementation for the PollableChannels, and from the beforeHandle(org.springframework.messaging.Message<?>, org.springframework.messaging.MessageChannel, org.springframework.messaging.MessageHandler) for the AbstractExecutorChannels and ExecutorSubscribableChannels

Important. Any further interceptor, which modifies the message to send (e.g. MessageBuilder.withPayload(...)...build()), may drop the state to propagate. Such kind of interceptors combination should be revised properly. In most cases the interceptors reordering is enough to overcome the issue.

Since:
4.2
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final org.springframework.messaging.Message<?>
    beforeHandle(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel, org.springframework.messaging.MessageHandler handler)
     
    protected abstract S
    obtainPropagatingContext(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel)
     
    protected abstract void
    populatePropagatedContext(S state, org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel)
     
    final org.springframework.messaging.Message<?>
    postReceive(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel)
     
    final org.springframework.messaging.Message<?>
    preSend(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.messaging.support.ChannelInterceptor

    afterReceiveCompletion, afterSendCompletion, postSend, preReceive

    Methods inherited from interface org.springframework.messaging.support.ExecutorChannelInterceptor

    afterMessageHandled
  • Constructor Details

    • ThreadStatePropagationChannelInterceptor

      public ThreadStatePropagationChannelInterceptor()
  • Method Details

    • preSend

      public final org.springframework.messaging.Message<?> preSend(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel)
      Specified by:
      preSend in interface org.springframework.messaging.support.ChannelInterceptor
    • postReceive

      public final org.springframework.messaging.Message<?> postReceive(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel)
      Specified by:
      postReceive in interface org.springframework.messaging.support.ChannelInterceptor
    • beforeHandle

      public final org.springframework.messaging.Message<?> beforeHandle(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel, org.springframework.messaging.MessageHandler handler)
      Specified by:
      beforeHandle in interface org.springframework.messaging.support.ExecutorChannelInterceptor
    • obtainPropagatingContext

      @Nullable protected abstract S obtainPropagatingContext(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel)
    • populatePropagatedContext

      protected abstract void populatePropagatedContext(@Nullable S state, org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel)