Class RoutedMessage

java.lang.Object
com.tccc.kos.commons.web.websocket.router.msg.RoutedMessage
Direct Known Subclasses:
InboundMessage, OutboundMessage

public abstract class RoutedMessage extends Object
Abstract base class for all messages that pass through the router.
Since:
1.0
Version:
2022-10-26
  • Field Details

  • 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, otherwise false
    • setHeadersModified

      public void setHeadersModified(boolean headersModified)
      Sets the internal "headers modified" flag.
      Parameters:
      headersModified - the headers modified flag
    • getType

      public String getType()
      Returns the message type.
      This is the header named "type".
      Returns:
      the message type, or null if it doesn't exist
    • setType

      public void setType(String type)
      Sets the message type, which is the simply "type" header.
      Parameters:
      type - the message type
    • getSrcAddr

      public String 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

      public void setSrcAddr(String addr)
      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

      public String 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

      public void setDstAddr(String addr)
      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

      public String 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

      public void setTrace(String trace)
      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

      public String getHeader(String name)
      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

      public boolean hasHeader(String name)
      Returns true if the specified header exists.
      Parameters:
      name - the header name
      Returns:
      true if the header exists
    • getHeaders

      public Map<String,String> getHeaders()
      Returns the map of all headers.
      Returns:
      the map containing the headers; never null
    • addHeader

      public void addHeader(String name, Object value)
      Adds the specified header to the message.
      If the value is null , then the header is removed.
      Parameters:
      name - the header name
      value - the header value
    • addHeaders

      public void addHeaders(Map<String,?> headers)
      Adds all the headers from the specified map. All values are converted to string via their toString() method.
      Parameters:
      headers - a map of headers
    • removeHeader

      public String removeHeader(String name)
      Removes the specified header.
      Parameters:
      name - the header name to remove
      Returns:
      the value removed, or null if nothing removed
    • getBody

      public abstract Object getBody()
      Returns the body of the message.
      Returns:
      the message body
    • getSerializedHeaders

      public String getSerializedHeaders()
      Serializes the headers in the format:
      header1:value1
      header2:value2
      header3:value3
      Returns:
      string that lists all the headers, one per line
    • toRouterAddr

      public String toRouterAddr(String addr)
      Given a string address, returns the address of the associated router.
      Returns:
      address of associated router