Class PushSessionAPI
- All Implemented Interfaces:
IPushNotificationCommonAPI, PushEvents.ISink
- Direct Known Subclasses:
AppSessionPushAPI, ClientSessionPushAPI
IPushNotificationCommonAPI, the threading rule of section 5, and the engine-sourced events of section 4.4 received from the engine's PushEvents.Threading. Nothing blocking runs on a session worker: a store query runs on a virtual thread and only its result is posted, through PushCallbackTask, to the worker the context names. An answer known at once - no_user, an argument refused - is posted the same way and never handed back inside the call. Listener registration is the one synchronous member, as contract 9.2 says.
Events reach this instance on the store's or the engine's thread - a receipt on the reporting client's connection thread (P4-11) - are matched to the session's user and application then, and are posted to the worker where the GenericListener delivers them, each listener in its own try/catch.
Disposal. dispose() unregisters from the hub, clears the listeners and abandons every pending callback with an INFO line (design 6.2). It is called by the gyro's own disposal, before the session's worker is disposed of.
- Author:
- Christopher Mindus
Field Summary
FieldsConstructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionbooleanAdds a listener for the Push Notification events of this session's user and application.protected <R> voidPosts a completed operation's callback to the session's worker.context()Gets the session.voiddispose()Disposes of this instance: unregisters from the engine's events, clears the listeners and abandons every pending callback, each logged INFO as not completed.protected PushEngineengine()Gets the running engine.protected <R> voidPosts a failure known at once to the session's worker - never handed back inside the call.intGets the number of callbacks posted to the worker and not yet run, for diagnostics and tests.booleanChecks whether this instance is disposed of.boolean--- PushEvents.ISink: the engine-sourced events, posted to the worker ------ IPushNotificationCommonAPI ---voidonNotificationAction(IPushReceipt receipt, String action) Called when a client reported a click on a notification or on one of its actions (P4-11).voidonNotificationReceived(IPushReceipt receipt) Called when a client reported that a notification was shown (P4-11).voidonSendFailed(String messageID, DeliveryTarget target, DeliveryOutcome outcome, String detail) Called when a target of a send ended in a failure (PushEvents.FAILURES).voidonSubscriptionCreated(SubscriptionRecord subscription) Called when a subscription was newly stored.voidonSubscriptionRemoved(SubscriptionRecord subscription, String reason) Called when a subscription was removed.voidqueryAvailableTransports(BiFunction<Set<PushTransport>, Exception, Void> callback) Queries the transports this server can deliver through for this application:PushTransport.VAPIDwhen the application has a VAPID key pair,PushTransport.FCMwhen it has Firebase credentials.voidquerySubscriptions(String topic, BiFunction<List<IPushSubscriptionInfo>, Exception, Void> callback) Queries the subscriptions of the session's user for this application, on every device the user has subscribed from.booleanRemoves a listener.protected <R> voidRuns blocking work - a store call, a send - on a virtual thread and posts its outcome to the session's worker.The store's Topic filter for a query: null is every Topic, the empty string the application-level subscription, a name that Topic.protected longGets the session's user ID.
Field Details
ctx
The session.
Constructor Details
PushSessionAPI
Constructor.- Parameters:
ctx- The session.- Throws:
NullPointerException- Ifctxis null.
Method Details
context
isDisposed
public boolean isDisposed()Checks whether this instance is disposed of.- Returns:
- true if disposed.
getPendingCount
public int getPendingCount()Gets the number of callbacks posted to the worker and not yet run, for diagnostics and tests.- Returns:
- The count.
dispose
public void dispose()Disposes of this instance: unregisters from the engine's events, clears the listeners and abandons every pending callback, each logged INFO as not completed.engine
Gets the running engine.- Throws:
PushNotificationException-internalwhen no engine is running.
user
Gets the session's user ID.- Parameters:
operation- The operation, for the message.- Throws:
PushNotificationException-no_userwhen the session has no authenticated user.
topics
complete
protected <R> void complete(String operation, BiFunction<R, Exception, Void> callback, R result, Exception failure) Posts a completed operation's callback to the session's worker.- Parameters:
operation- The operation.callback- The callback.result- The result, null on failure.failure- The failure, null on success.
fail
protected <R> void fail(String operation, BiFunction<R, Exception, Void> callback, String reason, String message) Posts a failure known at once to the session's worker - never handed back inside the call.- Parameters:
operation- The operation.callback- The callback.reason- The reason code.message- The message.
runOff
protected <R> void runOff(String operation, BiFunction<R, Exception, Void> callback, Callable<R> work) Runs blocking work - a store call, a send - on a virtual thread and posts its outcome to the session's worker. APushNotificationExceptionis reported as it is, anSQLExceptionasstore_failure, anything else asinternal.- Parameters:
operation- The operation.callback- The callback.work- The work.
newMessageBuilder
--- IPushNotificationCommonAPI ---- Specified by:
newMessageBuilderin interfaceIPushNotificationCommonAPI- Returns:
- A fresh builder, never
null.
querySubscriptions
public void querySubscriptions(String topic, BiFunction<List<IPushSubscriptionInfo>, Exception, Void> callback) Description copied from interface:IPushNotificationCommonAPIQueries the subscriptions of the session's user for this application, on every device the user has subscribed from. The result never carries key material, an endpoint or a token.- Specified by:
querySubscriptionsin interfaceIPushNotificationCommonAPI- Parameters:
topic- The topic, the empty string for the application-level subscriptions, ornullfor every topic.callback- Called on the session's worker thread with the subscriptions, possibly empty, or with the failure.
queryAvailableTransports
Description copied from interface:IPushNotificationCommonAPIQueries the transports this server can deliver through for this application:PushTransport.VAPIDwhen the application has a VAPID key pair,PushTransport.FCMwhen it has Firebase credentials.PushTransport.APNSis never in the set.An empty set means Push Notification cannot reach any device of this application on this server. The application should say so rather than offer a subscription that can never be delivered to.
- Specified by:
queryAvailableTransportsin interfaceIPushNotificationCommonAPI- Parameters:
callback- Called on the session's worker thread with the set, possibly empty, or with the failure.
addPushNotificationListener
Description copied from interface:IPushNotificationCommonAPIAdds a listener for the Push Notification events of this session's user and application. The listener is called on the session's worker thread. Adding the same listener again has no effect but to returnfalse.- Specified by:
addPushNotificationListenerin interfaceIPushNotificationCommonAPI- Parameters:
listener- The listener.- Returns:
trueif the listener was added,falseif it was already present.
removePushNotificationListener
Description copied from interface:IPushNotificationCommonAPIRemoves a listener.- Specified by:
removePushNotificationListenerin interfaceIPushNotificationCommonAPI- Parameters:
listener- The listener.- Returns:
trueif the listener was removed,falseif it was not present.
isFor
--- PushEvents.ISink: the engine-sourced events, posted to the worker ---- Specified by:
isForin interfacePushEvents.ISink- Parameters:
uid- The user ID.appId- The canonical application ID.- Returns:
- true when the sink's session belongs to that user and that application and has a listener to tell.
onSubscriptionCreated
Description copied from interface:PushEvents.ISinkCalled when a subscription was newly stored.- Specified by:
onSubscriptionCreatedin interfacePushEvents.ISink- Parameters:
subscription- The row.
onSubscriptionRemoved
Description copied from interface:PushEvents.ISinkCalled when a subscription was removed.- Specified by:
onSubscriptionRemovedin interfacePushEvents.ISink- Parameters:
subscription- The row as it was.reason- AnIPushNotificationListener.REMOVED_*constant.
onSendFailed
public void onSendFailed(String messageID, DeliveryTarget target, DeliveryOutcome outcome, String detail) Description copied from interface:PushEvents.ISinkCalled when a target of a send ended in a failure (PushEvents.FAILURES).- Specified by:
onSendFailedin interfacePushEvents.ISink- Parameters:
messageID- The message ID of the send, empty when the notification carried none.target- The target.outcome- The outcome.detail- The diagnostic, never null.
onNotificationReceived
Description copied from interface:PushEvents.ISinkCalled when a client reported that a notification was shown (P4-11).- Specified by:
onNotificationReceivedin interfacePushEvents.ISink- Parameters:
receipt- The receipt.
onNotificationAction
Description copied from interface:PushEvents.ISinkCalled when a client reported a click on a notification or on one of its actions (P4-11).- Specified by:
onNotificationActionin interfacePushEvents.ISink- Parameters:
receipt- The receipt.action- The action identity, empty for the notification itself.