L
- the listener typeN
- the notification typepublic 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.Invoker<L,N>
Interface implemented by clients that does the work of invoking listeners with notifications.
|
Constructor and Description |
---|
QueuedNotificationManager(Executor executor,
QueuedNotificationManager.Invoker<L,N> listenerInvoker,
int maxQueueCapacity,
String name)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
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.
|
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 QueuedNotificationManager(Executor executor, QueuedNotificationManager.Invoker<L,N> listenerInvoker, int maxQueueCapacity, String name)
executor
- the Executor
to use for notification taskslistenerInvoker
- the QueuedNotificationManager.Invoker
to use for invoking listenersmaxQueueCapacity
- the capacity of each listener queuename
- the name of this instance for logging infopublic void submitNotification(L listener, N notification) throws RejectedExecutionException
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 dispatchRejectedExecutionException
- if the notification can't be queued for dispatchingpublic void submitNotifications(L listener, Iterable<N> notifications) throws RejectedExecutionException
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 dispatchRejectedExecutionException
- if a notification can't be queued for dispatchingpublic List<ListenerNotificationQueueStats> getListenerNotificationQueueStats()
ListenerNotificationQueueStats
instances for each current listener
notification task in progress.public int getMaxQueueCapacity()
Copyright © 2017 OpenDaylight. All rights reserved.