public class BlaubotMessage
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
BlaubotMessage.Priority
Priority for BlaubotMessages.
|
Modifier and Type | Field and Description |
---|---|
static int |
CHANNEL_FIELD_LENGTH |
static int |
CHUNK_ID_FIELD_LENGTH |
static int |
CHUNK_NO_FIELD_LENGTH |
static int |
FULL_HEADER_LENGTH |
static int |
PAYLOAD_LENGTH_FIELD_LENGTH |
static int |
PRIORITY_FIELD_LENGTH |
protected int |
sequenceNumber
An attribute that is not sent via the connection
Only used to send messages with the same priority in the order they were
queued.
|
static int |
TYPE_FIELD_LENGTH |
static int |
VERSION_FIELD_LENGTH |
Constructor and Description |
---|
BlaubotMessage()
Constructs a default message, which sends data on a default channel
|
Modifier and Type | Method and Description |
---|---|
int |
applyBytes(byte[] headerBytes)
Applies all data from the message schema except the payload, which has to be set afterwards
by setPayload(), to this instance.
|
protected static int |
calculateHeaderLength(BlaubotMessageType messageType)
Calculates a messages total header length by a given BlaubotMessageType
|
java.util.List<BlaubotMessage> |
createChunks(short chunkId)
Creates chunks of this message containing the given chunkId.
|
boolean |
equals(java.lang.Object o) |
static BlaubotMessage |
fromByteArray(byte[] messageBytes)
Deserializes a BlaubotMessage from a byte array.
|
static BlaubotMessage |
fromChunks(java.util.List<BlaubotMessage> chunks)
Creates a message from multiple chunks
|
short |
getChannelId()
Retrieves the channelId for which this message was designated.
|
short |
getChunkId()
If this message is a chunk message, gets the chunk id.
|
short |
getChunkNo()
If this message is a chunk message, returns the chunk number.
|
protected IBlaubotConnection |
getLastOriginatorConnection()
Gets the last originators connection.
|
BlaubotMessageType |
getMessageType() |
byte[] |
getPayload()
Retrieve this message's payload
|
BlaubotMessage.Priority |
getPriority() |
byte |
getProtocolVersion() |
int |
hashCode() |
static void |
main(java.lang.String[] args) |
static BlaubotMessage |
readFromBlaubotConnection(IBlaubotConnection connection)
Reads a message from a given connection (readFully)
|
static BlaubotMessage |
readFromBlaubotConnection(IBlaubotConnection blaubotConnection,
java.nio.ByteBuffer headerByteBuffer,
byte[] headerBuffer)
Reads a message from a given connection and reuses buffers
|
protected void |
setChannelId(short channelId) |
void |
setChunkId(short chunkId)
sets the chunk id
|
void |
setChunkNo(short chunkNo)
Sets the chunk number
|
protected void |
setLastOriginatorConnection(IBlaubotConnection originatorConnection) |
protected void |
setMessageType(BlaubotMessageType messageType) |
void |
setPayload(byte[] payload)
Set the payload of this message.
|
void |
setPriority(BlaubotMessage.Priority priority) |
protected void |
setProtocolVersion(byte protocolVersion) |
byte[] |
toBytes()
Serializes the message to a byte array.
|
java.lang.String |
toString() |
public static final int VERSION_FIELD_LENGTH
public static final int TYPE_FIELD_LENGTH
public static final int PRIORITY_FIELD_LENGTH
public static final int CHANNEL_FIELD_LENGTH
public static final int PAYLOAD_LENGTH_FIELD_LENGTH
public static final int CHUNK_ID_FIELD_LENGTH
public static final int CHUNK_NO_FIELD_LENGTH
public static final int FULL_HEADER_LENGTH
protected int sequenceNumber
public BlaubotMessage()
public java.util.List<BlaubotMessage> createChunks(short chunkId)
chunkId
- the chunk id to identify this messagejava.lang.IllegalArgumentException
- iff the message contains too much payload to chunk (more than Short.MAX_VALUE resulting chunks)public static BlaubotMessage fromChunks(java.util.List<BlaubotMessage> chunks)
chunks
- the complete list of chunks with the same chunkId. Must not be ordered.protected IBlaubotConnection getLastOriginatorConnection()
protected void setLastOriginatorConnection(IBlaubotConnection originatorConnection)
public byte getProtocolVersion()
protected void setProtocolVersion(byte protocolVersion)
public BlaubotMessageType getMessageType()
protected void setMessageType(BlaubotMessageType messageType)
public BlaubotMessage.Priority getPriority()
public void setPriority(BlaubotMessage.Priority priority)
public short getChannelId()
protected void setChannelId(short channelId)
public byte[] getPayload()
public void setPayload(byte[] payload)
payload
- the payload bytesjava.lang.IllegalArgumentException
- if the payload length exeeds 65535 bytespublic int applyBytes(byte[] headerBytes)
headerBytes
- the byte array containing all header informationsprotected static int calculateHeaderLength(BlaubotMessageType messageType)
messageType
- the message typepublic byte[] toBytes()
public static BlaubotMessage fromByteArray(byte[] messageBytes)
messageBytes
- byte array containing header and payloadpublic short getChunkNo()
public void setChunkNo(short chunkNo)
chunkNo
- has to be 1-basedpublic short getChunkId()
public void setChunkId(short chunkId)
chunkId
- the chunk idpublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public static BlaubotMessage readFromBlaubotConnection(IBlaubotConnection connection) throws java.io.IOException
connection
- the connectionjava.io.IOException
- if something goes wrongpublic static BlaubotMessage readFromBlaubotConnection(IBlaubotConnection blaubotConnection, java.nio.ByteBuffer headerByteBuffer, byte[] headerBuffer) throws java.io.IOException
blaubotConnection
- the connectionheaderByteBuffer
- the byte buffer around header bufferheaderBuffer
- the header bufferjava.io.IOException
- if something goes wrongpublic static void main(java.lang.String[] args)