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