Record Class ChannelMessage
- Record Components:
sendSync- whether sending the message should block the current thread until the message is flushed.prioritized- whether this channel message should be handled with priority over other channel messages.channel- the channel to which the channel message gets sent. Mostly for identification reasons.message- the message key of this channel message. Mostly for identification reasons.content- the content of this channel message (the actual data to send).sender- the sender of the channel message. Should be, but must not the current network component.targets- the targets to which the channel message should get send.
A channel message has two main identification points. One is the channel to which the message gets sent. The channel is a string object which is generally used to collect multiple types of channel message to a collection of message types. On the other hand a channel message contains a message object which should be unique within in the network and is used to identify a channel message in a group messages sent to the same channel.
The message contains a DataBuf containing the actual content of the message. There is no real way to identify
which types are in the buffer or not, therefore it is crucial that a channel message gets identified via its channel
and/or message.
If targets were given that are not locatable in the network they will get ignored silently. On the other hand this means that if you try to send a channel message to a non-existing target, the send method will block until the future wait timeout (30 seconds by default) expired before returning.
Note: there is no guarantee that the sender of a channel message is the actual component sending the message, as the message can be modified on its way to the receiver.
The actual constructor of this class shouldn't get used. Use builder() instead.
- Since:
- 4.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA builder for a channel message. -
Field Summary
FieldsModifier and TypeFieldDescriptionThe field for thechannelrecord component.The field for thecontentrecord component.The field for themessagerecord component.private final booleanThe field for theprioritizedrecord component.private final @NonNull ChannelMessageSenderThe field for thesenderrecord component.private final booleanThe field for thesendSyncrecord component.private final @NonNull Collection<ChannelMessageTarget> The field for thetargetsrecord component. -
Constructor Summary
ConstructorsConstructorDescriptionChannelMessage(boolean sendSync, boolean prioritized, @NonNull String channel, @NonNull String message, @NonNull DataBuf content, @NonNull ChannelMessageSender sender, @NonNull Collection<ChannelMessageTarget> targets) Creates an instance of aChannelMessagerecord class. -
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull ChannelMessage.Builderbuilder()Constructs a new, empty builder for a ChannelMessage.static @NonNull ChannelMessage.BuilderConstructs a new builder which contains all needed data to respond to a channel message.channel()Returns the value of thechannelrecord component.content()Returns the value of thecontentrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.message()Returns the value of themessagerecord component.private @NonNull CloudMessengerUtil method to get the current messenger of the environment.booleanReturns the value of theprioritizedrecord component.voidsend()Sends this channel message using the current messenger of the environment.sender()Returns the value of thesenderrecord component.Sends this channel message as a query and suspends the calling thread until all responses is available or the query timeout of 30 seconds is exceeded.Sends this channel message as a query and returns a future which waits for target component(s) to respond.Sends this channel message as a query and returns and blocks until one of the target component responded to this message or the query timeout of 30 seconds is exceeded.Sends this channel message as a query and returns a future which waits for target component(s) to respond.booleansendSync()Returns the value of thesendSyncrecord component.targets()Returns the value of thetargetsrecord component.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
sendSync
private final boolean sendSyncThe field for thesendSyncrecord component. -
prioritized
private final boolean prioritizedThe field for theprioritizedrecord component. -
channel
-
message
-
-
sender
The field for thesenderrecord component. -
targets
The field for thetargetsrecord component.
-
-
Constructor Details
-
ChannelMessage
public ChannelMessage(boolean sendSync, boolean prioritized, @NonNull @NonNull String channel, @NonNull @NonNull String message, @NonNull @NonNull DataBuf content, @NonNull @NonNull ChannelMessageSender sender, @NonNull @NonNull Collection<ChannelMessageTarget> targets) Creates an instance of aChannelMessagerecord class.- Parameters:
sendSync- the value for thesendSyncrecord componentprioritized- the value for theprioritizedrecord componentchannel- the value for thechannelrecord componentmessage- the value for themessagerecord componentcontent- the value for thecontentrecord componentsender- the value for thesenderrecord componenttargets- the value for thetargetsrecord component
-
-
Method Details
-
builder
Constructs a new, empty builder for a ChannelMessage.- Returns:
- a new, empty builder for a ChannelMessage.
-
buildResponseFor
@Contract("_ -> new") @NonNull public static @NonNull ChannelMessage.Builder buildResponseFor(@NonNull @NonNull ChannelMessage input) Constructs a new builder which contains all needed data to respond to a channel message. As the channel message will get directly handled by the waiting future, there is no need to actually set the channel and message of the returned builder. The new builder will target the sender of the given input and has no data set.- Parameters:
input- the channel message to respond to.- Returns:
- a new builder for a channel message holding all base information to respond to the given source message.
- Throws:
NullPointerException- if the given input is null.
-
send
public void send()Sends this channel message using the current messenger of the environment. This is in fact just a shortcut method forCloudMessenger.sendChannelMessage(ChannelMessage). This method will not wait for the target component to respond (it doesn't even expect a response) but for the handling component to send the message. -
sendQueryAsync
Sends this channel message as a query and returns a future which waits for target component(s) to respond. This method is a shortcut forCloudMessenger.sendChannelMessageQueryAsync(ChannelMessage). The future will be completed when the target component responds or the query future times out (after 30 seconds).- Returns:
- a future completed with all responses of all target components of this channel message.
-
sendSingleQueryAsync
Sends this channel message as a query and returns a future which waits for target component(s) to respond. Only the first response of any target will get sent back to this component. This is in particular useful if there is only one target, or you are only expecting one component of the target components to respond. This is in fact just a shortcut method forCloudMessenger.sendSingleChannelMessageQueryAsync(ChannelMessage). The future will be completed when one target component responds or the query future times out (after 30 seconds).- Returns:
- a future completed with the first response of any target of this channel message.
-
sendQuery
Sends this channel message as a query and suspends the calling thread until all responses is available or the query timeout of 30 seconds is exceeded. This method is a shortcut forCloudMessenger.sendChannelMessageQuery(ChannelMessage).- Returns:
- all responses of all components this channel message is targeting.
-
sendSingleQuery
Sends this channel message as a query and returns and blocks until one of the target component responded to this message or the query timeout of 30 seconds is exceeded. This is in particular useful if there is only one target, or you are only expecting one component of the target components to respond. This is in fact just a shortcut method forCloudMessenger.sendSingleChannelMessageQueryAsync(ChannelMessage).- Returns:
- the first response of any component this message is targeting.
-
messenger
Util method to get the current messenger of the environment.- Returns:
- the current messenger of the environment.
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
sendSync
-
prioritized
public boolean prioritized()Returns the value of theprioritizedrecord component.- Returns:
- the value of the
prioritizedrecord component
-
channel
-
message
-
content
-
sender
-
targets
-