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

java.lang.Object
eu.bandm.tools.message.PrimitiveMessageDemux<E,M>
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 administrating an enumeration type and a map from this type to optional MessageReceivers. Intended for de-multiplexing a message stream as calculated by some derived class.
  • 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 null is allowed and acts like a MessageDisposer.
      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 wiht that tag, NOP is performed.

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

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