2 * Copyright (c) 2014 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.util.concurrent;
10 import com.google.common.collect.ImmutableList;
11 import java.util.concurrent.Executor;
12 import org.eclipse.jdt.annotation.NonNull;
18 * This class is pessimistic about listener type and uses identity mapping for comparing them. This is defensive versus
19 * reused objects, maintaining semantics. This may not always be intended, for example if {@code L} is a {@code String}
20 * which is being dynamically determined. In that case we do not want to use identity, but equality, as otherwise
21 * the caller is forced to use {@link String#intern()} -- leading to interning in lookup, which is absolutely
22 * unnecessary. In such use cases, use {@link EqualityQueuedNotificationManager} instead.
24 * @author Thomas Pantelis
26 public final class QueuedNotificationManager<L, N> extends IdentityQueuedNotificationManager<L, N> {
28 public interface BatchedInvoker<L, N> {
30 * Called to invoke a listener with a notification.
32 * @param listener the listener to invoke
33 * @param notifications notifications to send
35 void invokeListener(@NonNull L listener, @NonNull ImmutableList<N> notifications);
38 QueuedNotificationManager(final @NonNull Executor executor, final @NonNull BatchedInvoker<L, N> listenerInvoker,
39 final int maxQueueCapacity, final @NonNull String name) {
40 super(name, executor, maxQueueCapacity, listenerInvoker);
44 * Create a new notification manager.
46 * @param executor the {@link Executor} to use for notification tasks
47 * @param listenerInvoker the {@link BatchedInvoker} to use for invoking listeners
48 * @param maxQueueCapacity the capacity of each listener queue
49 * @param name the name of this instance for logging info
51 public static <L, N> QueuedNotificationManager<L, N> create(final @NonNull Executor executor,
52 final@NonNull BatchedInvoker<L, N> listenerInvoker, final int maxQueueCapacity,
53 final @NonNull String name) {
54 return new QueuedNotificationManager<>(executor, listenerInvoker, maxQueueCapacity, name);