Class Message

java.lang.Object
edu.uky.cs.nil.tt.io.Message
All Implemented Interfaces:
Timestamped
Direct Known Subclasses:
Choice, Connect, End, Error, Join, Report, Start, Stop, Update

public abstract class Message extends Object implements Timestamped
A message is information sent to or from a server in JSON format.
Author:
Stephen G. Ware
  • Nested Class Summary

    Nested classes/interfaces inherited from interface Timestamped

    Timestamped.Adapter
  • Field Summary

    Fields inherited from interface Timestamped

    FORMAT
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a message.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    configure(com.google.gson.GsonBuilder builder)
    Configures a GsonBuilder to encode and decode Message objects as JSON.
    Returns the Agent who sent this message, or null if this message was sent by the server.
    long
    Returns the time this object was created as the number of milliseconds from the epoch (1970-01-01T00:00:00Z) in Coordinated Universal Time (UTC).
    void
    setAgent(Agent agent)
    Sets the Agent who sent this message.
    void
    Checks that this message is correctly configured and throws an exception if not.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Message

      public Message()
      Constructs a message.
  • Method Details

    • configure

      public static void configure(com.google.gson.GsonBuilder builder)
      Configures a GsonBuilder to encode and decode Message objects as JSON.
      Parameters:
      builder - the GSON builder to configure
    • getAgent

      public Agent getAgent()
      Returns the Agent who sent this message, or null if this message was sent by the server.
      Returns:
      the agent who sent the message, or null
    • setAgent

      public void setAgent(Agent agent)
      Sets the Agent who sent this message. For messages sent to the server, this method should be called soon after the message has been parsed.
      Parameters:
      agent - the agent who sent this message
    • getTimestamp

      public long getTimestamp()
      Description copied from interface: Timestamped
      Returns the time this object was created as the number of milliseconds from the epoch (1970-01-01T00:00:00Z) in Coordinated Universal Time (UTC).
      Specified by:
      getTimestamp in interface Timestamped
      Returns:
      the object's timestamp in milliseconds from the epoch in UTC
    • verify

      public void verify()
      Checks that this message is correctly configured and throws an exception if not. This method should be called soon after the message has been parsed. It should check that all the necessary fields are set and that their values are legal values.