Class PushMessage

java.lang.Object
com.iizix.server.push.engine.PushMessage
All Implemented Interfaces:
IPushNotification

public final class PushMessage extends Object implements IPushNotification
The lightweight, immutable, in-flight notification: a title and an options map aligned to the browser showNotification(title,options) call, plus a time-to-live.

This is the canonical form the engine holds and the device transports ship. The wire JSON of the VAPID leg is toJSON(): title beside every option, which is exactly what the service worker's push event consumes (WIRE-CONTRACT §2.8) and what the client sends as m in /iizi-push/push (§1.5). The heavyweight property form is materialised only at the persistence boundary, by asProperty(Atom) and fromProperty(PNMessageProp,long).

Option values are the JSON types: String, Number, Boolean, JSONObject, JSONArray. actions and data pass through intact; they are a first-class use case, never decoration.

Author:
Christopher Mindus
  • Field Details

  • Constructor Details

    • PushMessage

      public PushMessage(String title, Map<String,Object> options, long ttlMillis)
      Constructor.
      Parameters:
      title - The title, non-empty.
      options - The options; copied.
      ttlMillis - The TTL in milliseconds, negative for the server default.
      Throws:
      IllegalArgumentException - If the title is null or empty.
  • Method Details

    • getTitle

      public String getTitle()
      Description copied from interface: IPushNotification
      Gets the notification title — the title argument of the browser showNotification(title, options) call, and the primary line a device surfaces.
      Specified by:
      getTitle in interface IPushNotification
      Returns:
      The title; never null.
    • getOptions

      public Map<String,Object> getOptions()
      Description copied from interface: IPushNotification
      Gets the notification options as an immutable map, aligned to the options argument of showNotification — body, icon, badge, tag, data, actions, and the rest. The service worker consumes this shape directly, so the browser leg needs no translation.
      Specified by:
      getOptions in interface IPushNotification
      Returns:
      An unmodifiable options map; never null, possibly empty.
    • getTimeToLiveMillis

      public long getTimeToLiveMillis()
      Description copied from interface: IPushNotification
      Gets this notification's time-to-live in milliseconds, or a negative value if it carries none and the server default (IPushSettings.getDefaultTTL()) applies.

      Milliseconds is the unit throughout; conversion to the seconds required by the transport header happens only at the transport boundary. A spooled notification whose TTL has elapsed is dropped rather than replayed.

      Specified by:
      getTimeToLiveMillis in interface IPushNotification
      Returns:
      The TTL in milliseconds, or a negative value to mean "use the server default".
    • getOptionString

      public String getOptionString(String name)
      Gets a string-valued option.
      Parameters:
      name - The option name.
      Returns:
      The value as a string, or null when absent.
    • getBody

      public String getBody()
      Gets the body option.
      Returns:
      The body text, or null.
    • toJSON

      public JSONObject toJSON()
      Gets the wire JSON: the title beside every option.
      Returns:
      A new JSON object.
    • toWireBytes

      public byte[] toWireBytes()
      Gets the wire JSON as UTF-8 bytes, the VAPID plaintext.
      Returns:
      The bytes.
    • fromJSON

      public static PushMessage fromJSON(JSONObject m, long ttlMillis)
      Creates a message from the client's m object: title plus options.
      Parameters:
      m - The JSON object.
      ttlMillis - The TTL, negative for the server default.
      Returns:
      The message.
      Throws:
      IllegalArgumentException - If there is no non-empty title.
    • asProperty

      public PNMessageProp asProperty(Atom atom) throws PropException
      Materialises the heavyweight property form, for the spool.
      Parameters:
      atom - The atom of the property, PNSpoolEntry.MESSAGE_ATOM for a spool entry.
      Returns:
      The property tree.
      Throws:
      PropException - If a property cannot be added.
    • fromProperty

      public static PushMessage fromProperty(PNMessageProp p, long ttlMillis)
      Rebuilds a message from its property form, after a spool reload.
      Parameters:
      p - The property tree.
      ttlMillis - The TTL, negative for the server default.
      Returns:
      The message.
      Throws:
      IllegalArgumentException - If the tree carries no title.
    • getActions

      public List<JSONObject> getActions()
      Gets the action objects of the actions option, for a transport that needs them as a list.
      Returns:
      The actions as JSON objects, empty when there are none.
    • toString

      public String toString()
      Gets a string representation.
      Overrides:
      toString in class Object
      Returns:
      The wire JSON.