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

java.lang.Object
eu.bandm.tools.message.PrimitiveMessageDemux<E,M>
eu.bandm.tools.message.MessageDemux<E,M>
All Implemented Interfaces:
MessageReceiver<M>
Direct Known Subclasses:
MessageDemux.All, MessageDemux.ByKind

public abstract class MessageDemux<E extends Enum<E>,M extends Message> extends PrimitiveMessageDemux<E,M>
Auxiliary class which concretizes PrimitiveMessageDemux in so far it calculates a set of enum values for every message it receives, and then calls the PrimitiveMessageDemux.receive(Enum,Message) method for all these.
  • Constructor Details

    • MessageDemux

      protected MessageDemux(Class<E> tagclass)
      Only constructor.
      Parameters:
      tagclass - the class of the controlling tags.
  • Method Details

    • getOutputTags

      protected abstract EnumSet<E> getOutputTags(M m)
      Has to be re-defined by derived classes to calculate the set of enum items which indicate the receivers the message shall be propagated to.

      This is the only method which needs to be overrideden by a subclass to be operative.

      Parameters:
      m - the message to be sent.
      Returns:
      all tags to which this message shall be sent.
    • receive

      public void receive(M message)
      Propagates the received message to all receivers indicated by the calculated enum item set. Calls getOutputTags(Message) to calculate this set.
      Parameters:
      message - the message to be sent.
    • all

      public static <E extends Enum<E>, M extends Message> MessageDemux<E,M> all(Class<E> tags)
      Delivers a trivial instantiation of MessageDemux, see MessageDemux.All.
      Type Parameters:
      E - the type of the controlling tags.
      M - the type of the messages.
      Parameters:
      tags - the class of the enum type which shall control the message delivery.
      Returns:
      a new instance of MessageDemux which sends to all registered receivers.
    • byKind

      public static <M extends Message> MessageDemux<Message.Kind,M> byKind()
      Factory method for the constructor MessageDemux.ByKind
      Type Parameters:
      M - the class of the messages.
      Returns:
      a demultiplexer which is controlled by the kinds of the messages.