Package eu.bandm.tools.message
Class SingleSender<M extends Message>
java.lang.Object
eu.bandm.tools.message.SingleSender<M>
- Type Parameters:
M
- the message type propagated by this sender
- Direct Known Subclasses:
MessageCatcher
,MessageMapper
,MessagePasser
,SimpleMessage.LocationMapper
,SimpleMessage.Sender
Common superclass of classes which send messages to one single
switchable drain.
This includes some genuine message sources, ie. senders only, but most
of the subclasses are
MessageReceiver
s, which pass on
the received messages to that single drain.
That drain can be inquired and set, ie. it can change dynamically
during execution. Intentionally, the code will crash
if it is equal to null and send(M)
is called.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected @Opt MessageReceiver
<? super M> Whereto the messages are passed. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Constructor which sets nothing.protected
SingleSender
(@Opt MessageReceiver<? super M> r) Constructor which setsdrain
. -
Method Summary
Modifier and TypeMethodDescription@Opt MessageReceiver
<? super M> getDrain()
Return the currently active drain.@Opt MessageReceiver
<? super M> Deprecated.void
Send a message to the currentdrain
.setDrain
(@Opt MessageReceiver<? super M> r) Set the drain for the sent messages.setReceiver
(@Opt MessageReceiver<? super M> r) Deprecated.
-
Field Details
-
drain
Whereto the messages are passed.
-
-
Constructor Details
-
SingleSender
protected SingleSender()Constructor which sets nothing. After calling this constructor, a call tosetReceiver(MessageReceiver)
with a non-null argument is necessary before you can usesend(Message)
. Otherwise invokingsend(M)
will crash intentionally. -
SingleSender
Constructor which setsdrain
.- Parameters:
r
- the receiver of the sent messages.- See Also:
-
-
Method Details
-
setReceiver
@Deprecated(since="1.0.1") public SingleSender<M> setReceiver(@Opt @Opt MessageReceiver<? super M> r) Deprecated.Set the receiver of the sent messages. As long as the value of the receiver is null, invokingsend(M)
will crash intentionally.- Parameters:
r
- the receiver of the sent messages.- Returns:
- this instance, for method chaining.
-
setDrain
Set the drain for the sent messages. As long as the value of the receiver is null, invokingsend(M)
will crash intentionally.- Parameters:
r
- the drain for the sent messages.- Returns:
- this instance, for method chaining.
-
getReceiver
Deprecated.usegetDrain()
instead.Return the currently active drain.- Returns:
- the currently active drain.
-
getDrain
Return the currently active drain.- Returns:
- the currently active drain.
-
send
Send a message to the currentdrain
. Intentionally, the code will crash if that is currently null.- Parameters:
m
- the message to be sent to the current receiver.
-
getDrain()
instead.