Class QueuedNotificationManager<L,N>
- java.lang.Object
-
- org.opendaylight.yangtools.concepts.AbstractIdentifiable<T,T>
-
- org.opendaylight.yangtools.concepts.AbstractSimpleIdentifiable<String>
-
- org.opendaylight.yangtools.util.concurrent.IdentityQueuedNotificationManager<L,N>
-
- org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager<L,N>
-
- All Implemented Interfaces:
Identifiable<String>
,NotificationManager<L,N>
public final class QueuedNotificationManager<L,N> extends IdentityQueuedNotificationManager<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 anExecutor
.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 aString
which is being dynamically determined. In that case we do not want to use identity, but equality, as otherwise the caller is forced to useString.intern()
-- leading to interning in lookup, which is absolutely unnecessary. In such use cases, useEqualityQueuedNotificationManager
instead.- Author:
- Thomas Pantelis
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
QueuedNotificationManager.BatchedInvoker<L,N>
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 theExecutor
to used for notification tasks.int
getMaxQueueCapacity()
Returns the maximum listener queue capacity.QueuedNotificationManagerMXBean
getMXBean()
Return anQueuedNotificationManagerMXBean
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.-
Methods inherited from class org.opendaylight.yangtools.concepts.AbstractIdentifiable
addToStringAttributes, getIdentifier, toString
-
-
-
-
Method Detail
-
create
public 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.- Parameters:
executor
- theExecutor
to use for notification taskslistenerInvoker
- theQueuedNotificationManager.BatchedInvoker
to use for invoking listenersmaxQueueCapacity
- the capacity of each listener queuename
- the name of this instance for logging info
-
getExecutor
public final Executor getExecutor()
Returns theExecutor
to used for notification tasks.
-
getMaxQueueCapacity
public final int getMaxQueueCapacity()
Returns the maximum listener queue capacity.
-
getMXBean
public final QueuedNotificationManagerMXBean getMXBean()
Return anQueuedNotificationManagerMXBean
tied to this instance.- Returns:
- An QueuedNotificationManagerMXBean object.
-
submitNotification
public final 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 interfaceNotificationManager<T,L>
- Parameters:
listener
- the listener to notifynotification
- the notification to dispatch
-
submitNotifications
public final void submitNotifications(L listener, @Nullable 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 interfaceNotificationManager<T,L>
- Parameters:
listener
- the listener to notifynotifications
- the notifications to dispatch
-
-