Class QueuedNotificationManager<L,​N>

  • Type Parameters:
    L - the listener type
    N - the notification type
    All Implemented Interfaces:
    NotificationManager<L,​N>

    public final class QueuedNotificationManager<L,​N>
    extends Object
    implements NotificationManager<L,​N>
    This class manages queuing and dispatching notifications for multiple listeners concurrently. Notifications are queued on a per-listener basis and dispatched serially to each listener via an Executor.

    This class optimizes its memory footprint by only allocating and maintaining a queue and executor task for a listener when there are pending notifications. On the first notification(s), a queue is created and a task is submitted to the executor to dispatch the queue to the associated listener. Any subsequent notifications that occur before all previous notifications have been dispatched are appended to the existing queue. When all notifications have been dispatched, the queue and task are discarded.

    Author:
    Thomas Pantelis
    • Method Detail

      • getMaxQueueCapacity

        public int getMaxQueueCapacity()
        Returns the maximum listener queue capacity.
      • getExecutor

        public @NonNull Executor getExecutor()
        Returns the Executor to used for notification tasks.
      • submitNotification

        public void submitNotification​(L listener,
                                       N notification)
        Description copied from interface: NotificationManager
        Submits a notification to be queued and dispatched to the given listener.

        Note: This method may block if the listener queue is currently full.

        Specified by:
        submitNotification in interface NotificationManager<L,​N>
        Parameters:
        listener - the listener to notify
        notification - the notification to dispatch
      • submitNotifications

        public void submitNotifications​(L listener,
                                        Iterable<N> notifications)
        Description copied from interface: NotificationManager
        Submits notifications to be queued and dispatched to the given listener.

        Note: This method may block if the listener queue is currently full.

        Specified by:
        submitNotifications in interface NotificationManager<L,​N>
        Parameters:
        listener - the listener to notify
        notifications - the notifications to dispatch