Class MessageTee<M extends Message>

java.lang.Object
eu.bandm.tools.message.MessageTee<M>
All Implemented Interfaces:
MessageReceiver<M>

public class MessageTee<M extends Message> extends Object implements MessageReceiver<M>
Re-sends the message received sequentially to a multitude of current drains.
The identical message object is sent to all receivers, so in most use cases it should be treated read-only by subsequent processing in the drains.
For details see receive(Message).
  • Field Details

    • drains

      protected final List<MessageReceiver<? super M extends Message>> drains
      List of all receivers. The sequential order is respected when sending the message, but in most use cases should not be relevant.
  • Constructor Details

  • Method Details

    • getDrains

      public List<MessageReceiver<? super M>> getDrains()
      Return an unmodifiable list of all drains.
    • add

      public void add(MessageReceiver<? super M> drain)
      Adds the message receiver at the end of the list of all current drains. Cf receive(Message). If it is already contained at some position in the list, it is first removed and then re-inserted at the end of the list.
    • add

      public void add(MessageReceiver<? super M> drain1, MessageReceiver<? super M> drain2)
      Nonvararg specialization avoids unchecked warnings. Internally calls add(MessageReceiver), please see there.
    • add

      @SafeVarargs public final void add(MessageReceiver<? super M>... newdrains)
      Internally calls add(MessageReceiver), please see there.
    • addAll

      public void addAll(Iterable<MessageReceiver<? super M>> newdrains)
      Internally calls add(MessageReceiver), please see there.
    • clear

      public void clear()
      Clear the list of all drains.
    • receive

      public void receive(M message)
      Propagates the message received sequentially to a multitude of current drains.

      If there is one or more MessageThrowers in the pipeline behind these drains, then additionally the message is thrown after all drains have been sent to.
      (Any other Throwable is, of course, not intercepted!)
      Specified by:
      receive in interface MessageReceiver<M extends Message>