Class PrimitiveMessageDemux<E extends Enum<E>,M extends Message>

java.lang.Object
eu.bandm.tools.message.PrimitiveMessageDemux<E,M>
Type Parameters:
E - the enumeration type controlling the routing
M - the type of the messages
All Implemented Interfaces:
MessageReceiver<M>
Direct Known Subclasses:
MessageDemux

public abstract class PrimitiveMessageDemux<E extends Enum<E>,M extends Message> extends Object implements MessageReceiver<M>
Auxiliary class which maps from an enumeration type to optional MessageReceivers. This class is intended as base class for classes which de-multiplex a message stream to these receivers.
  • Field Details

    • outlets

      protected final EnumMap<E extends Enum<E>,@Opt MessageReceiver<? super M extends Message>> outlets
      Internal directory of the different drains per tag.
    • tagclass

      protected final Class<E extends Enum<E>> tagclass
      Configuration value holding the class used for tagging.
  • Constructor Details

    • PrimitiveMessageDemux

      protected PrimitiveMessageDemux(Class<E> tagclass)
      Only constructor.
      Parameters:
      tagclass - the class used as index to the MessageReceivers.
  • Method Details

    • setReceiver

      public void setReceiver(E tag, @Opt @Opt MessageReceiver<? super M> rec)
      Set the receiver for one particular tag. Setting to null is allowed and make it act like a MessageDisposer, i.e. discard the message.
      Parameters:
      tag - the key under which the receiver can be activated
      rec - the message receiver activated by the tag
    • getReceiver

      @Opt public @Opt MessageReceiver<? super M> getReceiver(E tag)
      Get the receiver for one particular tag.
      Parameters:
      tag - under which the reciever has been stored.
      Returns:
      the receiver stored with the given tag, or null iff no such exists.
    • receive

      protected void receive(E tag, M msg)
      Auxiliary internal method for performing the sending to a certain MessageReceiver, as indicated by an enum value. If no receiver has been registered with that tag, no operation is performed.

      This method is called by some subclass, after it has determined the applicable enum value or value set.

      Parameters:
      tag - the tag identifying the intended receiver.
      msg - the message to send