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 for message interceptors that 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 by message consumers on the receiver-side, or before it is sent by a message sender to 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

    Modifier and Type Method Description
    com.google.common.collect.ImmutableList<MessageInterceptor> getInterceptors()
    Returns the immutable list of registered message interceptors.
    TextMessage intercept​(TextMessage message)
    Intercepts a message using all registered interceptors and returns the resulting message.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • InterceptorChain

      public InterceptorChain()
      Creates an empty InterceptorChain.
    • InterceptorChain

      public InterceptorChain​(com.google.common.collect.ImmutableList<MessageInterceptor> messageInterceptors)
  • Method Details

    • getInterceptors

      public com.google.common.collect.ImmutableList<MessageInterceptor> getInterceptors()
      Returns the immutable list of registered message 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 null is returned, the message must be dropped by the AbstractMessageEndpoint.

      Every interceptor may transform the message, or may take additional actions like, for example, logging, monitoring or other things.

      Specified by:
      intercept in interface MessageInterceptor
      Parameters:
      message - the message to intercept
      Returns:
      the (possibly modified) message, or null if the message should be dropped.