Package org.apache.juneau.console.bus
Class BusFrames
java.lang.Object
org.apache.juneau.console.bus.BusFrames
The bus wire format, version 1: one JSON object per frame, in a canonical field order shared with the
browser codec and pinned by
bus-frames-corpus.json.
The SSE transport writes each frame as event: bus, id: <seq>, data: <frame>; the WebSocket
transport sends one frame per text message.
Example:
String
- Since:
- 10.0.0
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringAclearframe.static JsonMapDecodes and validates one frame.static StringEncodes a frame given as a map, in canonical field order, omitting absent optional fields.static StringAnerrorframe.static Stringping()static StringApubframe.static StringresyncBegin(long seq) static StringresyncEnd(long seq) static OptionalLongExtracts theseqof a frame produced by this class (it is always the last field when present).static intutf8Length(String s) The UTF-8 length of a string, without allocating its bytes.
-
Field Details
-
VERSION
The wire format version.- See Also:
-
EVENT
The SSE event name carrying frames.- See Also:
-
TYPES
The frame types of version 1.
-
-
Method Details
-
pub
Apubframe.- Parameters:
topic- The topic.payloadJson- The payload, already serialized as JSON.retained- Whether the value is retained.seq- The session sequence number.- Returns:
- The encoded frame.
-
clear
Aclearframe.- Parameters:
topic- The retained topic being cleared.seq- The session sequence number.- Returns:
- The encoded frame.
-
resyncBegin
- Parameters:
seq- The session sequence number. @return The encodedresync-beginframe.
-
resyncEnd
- Parameters:
seq- The session sequence number. @return The encodedresync-endframe.
-
ping
- Returns:
- The encoded
pingframe.
-
error
Anerrorframe.- Parameters:
code- Thebus:*code.message- Fixed server text.topic- The topic concerned. Can benull .- Returns:
- The encoded frame.
-
encode
Encodes a frame given as a map, in canonical field order, omitting absent optional fields.- Parameters:
frame- The frame (typerequired;vis always written as1).- Returns:
- The encoded frame.
- Throws:
IllegalArgumentException- On an unknowntype, or whentopic,codeormessageis missing or not a string, orretainedis not a boolean.
-
decode
Decodes and validates one frame. The result holds only the known fields of its type, in canonical order.- Parameters:
text- The frame text (strict RFC 8259 JSON).- Returns:
- The frame.
- Throws:
BusRefusal-bus:bad-framewhen the text is not a valid version-1 frame.
-
seq
Extracts theseqof a frame produced by this class (it is always the last field when present).- Parameters:
encoded- An encoded frame.- Returns:
- The sequence number, or empty for
pinganderror.
-
utf8Length
The UTF-8 length of a string, without allocating its bytes.- Parameters:
s- The string.- Returns:
- The number of UTF-8 bytes.
-