Class AbstractMessage

java.lang.Object
ch.autumo.beetroot.server.message.AbstractMessage
Direct Known Subclasses:
ClientAnswer, ServerCommand

public abstract class AbstractMessage extends Object
Abstract message.

Reduce the transport layer to the max. with the option to encrypt all information with SHA3.

Messages are mainly used for dispatchers / distributed modules between the dedicated web-app installed in a web-container and the beetRoot server or for server administration commands.

It is also used for the file-server (if activated) to down- or upload files from/to a plug-able file storage and for roundtrip-checks of the file-server.

Messages for dispatchers are sent and received with ClientCommunicator and files are sent and received with FileTransfer; in this case messages are being used for coordinating the upload and download of files that are directly transported by sockets.
  • Field Details

    • LOG

      protected static final org.slf4j.Logger LOG
    • MSG_PART_SEPARATOR

      public static final String MSG_PART_SEPARATOR
      message part separator
      See Also:
    • MSG_PART_SEPARATOR_REGEXP

      public static final String MSG_PART_SEPARATOR_REGEXP
      message part separator regular expression
      See Also:
    • INTERNAL_MSG_PART_SEPARATOR

      public static final String INTERNAL_MSG_PART_SEPARATOR
      internal message part separator
      See Also:
    • INTERNAL_MSG_PART_SEPARATOR_REGEXP

      public static final String INTERNAL_MSG_PART_SEPARATOR_REGEXP
      internal message part separator regular expression
      See Also:
    • serverName

      public static String serverName
      server name
    • ENCRYPT

      protected static final boolean ENCRYPT
    • message

      protected String message
      Transport message.
    • entity

      protected String entity
      Transport entity name.
    • domain

      protected String domain
      Transport domain name.
    • id

      protected long id
      Transport entity ID.
    • fileId

      protected String fileId
      Transport file ID.
    • object

      protected Serializable object
      Additional transport object.
  • Constructor Details

    • AbstractMessage

      public AbstractMessage()
      Constructor.
    • AbstractMessage

      public AbstractMessage(String message)
      Constructor with a transport message. A transport message is usually the minimum of information needed.
      Parameters:
      message - text message with an own chosen format
  • Method Details

    • getJSONObject

      public org.json.JSONObject getJSONObject()
      Return a JSON object or null; null means the object hold by this message represents another object type, but it is always serializable.
      Returns:
      JSON object or null
    • setObject

      public void setObject(Serializable object)
      Set any serializable object, usually a JSON string is meaningful for transport.
      Parameters:
      object - serializable object, e.g. JSON string
    • getObject

      public Serializable getObject()
      Get serializable transport object hold by this message or null.
      Returns:
      transport object or null
    • setEntity

      public void setEntity(String entity)
      Set an entity associated with this message.
      Parameters:
      entity - entity
    • getEntity

      public String getEntity()
      Get entity associated with this message or null.
      Returns:
      entity or null.
    • getId

      public long getId()
      Get entity ID associated with this message or null.
      Returns:
      ID or 0.
    • getDomain

      public String getDomain()
      Get a domain associated with this message or null. A domain can help to categorize this message for specific destinations or logical containers.
      Returns:
      domain or null.
    • getFileId

      public String getFileId()
      File ID if this message is used to transport file information.
      Returns:
      File ID or 0
    • getData

      public byte[] getData() throws IOException
      Get transfer data; this includes all set information including an object.
      Returns:
      transfer data
      Throws:
      IOException - IO exception
    • getDataLength

      public int getDataLength() throws IOException
      Get transfer data length.
      Returns:
      transfer data length
      Throws:
      IOException - IO exception
    • getMessageIntValue

      public int getMessageIntValue(String key)
      Helper method for accessing paired transport message values. A paired transport message separates values with INTERNAL_MSG_PART_SEPARATOR and is set by the constructor AbstractMessage(String). Key-Value pairs are separated by the '=' sign.
      Parameters:
      key - key
      Returns:
      value
    • getMessageValue

      public String getMessageValue(String key)
      Helper method for accessing paired transport message values. A paired transport message separates values with INTERNAL_MSG_PART_SEPARATOR and is set by the constructor AbstractMessage(String). Key-Value pairs are separated by the '=' sign.
      Parameters:
      key - key
      Returns:
      value
    • contains

      public boolean contains(String key)
      Checks if this key is contained in a paired transport message.
      Parameters:
      key - key
      Returns:
      true if so, otherwise false
    • getTransferString

      public abstract String getTransferString() throws IOException
      Get transfer string; this includes all set information including the additional object is set.
      Returns:
      transfer string
      Throws:
      IOException - IO exception
    • getJsonTransferString

      public abstract String getJsonTransferString() throws IOException
      Get JSON representation; this includes all set information including the additional object if set.
      Returns:
      transfer JSON string
      Throws:
      IOException - IO exception
    • deserializeObject

      protected void deserializeObject(String serializedObject) throws IOException
      Deserialize this object with FasterXML/Jackson. Internal method, don't call it.
      Parameters:
      serializedObject - serialized object
      Throws:
      IOException
    • serializeObject

      protected String serializeObject() throws IOException
      Serialize this object with FasterXML/Jackson. Internal method, don't call it.
      Returns:
      serialized object
      Throws:
      IOException