Package alpine.notification
Class NotificationService
java.lang.Object
alpine.notification.NotificationService
- All Implemented Interfaces:
INotificationService
The NotificationService provides a way to dispatch (publish) notifications to zero or more subscribers.
Architecturally, the NotificationService is similar to
IEventService but
the objectives and logic of notification processing vary enough to warrant implementations specific to
notifications.- Since:
- 1.3.0
- Author:
- Steve Springett
-
Method Summary
Modifier and TypeMethodDescriptionstatic NotificationServicebooleanhasSubscriptions(Notification notification) Determines if the specified notification is able to be processed by the NotificationService.voidpublish(Notification notification) Publishes Notification.voidshutdown()Shuts down the executioner.booleanShuts down thisINotificationService, and waits for already queued notifications to be processed until a giventimeoutelapses.voidsubscribe(Subscription subscription) Subscribes to a Notification.voidsubscribe(Class<? extends Notification> notificationClass, Subscription subscription) Subscribes to a Notification.voidunsubscribe(Subscription subscription) Unsubscribes a subscriber.
-
Method Details
-
getInstance
-
publish
Publishes Notification. Published notifications will get dispatched to all subscribers in the order in which they subscribed. Subscribers are informed asynchronously one after the next.- Specified by:
publishin interfaceINotificationService- Parameters:
notification- A Notification to publish- Since:
- 1.3.0
-
subscribe
Subscribes to a Notification. Subscribes are automatically notified of all notifications for which they are subscribed.- Specified by:
subscribein interfaceINotificationService- Parameters:
notificationClass- The notification class to subscribe tosubscription- The Subscription (containing the subscriber) that gets informed- Since:
- 1.3.0
-
subscribe
Subscribes to a Notification. Subscribes are automatically notified of all notifications for which they are subscribed.- Specified by:
subscribein interfaceINotificationService- Parameters:
subscription- The Subscription (containing the subscriber) that gets informed- Since:
- 1.3.0
-
unsubscribe
Unsubscribes a subscriber. All notifications the subscriber has subscribed to will be unsubscribed. Once unsubscribed, the subscriber will no longer be informed of published notifications.- Specified by:
unsubscribein interfaceINotificationService- Parameters:
subscription- The Subscription to unsubscribe.- Since:
- 1.3.0
-
hasSubscriptions
Determines if the specified notification is able to be processed by the NotificationService. If a subscriber exists for the notification, this method will return true, otherwise false.- Specified by:
hasSubscriptionsin interfaceINotificationService- Parameters:
notification- the notification to query if subscribers exist- Returns:
- true if the notification has subscribers, false if not
- Since:
- 1.3.0
-
shutdown
public void shutdown()Shuts down the executioner. Once shut down, future work will not be performed. This should only be called prior to the application being shut down.- Specified by:
shutdownin interfaceINotificationService- Since:
- 1.3.0
-
shutdown
Shuts down thisINotificationService, and waits for already queued notifications to be processed until a giventimeoutelapses.Notifications enqueued during shutdown will not be processed.
- Specified by:
shutdownin interfaceINotificationService- Parameters:
timeout- TheDurationto wait for notification processing to complete- Returns:
truewhen all queued notifications were processed prior totimeoutelapsing, otherwisefalse
-