Package eu.bandm.tools.message
Class MessageLevelFilter<M extends Message>
java.lang.Object
eu.bandm.tools.message.SingleSender<M>
eu.bandm.tools.message.MessagePasser<M>
eu.bandm.tools.message.MessageLevelFilter<M>
- Type Parameters:
M
- the message subtype which can be received
- All Implemented Interfaces:
MessageReceiver<M>
A filter which sends messages only to its drain if their
level value is equal to or below a given threshold.
As with any MessagePasser, the receiver must be set to a non-null value before the first message is received. Otherwise the code may crash intentionally.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) int
Level threshold.(package private) EnumSet
<Message.Kind> Set of Message.Kind which will not be suppressed by the threshold, i.e. which will always be forwarded.Fields inherited from class eu.bandm.tools.message.SingleSender
drain
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor with no initial drain.MessageLevelFilter
(@Opt MessageReceiver<M> drain) Constructor with an initial drain. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Receive a message and propagate it when it passes the threshold.setDrain
(@Opt MessageReceiver<? super M> r) Set the drain of the sent messages.setLevel
(int level) Set the level threshold.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.Methods inherited from class eu.bandm.tools.message.SingleSender
getDrain, getReceiver, send, setReceiver
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface eu.bandm.tools.message.MessageReceiver
ifSubcriticalThen, ifSubcriticalThen, ifSubcriticalThenElse
-
Field Details
-
level
int levelLevel threshold. Only messages with a level equal or lower to this value are propagated. -
unfiltered
EnumSet<Message.Kind> unfilteredSet of Message.Kind which will not be suppressed by the threshold, i.e. which will always be forwarded. Initially, error and failure are contained here.
-
-
Constructor Details
-
MessageLevelFilter
public MessageLevelFilter()Constructor with no initial drain. Before the filter can be used,SingleSender.setReceiver(MessageReceiver)
must be called. -
MessageLevelFilter
Constructor with an initial drain.- Parameters:
drain
- the receiver of all messages which pass this filter.
-
-
Method Details
-
setDrain
Set the drain of the sent messages. As long as the value of that drain is null, invokingreceive(M)
may crash intentionally.- Overrides:
setDrain
in classSingleSender<M extends Message>
- Parameters:
r
- the drain of the sent messages.- Returns:
- this instance, for method chaining.
-
setLevel
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
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
Receive a message and propagate it when it passes the threshold.- Specified by:
receive
in interfaceMessageReceiver<M extends Message>
- Overrides:
receive
in classMessagePasser<M extends Message>
- Parameters:
m
- the message to receive.- Throws:
NullPointerException
- if the drain has not been set, either by constructor or by invokingSingleSender.setReceiver(MessageReceiver)
.
-