L
- the listener typeN
- the notification typepublic final class QueuedNotificationManager<L,N> extends Object implements NotificationManager<L,N>
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.
Modifier and Type | Class and Description |
---|---|
static interface |
QueuedNotificationManager.BatchedInvoker<L,N> |
Modifier and Type | Method and Description |
---|---|
static <L,N> QueuedNotificationManager<L,N> |
create(@NonNull Executor executor,
@NonNull QueuedNotificationManager.BatchedInvoker<L,N> listenerInvoker,
int maxQueueCapacity,
@NonNull String name)
Create a new notification manager.
|
@NonNull Executor |
getExecutor()
Returns the
Executor to used for notification tasks. |
List<ListenerNotificationQueueStats> |
getListenerNotificationQueueStats()
Returns
ListenerNotificationQueueStats instances for each current listener
notification task in progress. |
int |
getMaxQueueCapacity()
Returns the maximum listener queue capacity.
|
@NonNull QueuedNotificationManagerMXBean |
getMXBean()
Return an
QueuedNotificationManagerMXBean tied to this instance. |
void |
submitNotification(L listener,
N notification)
Submits a notification to be queued and dispatched to the given listener.
|
void |
submitNotifications(L listener,
Iterable<N> notifications)
Submits notifications to be queued and dispatched to the given listener.
|
public static <L,N> QueuedNotificationManager<L,N> create(@NonNull Executor executor, @NonNull QueuedNotificationManager.BatchedInvoker<L,N> listenerInvoker, int maxQueueCapacity, @NonNull String name)
executor
- the Executor
to use for notification taskslistenerInvoker
- the QueuedNotificationManager.BatchedInvoker
to use for invoking listenersmaxQueueCapacity
- the capacity of each listener queuename
- the name of this instance for logging infopublic int getMaxQueueCapacity()
public @NonNull QueuedNotificationManagerMXBean getMXBean()
QueuedNotificationManagerMXBean
tied to this instance.public @NonNull Executor getExecutor()
Executor
to used for notification tasks.public void submitNotification(L listener, N notification)
NotificationManager
Note: This method may block if the listener queue is currently full.
submitNotification
in interface NotificationManager<L,N>
listener
- the listener to notifynotification
- the notification to dispatchpublic void submitNotifications(L listener, Iterable<N> notifications)
NotificationManager
Note: This method may block if the listener queue is currently full.
submitNotifications
in interface NotificationManager<L,N>
listener
- the listener to notifynotifications
- the notifications to dispatchpublic List<ListenerNotificationQueueStats> getListenerNotificationQueueStats()
ListenerNotificationQueueStats
instances for each current listener
notification task in progress.Copyright © 2019 OpenDaylight. All rights reserved.