Class ChannelMessageReceiveEvent
java.lang.Object
eu.cloudnetservice.driver.event.Event
eu.cloudnetservice.driver.event.events.network.NetworkEvent
eu.cloudnetservice.driver.event.events.channel.ChannelMessageReceiveEvent
An event called when a channel message of another component is received which targets the current network component.
In a node environment this event will not get called when the channel message is not targeting the current node,
event though the nodes receives the channel message for redirection into the cluster.
This event is especially useful as it removes the need to read channel messages by using an own created network listener and gives the possibility to easily respond channel messages when needed.
- Since:
- 4.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ChannelMessageprivate final booleanprivate CompletableFuture<ChannelMessage> -
Constructor Summary
ConstructorsConstructorDescriptionChannelMessageReceiveEvent(@NonNull ChannelMessage message, @NonNull NetworkChannel networkChannel, boolean query) Constructs a new instance of a channel message receive event. -
Method Summary
Modifier and TypeMethodDescriptionvoidbinaryResponse(@NonNull DataBuf dataBuf) Sets the response of this channel message to a channel message which just contains the given buffer as the content of it.channel()Get the channel to which the channel message got sent.Get the original channel message which was sent.content()Get the content of the channel message.message()Get the message key of the channel message.booleanquery()Get if this channel message is a query.Get the current query response to the received channel message.voidqueryResponse(@Nullable ChannelMessage queryResponse) Sets the query response of the received channel message to the given channel message.voidqueryResponse(@Nullable CompletableFuture<ChannelMessage> queryResponse) Sets the query response of the received channel message to the given channel message.sender()Get the original sender of the channel message.targets()Get all targets of the received channel message.Methods inherited from class eu.cloudnetservice.driver.event.events.network.NetworkEvent
networkChannel
-
Field Details
-
channelMessage
-
query
private final boolean query -
queryResponse
-
-
Constructor Details
-
ChannelMessageReceiveEvent
public ChannelMessageReceiveEvent(@NonNull @NonNull ChannelMessage message, @NonNull @NonNull NetworkChannel networkChannel, boolean query) Constructs a new instance of a channel message receive event.- Parameters:
message- the original message sent to the component.networkChannel- the channel from which the message came.query- true if the channel message expects a response, false otherwise.- Throws:
NullPointerException- if the given message or channel is null.
-
-
Method Details
-
sender
Get the original sender of the channel message.This call is equivalent to
channelMessage().sender().- Returns:
- the original sender of the channel message.
-
targets
Get all targets of the received channel message.This call is equivalent to
channelMessage().targets().- Returns:
- all targets of the received channel message.
-
channel
-
message
-
channelMessage
Get the original channel message which was sent.- Returns:
- the original channel message which was sent.
-
content
Get the content of the channel message. The content will not get released when reading from it, however there is no guarantee that a read from the buffer will succeed. A call toDataBuf.redoTransaction()will ensure that the reader index of the buffer is reset to the first byte of the buffer (any read will start from the beginning again then).This call is equivalent to
channelMessage().content().- Returns:
- the content of the channel message.
-
query
public boolean query()Get if this channel message is a query. This means that the sending network components expects a response. But there is no need for this component to respond to the channel message.- Returns:
- true if the channel message expects a response, false otherwise.
-
binaryResponse
Sets the response of this channel message to a channel message which just contains the given buffer as the content of it.- Parameters:
dataBuf- the content of the channel message to respond with.- Throws:
NullPointerException- if the given content is null.IllegalArgumentException- if the received channel message is not expecting a response.
-
queryResponse
Get the current query response to the received channel message. Null means, that there will be no response by this component to the channel message.- Returns:
- the current query response to the received channel message.
-
queryResponse
Sets the query response of the received channel message to the given channel message. Null is accepted and a valid value, representing that there will be no response to the channel message.- Parameters:
queryResponse- the response to the received channel message.- Throws:
NullPointerException- if the given response is null.IllegalArgumentException- if the received channel message is not expecting a response.
-
queryResponse
Sets the query response of the received channel message to the given channel message. Null is accepted and a valid value, representing that there will be no response to the channel message. The caller of the event will wait for the given task to compute a response but will resume the calling thread.- Parameters:
queryResponse- a future completed with the query response to the received channel message.- Throws:
NullPointerException- if the given response future is null.IllegalArgumentException- if the received channel message is not expecting a response.
-