public abstract class Message
extends java.lang.Object
Each MessageType must have a specific derivation of the Message abstract class.
The "prologue" information is managed by this parent class "Message" in the "fromInputStream" static method, and "computePrologue" instance method.
The prologue format is:
[0xF1 (Flag 2 bytes)] + [Message Length (4 bytes)] + [Message Type (1 byte)] + [Message Origin IP (4 bytes)] + [Message Origin port (2 bytes)]
Messages must be received using the static method "fromInputStream". It calls inside its code the "fromInputStream" of a specific instance depending of the message type.
Modifier and Type | Class and Description |
---|---|
static class |
Message.MessageType |
Modifier and Type | Field and Description |
---|---|
protected byte[] |
bufferHeader |
protected byte[] |
bufferPayload |
protected byte[] |
bufferPrologue |
protected static byte[] |
msgFlag |
protected IPPort |
sourceIPPort |
protected long |
timeStamp |
protected Message.MessageType |
type |
Constructor and Description |
---|
Message() |
Modifier and Type | Method and Description |
---|---|
byte[] |
computePrologue()
Helper method to compute the header of an already populated message.
|
static Message |
fromInputStream(java.io.InputStream is)
Static method to create a new specific "MessageXXX" according the message
type contained in the prologue.
|
protected abstract boolean |
fromInputStream(java.io.InputStream is,
int size)
This method populates the "MessageXXX" instance reading data from an
input stream.
|
byte[] |
getBufferHeader() |
byte[] |
getBufferPayload() |
byte[] |
getBufferPrologue() |
IPPort |
getSourceIPPort() |
long |
getTimeStamp() |
Message.MessageType |
getType() |
protected abstract void |
toOutputStream(java.io.OutputStream os)
It writes the "MessageXXX" instance to the specified stream.
|
protected byte[] bufferHeader
protected byte[] bufferPayload
protected byte[] bufferPrologue
protected static byte[] msgFlag
protected IPPort sourceIPPort
protected long timeStamp
protected Message.MessageType type
public byte[] computePrologue()
public static Message fromInputStream(java.io.InputStream is) throws java.io.IOException
is
- java.io.IOException
protected abstract boolean fromInputStream(java.io.InputStream is, int size) throws java.io.IOException
is
- size
- java.io.IOException
public byte[] getBufferHeader()
public byte[] getBufferPayload()
public byte[] getBufferPrologue()
public IPPort getSourceIPPort()
public long getTimeStamp()
public Message.MessageType getType()
protected abstract void toOutputStream(java.io.OutputStream os) throws java.io.IOException
os
- java.io.IOException