Class MessageLevelFilter<M extends Message>

java.lang.Object
eu.bandm.tools.message.MessageLevelFilter<M>
Type Parameters:
M - the message subtype which can be received
All Implemented Interfaces:
MessageReceiver<M>

public class MessageLevelFilter<M extends Message> extends Object implements MessageReceiver<M>
A filter which sends messages only to its sink if their level value is equal to or below a given threshold.
  • Field Details

    • level

      int level
      Level threshold. Only messages with a level equal or lower to this value are propagated.
    • drain

      MessageReceiver<? super M extends Message> drain
      The receiver of all messages which pass this filter.
    • unfiltered

      EnumSet<Message.Kind> unfiltered
      Set of Message.Kind which will not be suppressed by the threshold, i.e. which will always be forwarded.
  • Constructor Details

    • MessageLevelFilter

      public MessageLevelFilter()
      Constructor with no initial drain. Before the filter can be used, setDrain(MessageReceiver) must be called.
    • MessageLevelFilter

      public MessageLevelFilter(MessageReceiver<M> drain)
      Constructor with an initial drain.
      Parameters:
      drain - the receiver of all messages which pass this filter.
  • Method Details

    • setDrain

      public MessageLevelFilter<M> setDrain(MessageReceiver<? super M> drain)
      Set the receiver of all messages which pass this filter.
      Parameters:
      drain - the receiver of all messages which pass this filter.
      Returns:
      this for message chaining.
    • setLevel

      public MessageLevelFilter<M> setLevel(int level)
      Set the level threshold. Only messages with a level equal or lower to this value are propagated.
      Parameters:
      level - the threshold level.
      Returns:
      this for message chaining.
    • setUnfilteredKinds

      public MessageLevelFilter<M> setUnfilteredKinds(EnumSet<Message.Kind> unfiltered)
      Define the set of Message.Kind which will not be suppressed by the threshold, i.e. which will always be forwarded. The initial setting lets all error and failure messages pass, what is appropriate in most use cases.
      Parameters:
      unfiltered - the set of kinds which will not be suppressed by the level
      Returns:
      this for message chaining.
    • receive

      public void receive(M m)
      Receive a message and propagate it when it passes the threshold.
      Specified by:
      receive in interface MessageReceiver<M extends Message>
      Parameters:
      m - the message to receive.
      Throws:
      NullPointerException - if the drain has not been set, either by constructor or by invoking setDrain(MessageReceiver).