Class AbstractMessageSplitter

All Implemented Interfaces:
org.reactivestreams.Subscriber<Message<?>>, Aware, BeanClassLoaderAware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, Ordered, ExpressionCapable, Orderable, MessageProducer, DiscardingMessageHandler, HeaderPropagationAware, IntegrationPattern, NamedComponent, IntegrationManagement, TrackableComponent, MessageHandler, reactor.core.CoreSubscriber<Message<?>>
Direct Known Subclasses:
DefaultMessageSplitter, ExpressionEvaluatingSplitter, FileSplitter, MethodInvokingSplitter, UnZipResultSplitter, XPathMessageSplitter

public abstract class AbstractMessageSplitter extends AbstractReplyProducingMessageHandler implements DiscardingMessageHandler
Base class for Message-splitting handlers.
Author:
Mark Fisher, Dave Syer, Artem Bilan, Ruslan Stelmachenko, Gary Russell
  • Constructor Details

    • AbstractMessageSplitter

      public AbstractMessageSplitter()
  • Method Details

    • setApplySequence

      public void setApplySequence(boolean applySequence)
      Set the applySequence flag to the specified value. Defaults to true.
      Parameters:
      applySequence - true to apply sequence information.
    • setDiscardChannel

      public void setDiscardChannel(MessageChannel discardChannel)
      Specify a channel where rejected Messages should be sent. If the discard channel is null (the default), rejected Messages will be dropped. A "Rejected Message" means that split function has returned an empty result (but not null): no items to iterate for sending.
      Parameters:
      discardChannel - The discard channel.
      Since:
      5.2
    • setDiscardChannelName

      public void setDiscardChannelName(String discardChannelName)
      Specify a channel bean name (resolved to MessageChannel lazily) where rejected Messages should be sent. If the discard channel is null (the default), rejected Messages will be dropped. A "Rejected Message" means that split function has returned an empty result (but not null): no items to iterate for sending.
      Parameters:
      discardChannelName - The discard channel bean name.
      Since:
      5.2
    • getDiscardChannel

      public MessageChannel getDiscardChannel()
      Description copied from interface: DiscardingMessageHandler
      Return the discard channel.
      Specified by:
      getDiscardChannel in interface DiscardingMessageHandler
      Returns:
      the channel.
    • getIntegrationPatternType

      public IntegrationPatternType getIntegrationPatternType()
      Description copied from interface: IntegrationPattern
      Return a pattern type this component implements.
      Specified by:
      getIntegrationPatternType in interface IntegrationPattern
      Overrides:
      getIntegrationPatternType in class AbstractReplyProducingMessageHandler
      Returns:
      the IntegrationPatternType this component implements.
    • doInit

      protected void doInit()
      Overrides:
      doInit in class AbstractReplyProducingMessageHandler
    • handleRequestMessage

      protected final Object handleRequestMessage(Message<?> message)
      Description copied from class: AbstractReplyProducingMessageHandler
      Subclasses must implement this method to handle the request Message. The return value may be a Message, a MessageBuilder, or any plain Object. The base class will handle the final creation of a reply Message from any of those starting points. If the return value is null, the Message flow will end here.
      Specified by:
      handleRequestMessage in class AbstractReplyProducingMessageHandler
      Parameters:
      message - The request message.
      Returns:
      The result of handling the message, or null.
    • obtainSizeIfPossible

      protected int obtainSizeIfPossible(Iterable<?> iterable)
      Obtain a size of the provided Iterable. Default implementation returns Collection.size() if the iterable is a collection, or 0 otherwise. If iterable is a Jackson TreeNode, then its size is used.
      Parameters:
      iterable - the Iterable to obtain the size
      Returns:
      the size of the Iterable
      Since:
      5.0
    • obtainSizeIfPossible

      protected int obtainSizeIfPossible(Iterator<?> iterator)
      Obtain a size of the provided Iterator. Default implementation returns 0.
      Parameters:
      iterator - the Iterator to obtain the size
      Returns:
      the size of the Iterator
      Since:
      5.0
    • willAddHeaders

      protected boolean willAddHeaders(Message<?> message)
      Return true if the subclass needs to add headers in the resulting splits. If true, addHeaders(org.springframework.messaging.Message<?>, java.util.Map<java.lang.String, java.lang.Object>) will be called.
      Parameters:
      message - the message.
      Returns:
      true
    • addHeaders

      protected void addHeaders(Message<?> message, Map<String,Object> headers)
      Allows subclasses to add extra headers to the output messages. Headers may not be removed by this method.
      Parameters:
      message - the inbound message.
      headers - the headers to add messages to.
    • shouldCopyRequestHeaders

      protected boolean shouldCopyRequestHeaders()
      Description copied from class: AbstractMessageProducingHandler
      Subclasses may override this. True by default.
      Overrides:
      shouldCopyRequestHeaders in class AbstractMessageProducingHandler
      Returns:
      true if the request headers should be copied.
    • produceOutput

      protected void produceOutput(Object result, Message<?> requestMessage)
      Overrides:
      produceOutput in class AbstractMessageProducingHandler
    • getComponentType

      public String getComponentType()
      Description copied from class: IntegrationObjectSupport
      Subclasses may implement this method to provide component type information.
      Specified by:
      getComponentType in interface NamedComponent
      Overrides:
      getComponentType in class MessageHandlerSupport
    • splitMessage

      protected abstract Object splitMessage(Message<?> message)
      Subclasses must override this method to split the received Message. The return value may be a Collection or Array. The individual elements may be Messages, but it is not necessary. If the elements are not Messages, each will be provided as the payload of a Message. It is also acceptable to return a single Object or Message. In that case, a single reply Message will be produced.
      Parameters:
      message - The message.
      Returns:
      The result of splitting the message.