Class MessageTee<M extends Message>
- Type Parameters:
M
- the type of the messages
- All Implemented Interfaces:
MessageReceiver<M>
add(MessageReceiver)
.
The identical message object is sent to all receivers, so in most use cases it should be treated read-only by subsequent processing in the drain pipelines.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final List
<MessageReceiver<? super M>> List of all receivers. -
Constructor Summary
ConstructorsConstructorDescriptionSimplest constructor.MessageTee
(MessageReceiver<? super M> drain1) Constructor with one given receiver.MessageTee
(MessageReceiver<? super M>... drains) Constructor with the given receivers.MessageTee
(MessageReceiver<? super M> drain1, MessageReceiver<? super M> drain2) Constructor with two given receivers.MessageTee
(MessageReceiver<? super M> drain1, MessageReceiver<? super M> drain2, MessageReceiver<? super M> drain3) Constructor with three given receivers. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(MessageReceiver<? super M> drain) Adds the message receiver at the end of the list of all current drains.final void
add
(MessageReceiver<? super M>... newdrains) Adds the message receivers at the end of the list of all current drains.void
add
(MessageReceiver<? super M> drain1, MessageReceiver<? super M> drain2) Adds the message receivers at the end of the list of all current drains.void
addAll
(Iterable<MessageReceiver<? super M>> newdrains) Adds the message receivers at the end of the list of all current drains.void
clear()
Clear the list of all receivers.List
<MessageReceiver<? super M>> Return an unmodifiable list of all receivers.void
Propagates the message received sequentially to a multitude of current drains.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
-
drains
List of all receivers. The sequential order is respected when sending the message, but should better not be relevant.
-
-
Constructor Details
-
MessageTee
public MessageTee()Simplest constructor. The receivers must be added subsequently. -
MessageTee
Constructor with the given receivers.(Attention when method add is redefined by a subclass to possible this-escapes.)
- Parameters:
drains
- the list of receivers- See Also:
-
MessageTee
Constructor with one given receiver. (Non-vararg specialization avoidsunchecked
warnings.)(Attention when method add is redefined by a subclass to possible this-escapes.)
- Parameters:
drain1
- the only initial receiver (more can be added)- See Also:
-
MessageTee
Constructor with two given receivers. (Non-vararg specialization avoidsunchecked
warnings.)(Attention when method add is redefined by a subclass to possible this-escapes.)
- Parameters:
drain1
- the first initial receiverdrain2
- the second initial receiver (more can be added)- See Also:
-
MessageTee
public MessageTee(MessageReceiver<? super M> drain1, MessageReceiver<? super M> drain2, MessageReceiver<? super M> drain3) Constructor with three given receivers. (Non-vararg specialization avoidsunchecked
warnings.)(Attention when method add is redefined by a subclass to possible this-escapes.)
- Parameters:
drain1
- the first initial receiverdrain2
- the second initial receiverdrain3
- the second initial receiver (more can be added)- See Also:
-
-
Method Details
-
getDrains
Return an unmodifiable list of all receivers.- Returns:
- an unmodifiable list of all receivers.
-
add
Adds the message receiver at the end of the list of all current drains. If it is already contained at some position in the list, it is first removed and then re-inserted at the end of the list.- Parameters:
drain
- the receiver to add or to re-add
-
add
Adds the message receivers at the end of the list of all current drains. (Non-vararg specialization avoidsunchecked
warnings.)- Parameters:
drain1
- the first receiver to add or re-adddrain2
- the second receiver to add or re-add- See Also:
-
add
Adds the message receivers at the end of the list of all current drains.- Parameters:
newdrains
- the receivers to add or re-add- See Also:
-
addAll
Adds the message receivers at the end of the list of all current drains.- Parameters:
newdrains
- the receivers to add or re-add- See Also:
-
clear
public void clear()Clear the list of all receivers. -
receive
Propagates the message received sequentially to a multitude of current drains.In case that while propagating the message to the drains, the very same message is thrown as an exception, then it will be caught and re-thrown after the propagation to all drains is completed. Other exceptions, esp. the throwing of different messages, are not intercepted.
- Specified by:
receive
in interfaceMessageReceiver<M extends Message>
- Parameters:
message
- to propagate
-