Class InterceptorChain
- java.lang.Object
-
- de.otto.synapse.endpoint.InterceptorChain
-
- All Implemented Interfaces:
MessageInterceptor
@ThreadSafe public final class InterceptorChain extends java.lang.Object implements MessageInterceptor
Implementation of the Composite pattern formessage interceptorsthat can be used to build chains of interceptors.Just like any other
MessageInterceptor, the InterceptorChain is used to process a message before it is consumed bymessage consumerson the receiver-side, or before it is sent by amessage senderto the channel infrastructure.The interceptors of the InterceptorChain will be called in order. The result of the first interceptor is propagated to the next interceptor, and so on.
If an interceptor returns null, the chain will return null without further processing of the message.
- See Also:
- Composite Pattern
-
-
Constructor Summary
Constructors Constructor Description InterceptorChain()Creates an empty InterceptorChain.InterceptorChain(com.google.common.collect.ImmutableList<MessageInterceptor> messageInterceptors)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.google.common.collect.ImmutableList<MessageInterceptor>getInterceptors()Returns the immutable list of registeredmessage interceptors.TextMessageintercept(TextMessage message)Intercepts a message using all registered interceptors and returns the resulting message.
-
-
-
Constructor Detail
-
InterceptorChain
public InterceptorChain()
Creates an empty InterceptorChain.
-
InterceptorChain
public InterceptorChain(com.google.common.collect.ImmutableList<MessageInterceptor> messageInterceptors)
-
-
Method Detail
-
getInterceptors
public com.google.common.collect.ImmutableList<MessageInterceptor> getInterceptors()
Returns the immutable list of registeredmessage interceptors.- Returns:
- registered message interceptors
-
intercept
@Nullable public TextMessage intercept(@Nonnull TextMessage message)
Intercepts a message using all registered interceptors and returns the resulting message.The interceptors are called in order. The result of one interceptor is propagated to the next interceptor in the chain, until the end of the chain is reached, or one interceptor has returned null.
If
nullis returned, the message must be dropped by theAbstractMessageEndpoint.Every interceptor may transform the message, or may take additional actions like, for example, logging, monitoring or other things.
- Specified by:
interceptin interfaceMessageInterceptor- Parameters:
message- the message to intercept- Returns:
- the (possibly modified) message, or null if the message should be dropped.
-
-