Class WireMessage (0.27.0)

publicabstractclass WireMessage

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
Name Description
input DataInputStream

The data stream containing the user request.

Returns
Type Description
byte[][]

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

Exceptions
Type Description
Exception

If reading fails in any way.

Constructors

WireMessage(ConnectionHandler connection, int length)

publicWireMessage(ConnectionHandlerconnection,intlength)
Parameters
Name Description
connection ConnectionHandler
length int

Fields

connection

protectedConnectionHandlerconnection
Field Value
Type Description
ConnectionHandler

inputStream

protectedDataInputStreaminputStream
Field Value
Type Description
DataInputStream

length

protectedintlength
Field Value
Type Description
int

outputStream

protectedDataOutputStreamoutputStream
Field Value
Type Description
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
Type Description
int

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

getIdentifier()

publicabstractStringgetIdentifier()

Used for logging.

Returns
Type Description
String

Message Identifier (int for Bootstrap, char otherwise).

getMessageName()

protectedabstractStringgetMessageName()

Used for logging.

Returns
Type Description
String

The official name of the wire message.

getPayloadString()

protectedabstractStringgetPayloadString()

Used for logging.

Returns
Type Description
String

Payload metadata.

nextHandler()

publicvoidnextHandler()

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

Exceptions
Type Description
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
Name Description
length int

The number of bytes to read.

Returns
Type Description
String

the string.

Exceptions
Type Description
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
Type Description
String

The remainder of the message in String format.

Exceptions
Type Description
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
Type Description
String

the string.

Exceptions
Type Description
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
Type Description
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
Type Description
Exception

If any step in output message fails.

toString()

publicStringtoString()
Returns
Type Description
String
Overrides

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年10月30日 UTC.