Class WireMessage (0.27.1)

publicabstractclassWireMessage

Generic representation for a wire message, generally executed by calling send.

Inheritance

java.lang.Object > WireMessage

Static Methods

getParameters(DataInputStream input)

protectedstaticbyte[][]getParameters(DataInputStreaminput)

Extracts parameters/arguments from the user input.

Parameter
NameDescription
inputDataInputStream

The data stream containing the user request.

Returns
TypeDescription
byte[][]

A byte array of user-defined parameters to be bound.

Exceptions
TypeDescription
Exception

If reading fails in any way.

Constructors

WireMessage(ConnectionHandler connection, int length)

publicWireMessage(ConnectionHandlerconnection,intlength)
Parameters
NameDescription
connectionConnectionHandler
lengthint

Fields

connection

protectedConnectionHandlerconnection
Field Value
TypeDescription
ConnectionHandler

inputStream

protectedDataInputStreaminputStream
Field Value
TypeDescription
DataInputStream

length

protectedintlength
Field Value
TypeDescription
int

outputStream

protectedDataOutputStreamoutputStream
Field Value
TypeDescription
DataOutputStream

Methods

getHeaderLength()

protectedintgetHeaderLength()

How many bytes is taken by the payload header. Header is defined here as protocol definition + length. Most common value here is four bytes, so we keep that as default. Effectively, this is how much of the message you "don't" want to read from the message's total length with readAll.

Returns
TypeDescription
int

The remaining length to be processed once "header" information is processed.

getIdentifier()

publicabstractStringgetIdentifier()

Used for logging.

Returns
TypeDescription
String

Message Identifier (int for Bootstrap, char otherwise).

getMessageName()

protectedabstractStringgetMessageName()

Used for logging.

Returns
TypeDescription
String

The official name of the wire message.

getPayloadString()

protectedabstractStringgetPayloadString()

Used for logging.

Returns
TypeDescription
String

Payload metadata.

nextHandler()

publicvoidnextHandler()

Some messages may have some more context and require some order. This handles state machine setting for ConnectionHandler.

Exceptions
TypeDescription
Exception

read(int length)

publicStringread(intlength)

Reads a fixed-length string from the saved stream. The string still needs to be null-terminated, but the read is more efficient, as we can read the entire string in one go instead of continuously checking for a null-terminator.

Parameter
NameDescription
lengthint

The number of bytes to read.

Returns
TypeDescription
String

the string.

Exceptions
TypeDescription
IOException

if an error occurs while reading from the stream, or if no null-terminator is found at the end of the string.

readAll()

protectedStringreadAll()

Read the remainder of the received message. To be called once metadata for the message is read. Metadata is designated as type, length, etc.

Returns
TypeDescription
String

The remainder of the message in String format.

Exceptions
TypeDescription
Exception

If reading fails in any way.

readString()

publicStringreadString()

Reads a null-terminated string from a DataInputStream. Note that though existing solutions for this exist, they are either not keyed exactly for our use case, or would lead to a more combersome addition to this codebase. Also note the 128 byte length is chosen from profiling and determining that it exceeds the 90th percentile size for inbound messages.

Returns
TypeDescription
String

the string.

Exceptions
TypeDescription
IOException

if an error occurs while reading from the stream, or if no null-terminator is found before the end of the stream.

send()

publicvoidsend()

Once the message is ready, call this to send it across the wire. Effectively a template pattern.

Exceptions
TypeDescription
Exception

If the sending fails.

sendPayload()

protectedabstractvoidsendPayload()

Override this method to include post-processing and metadata in the sending process. Template method for send.

Exceptions
TypeDescription
Exception

If any step in output message fails.

toString()

publicStringtoString()
Returns
TypeDescription
String
Overrides