Class RoutedMessage
java.lang.Object
com.tccc.kos.commons.web.websocket.router.msg.RoutedMessage
- Direct Known Subclasses:
InboundMessage
,OutboundMessage
Abstract base class for all messages that pass through the router.
- Since:
- 1.0
- Version:
- 2022-10-26
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the specified header to the message.
If the value isnull
, then the header is removed.void
addHeaders
(Map<String, ?> headers) Adds all the headers from the specified map.boolean
Indicates if the headers in this routed message have been modified or not.abstract Object
getBody()
Returns the body of the message.Returns the destination address of the message (only used when routing).
This is the header named "dst-addr".Returns the header with the specified name.Returns the map of all headers.Serializes the headers in the format:
header1:value1
header2:value2
header3:value3Returns the source address of the message (only used when routing).
This is the header named "src-addr".getTrace()
Returns the trace header if there is one.
This is the header named "trace".getType()
Returns the message type.
This is the header named "type".boolean
Returns true if the specified header exists.boolean
isHide()
Return true if the message has a hide header, regardless of valueremoveHeader
(String name) Removes the specified header.void
setDstAddr
(String addr) Sets the destination address of the message (only used by the router), which is simply the "dst-addr" header.void
setHeadersModified
(boolean headersModified) Sets the internal "headers modified" flag.void
setHide()
Set the hide header so the message won't be picked up by sniffersvoid
setSrcAddr
(String addr) Sets the source address of the message (only used by the router), which is simply the "src-addr" header.void
Sets the trace header for the message, which is simply the "trace" header.void
Sets the message type, which is the simply "type" header.toRouterAddr
(String addr) Given a string address, returns the address of the associated router.
-
Field Details
-
HEADER_LINE_TERMINATOR
public static final char HEADER_LINE_TERMINATOR- See Also:
-
HEADER_NAME_VAL_SEPARATOR
public static final char HEADER_NAME_VAL_SEPARATOR- See Also:
-
HEADER_DST_ADDR
- See Also:
-
HEADER_SRC_ADDR
- See Also:
-
HEADER_TRACE
- See Also:
-
HEADER_HIDE
- See Also:
-
-
Constructor Details
-
RoutedMessage
public RoutedMessage()
-
-
Method Details
-
areHeadersModified
public boolean areHeadersModified()Indicates if the headers in this routed message have been modified or not.- Returns:
true
if headers have been modified, otherwisefalse
-
setHeadersModified
public void setHeadersModified(boolean headersModified) Sets the internal "headers modified" flag.- Parameters:
headersModified
- the headers modified flag
-
getType
Returns the message type.
This is the header named "type".- Returns:
- the message type, or
null
if it doesn't exist
-
setType
Sets the message type, which is the simply "type" header.- Parameters:
type
- the message type
-
getSrcAddr
Returns the source address of the message (only used when routing).
This is the header named "src-addr".- Returns:
- address of the sender, or
null
if it doesn't exist
-
setSrcAddr
Sets the source address of the message (only used by the router), which is simply the "src-addr" header.- Parameters:
addr
- the source address
-
getDstAddr
Returns the destination address of the message (only used when routing).
This is the header named "dst-addr".- Returns:
- address of the recipient, or
null
if it doesn't exist
-
setDstAddr
Sets the destination address of the message (only used by the router), which is simply the "dst-addr" header.- Parameters:
addr
- the destination address
-
getTrace
Returns the trace header if there is one.
This is the header named "trace".- Returns:
- the trace value to activate logs, or
null
if it doesn't exist
-
setTrace
Sets the trace header for the message, which is simply the "trace" header. This causes router infrastructure to log data about this message.- Parameters:
trace
- the trace string to put in the logs
-
isHide
public boolean isHide()Return true if the message has a hide header, regardless of value -
setHide
public void setHide()Set the hide header so the message won't be picked up by sniffers -
getHeader
Returns the header with the specified name.- Parameters:
name
- the header name- Returns:
- the value of the header, or
null
if it doesn't exist
-
hasHeader
Returns true if the specified header exists.- Parameters:
name
- the header name- Returns:
- true if the header exists
-
getHeaders
Returns the map of all headers.- Returns:
- the map containing the headers; never
null
-
addHeader
Adds the specified header to the message.
If the value isnull
, then the header is removed.- Parameters:
name
- the header namevalue
- the header value
-
addHeaders
Adds all the headers from the specified map. All values are converted to string via theirtoString()
method.- Parameters:
headers
- a map of headers
-
removeHeader
Removes the specified header.- Parameters:
name
- the header name to remove- Returns:
- the value removed, or
null
if nothing removed
-
getBody
Returns the body of the message.- Returns:
- the message body
-
getSerializedHeaders
Serializes the headers in the format:
header1:value1
header2:value2
header3:value3- Returns:
- string that lists all the headers, one per line
-
toRouterAddr
Given a string address, returns the address of the associated router.- Returns:
- address of associated router
-