public final class QueuedNotificationManager<L,N> extends IdentityQueuedNotificationManager<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.
This class is pessimistic about listener type and uses identity mapping for comparing them. This is defensive versus
reused objects, maintaining semantics. This may not always be intended, for example if L
is a String
which is being dynamically determined. In that case we do not want to use identity, but equality, as otherwise
the caller is forced to use String.intern()
-- leading to interning in lookup, which is absolutely
unnecessary. In such use cases, use EqualityQueuedNotificationManager
instead.
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.
|
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.
|
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,
@Nullable Iterable<N> notifications)
Submits notifications to be queued and dispatched to the given listener.
|
addToStringAttributes, getIdentifier, toString
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 final Executor getExecutor()
Executor
to used for notification tasks.public final int getMaxQueueCapacity()
public final QueuedNotificationManagerMXBean getMXBean()
QueuedNotificationManagerMXBean
tied to this instance.public final List<ListenerNotificationQueueStats> getListenerNotificationQueueStats()
ListenerNotificationQueueStats
instances for each current listener
notification task in progress.public final 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 final void submitNotifications(L listener, @Nullable 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 dispatchCopyright © 2020 OpenDaylight. All rights reserved.