Class PushMessage
- All Implemented Interfaces:
IPushNotification
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 Summary
FieldsConstructor Summary
ConstructorsConstructorDescriptionPushMessage(String title, Map<String, Object> options, long ttlMillis) Constructor.Method Summary
Modifier and TypeMethodDescriptionasProperty(Atom atom) Materialises the heavyweight property form, for the spool.static PushMessagefromJSON(JSONObject m, long ttlMillis) Creates a message from the client'smobject:titleplus options.static PushMessagefromProperty(PNMessageProp p, long ttlMillis) Rebuilds a message from its property form, after a spool reload.Gets the action objects of theactionsoption, for a transport that needs them as a list.getBody()Gets the body option.Gets the notification options as an immutable map, aligned to theoptionsargument ofshowNotification— body, icon, badge, tag, data, actions, and the rest.getOptionString(String name) Gets a string-valued option.longGets this notification's time-to-live in milliseconds, or a negative value if it carries none and the server default (IPushSettings.getDefaultTTL()) applies.getTitle()Gets the notification title — thetitleargument of the browsershowNotification(title, options)call, and the primary line a device surfaces.toJSON()Gets the wire JSON: the title beside every option.toString()Gets a string representation.byte[]Gets the wire JSON as UTF-8 bytes, the VAPID plaintext.
Field Details
TITLE
Constructor Details
PushMessage
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
Description copied from interface:IPushNotificationGets the notification title — thetitleargument of the browsershowNotification(title, options)call, and the primary line a device surfaces.- Specified by:
getTitlein interfaceIPushNotification- Returns:
- The title; never
null.
getOptions
Description copied from interface:IPushNotificationGets the notification options as an immutable map, aligned to theoptionsargument ofshowNotification— 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:
getOptionsin interfaceIPushNotification- Returns:
- An unmodifiable options map; never
null, possibly empty.
getTimeToLiveMillis
public long getTimeToLiveMillis()Description copied from interface:IPushNotificationGets 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:
getTimeToLiveMillisin interfaceIPushNotification- Returns:
- The TTL in milliseconds, or a negative value to mean "use the server default".
getOptionString
getBody
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
Creates a message from the client'smobject:titleplus 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
Materialises the heavyweight property form, for the spool.- Parameters:
atom- The atom of the property,PNSpoolEntry.MESSAGE_ATOMfor a spool entry.- Returns:
- The property tree.
- Throws:
PropException- If a property cannot be added.
fromProperty
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
Gets the action objects of theactionsoption, for a transport that needs them as a list.- Returns:
- The actions as JSON objects, empty when there are none.
toString