com.ericsson.research.trap.spi.TrapMessage |
Known Indirect Subclasses |
TrapMessage is a message that can be transported via Trap. This class defines the functionality of TrapMessages. A TrapMessage encapsulates the data to be sent in a structured format, and allows for easy serialization.
The messages have two representation formats: 8-bit and 7-bit. The 8-bit is the recommended format, while 7-bit is reserved for legacy use cases. The diagram below represents the 8-bit message format.
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-----------+---------------+-------------------------------+ |1|0| MESSAGEOP |C| Reserved1 | AUTHLEN | ; R = Reserved, C = Compressed Flag, CHANID = Channel ID 32 +-+-+-----------+---------------+-------------------------------+ | Message ID | 64 +---------------+---------------+-------------------------------+ | Reserved2 | ChannelID | Reserved3 | 96 +---------------+---------------+-------------------------------+ | Content Length | ; Length of the payload that begins *after* AUTHLEN 128 +---------------------------------------------------------------+ | ... Authentication Data (0...65535 bytes) ... | ; MUST be US-ASCII (0x20 - 0x7F) +---------------------------------------------------------------+ | Payload Data | ; Optional content, specified by Content Length + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + ; Payload begins at offset (in bytes) 12+AUTHLEN | Payload Data continued ... | +---------------------------------------------------------------+
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
TrapMessage.Format | The Format class specifies the available Trap message formats. | ||||||||||
TrapMessage.Operation | This subclass defines the possible message operations of a TrapMessage. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Attempts to deserialize a TrapMessage.
| |||||||||||
Accessor for the authentication payload.
| |||||||||||
Retrieves the channel this message was sent/received on.
| |||||||||||
Retrieves the compressed data, if compression is enabled.
| |||||||||||
Gets the message's data payload, as set by the user.
| |||||||||||
Accessor for the message format.
| |||||||||||
Fetches the message ID.
| |||||||||||
Fetches the message operation.
| |||||||||||
Checks whether this message will be or was transmitted compressed.
| |||||||||||
The length in bytes of this message, as it would appear when serialized using the current settings.
| |||||||||||
Serializes this TrapMessage into a byte array.
| |||||||||||
Sets the message's authentication string/header
| |||||||||||
Sets the channel this message should be transmitted on.
| |||||||||||
Sets the compressed flag of this message.
| |||||||||||
Sets the message's data (payload)
| |||||||||||
Sets a new message format.
| |||||||||||
Sets the message id.
| |||||||||||
Sets the message operation.
| |||||||||||
Generates a human-readable string describing this message.
|
Attempts to deserialize a TrapMessage.
rawData | The data to read from |
---|---|
offset | The start of the buffer, where to read from. |
length | The maximum number of bytes that can be read |
UnsupportedEncodingException | if the message encoding is not supported |
---|
Accessor for the authentication payload.
Retrieves the channel this message was sent/received on.
Retrieves the compressed data, if compression is enabled. Else returns the message data.
Gets the message's data payload, as set by the user. If data is not serialized at this point, will serialize it. If serialized, the resulting data is cached, so serialization occurs at most once.
Accessor for the message format.
Fetches the message ID.
Fetches the message operation.
Checks whether this message will be or was transmitted compressed.
The length in bytes of this message, as it would appear when serialized using the current settings. There is no guarantee this will be the number of bytes sent on the wire, but it is an estimate (if nothing else changes).
This method performs an estimate computation, so may be off in case of compressible encodings.
Serializes this TrapMessage into a byte array. This includes the headers and data. The format used is the one specified in the message settings. This operation is not cached.
IOException | If serialization fails. |
---|
Sets the message's authentication string/header
authData | The string to set |
---|
Sets the channel this message should be transmitted on. Trap supports channels with IDs 0-63, where 0 is the default channel. Each channel has a separate transmission queue, enabling multiplexing onto a single Trap logical connection.
Note that ID 0 is the control channel on which trap signalling goes. While it is possible to send a message on this channel, it is strongly discouraged. Sending application messages on channel ID 0 will be deprecated in the future.
channelID | The Channel ID to set. Allowed values are [0,63]. This setting should not be changed after the message is enqueued. |
---|
IllegalArgumentException | If channelId is outside the permitted range of [0,63]. |
---|
Sets the compressed flag of this message. If true, Trap will attempt to automatically compress (and decompress on the remote side)
isCompressed | true if Trap should compress this message, false otherwise. |
---|
Sets the message's data (payload)
data | The data to set |
---|
Sets a new message format.
format | The new format to use for serialzation. |
---|
Sets the message id. Messages must have a unique ID (except for certain transport messages). This method should only be called by Trap.
newMessageId | The new message ID. |
---|
Sets the message operation.
op | The new operation. |
---|
Generates a human-readable string describing this message. The string representation will contain the message operation, channel, id, and the data length (if present). For example:
OK/C0/0 - Plain OK message with no body, on the control channel. MESSAGE/C5/42/6 - Message with op MESSAGE, on channel 5, with ID 42, and 6 bytes payload.It is not possible to use toString() to serialize the message. The
serialize()
method exists for that
(but is not human readable).