Class SingleSender<M extends Message>

java.lang.Object
eu.bandm.tools.message.SingleSender<M>
Type Parameters:
M - the message type propagated by this sender
Direct Known Subclasses:
MessageCatcher, MessageMapper, MessagePasser, SimpleMessage.LocationMapper, SimpleMessage.Sender

public abstract class SingleSender<M extends Message> extends Object
Common superclass of classes which send messages to one single switchable drain. This includes some genuine message sources, ie. senders only, but most of the subclasses are MessageReceivers, which pass on the received messages to that single drain.

That drain can be inquired and set, ie. it can change dynamically during execution. Intentionally, the code will crash if it is equal to null while send(M) is called.

  • Field Details

  • Constructor Details

  • Method Details

    • setDrain

      public SingleSender<M> setDrain(@Opt @Opt MessageReceiver<? super M> r)
      Set the drain for the sent messages. As long as the value of the receiver is null, invoking send(M) will crash intentionally.
      Parameters:
      r - the drain for the sent messages.
      Returns:
      this instance, for method chaining.
    • getDrain

      @Opt public @Opt MessageReceiver<? super M> getDrain()
      Return the currently active drain.
      Returns:
      the currently active drain.
    • send

      public void send(M m)
      Send a message to the current drain. Intentionally, the code will crash if that is currently null.
      Parameters:
      m - the message to be sent to the current receiver.