S
- the propagated state object type.public abstract class ThreadStatePropagationChannelInterceptor<S> extends Object implements ExecutorChannelInterceptor
ExecutorChannelInterceptor
implementation responsible for
the Thread
(any?) state propagation from one message flow's thread to another
through the MessageChannel
s 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 PollableChannel
s, and from
the beforeHandle(org.springframework.messaging.Message<?>, org.springframework.messaging.MessageChannel, org.springframework.messaging.MessageHandler)
for the
AbstractExecutorChannel
s and
ExecutorSubscribableChannel
s
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.
Constructor and Description |
---|
ThreadStatePropagationChannelInterceptor() |
Modifier and Type | Method and Description |
---|---|
void |
afterMessageHandled(Message<?> message,
MessageChannel channel,
MessageHandler handler,
Exception ex) |
Message<?> |
beforeHandle(Message<?> message,
MessageChannel channel,
MessageHandler handler) |
protected abstract S |
obtainPropagatingContext(Message<?> message,
MessageChannel channel) |
protected abstract void |
populatePropagatedContext(S state,
Message<?> message,
MessageChannel channel) |
Message<?> |
postReceive(Message<?> message,
MessageChannel channel) |
Message<?> |
preSend(Message<?> message,
MessageChannel channel) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
afterReceiveCompletion, afterSendCompletion, postSend, preReceive
public ThreadStatePropagationChannelInterceptor()
public final Message<?> preSend(Message<?> message, MessageChannel channel)
preSend
in interface ChannelInterceptor
public final Message<?> postReceive(Message<?> message, MessageChannel channel)
postReceive
in interface ChannelInterceptor
public final Message<?> beforeHandle(Message<?> message, MessageChannel channel, MessageHandler handler)
beforeHandle
in interface ExecutorChannelInterceptor
public void afterMessageHandled(Message<?> message, MessageChannel channel, MessageHandler handler, Exception ex)
afterMessageHandled
in interface ExecutorChannelInterceptor
protected abstract S obtainPropagatingContext(Message<?> message, MessageChannel channel)
protected abstract void populatePropagatedContext(S state, Message<?> message, MessageChannel channel)