public class NetworkMessage
extends java.lang.Object
| Modifier and Type | Field | Description |
|---|---|---|
static int |
HEADER_LENGTH |
Length of the network message header (in bytes).
|
| Modifier and Type | Method | Description |
|---|---|---|
static NetworkMessage |
create() |
Creates an empty network message.
|
static NetworkMessage |
fromByteBuffer(java.nio.ByteBuffer buffer,
java.net.InetSocketAddress remoteEndPoint) |
Creates a
NetworkMessage from the given ByteBuffer containing the raw data. |
byte[] |
getPayload() |
Returns the payload of this message.
|
java.net.InetAddress |
getRemoteAddress() |
Returns the address of the remote end point associated with this message.
|
java.net.InetSocketAddress |
getRemoteEndPoint() |
Returns the remote end point associated with this message.
|
java.lang.String |
getRemoteHostName() |
Returns the host name of the remote end point associated with this message.
|
java.lang.Integer |
getRemotePort() |
Returns the port of the remote end point associated with this message.
|
java.util.UUID |
getUuid() |
Returns the UUID of this message.
|
boolean |
isValid() |
Checks whether the message is valid.
|
java.nio.ByteBuffer |
toByteBuffer() |
Returns a
ByteBuffer containing the raw data of this message. |
NetworkMessage |
withPayload(byte[] payload) |
Sets the payload of this message.
|
NetworkMessage |
withRandomUuid() |
Sets the UUID of this message to a random value.
|
NetworkMessage |
withRemoteEndPoint(java.net.InetSocketAddress remoteEndPoint) |
Sets the remote end point associated with this message.
|
NetworkMessage |
withUuid(java.util.UUID uuid) |
Sets the UUID of this message.
|
public static final int HEADER_LENGTH
public static NetworkMessage create()
public static NetworkMessage fromByteBuffer(java.nio.ByteBuffer buffer, java.net.InetSocketAddress remoteEndPoint) throws java.io.IOException
NetworkMessage from the given ByteBuffer containing the raw data.java.lang.IllegalArgumentException - if buffer is nulljava.lang.IllegalArgumentException - if remoteEndPoint is nulljava.io.IOExceptionpublic byte[] getPayload()
public java.net.InetAddress getRemoteAddress()
public java.net.InetSocketAddress getRemoteEndPoint()
public java.lang.String getRemoteHostName()
public java.lang.Integer getRemotePort()
public java.util.UUID getUuid()
public boolean isValid()
public java.nio.ByteBuffer toByteBuffer()
ByteBuffer containing the raw data of this message.java.lang.IllegalStateException - if the UUID has not yet been setpublic NetworkMessage withPayload(byte[] payload)
java.lang.IllegalArgumentException - if payload is nullpublic NetworkMessage withRandomUuid()
public NetworkMessage withRemoteEndPoint(java.net.InetSocketAddress remoteEndPoint)
java.lang.IllegalArgumentException - if remoteEndPoint is nulljava.lang.IllegalArgumentException - if remoteEndPoint.getPort() is 0public NetworkMessage withUuid(java.util.UUID uuid)
java.lang.IllegalArgumentException - if uuid is null