X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=binding%2Fmdsal-binding-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fapi%2FNotificationService.java;h=8cce8560c8de6215f39c977a2ae74de680393d1f;hb=d8914a7d84797e9a2b0aee65003296020ab385ff;hp=42729f651254ffaa3d4cb7964b8e15b018994534;hpb=c241dcfa5322ac10810a1068ccd2eb57f6f2dbb2;p=mdsal.git diff --git a/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/NotificationService.java b/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/NotificationService.java index 42729f6512..8cce8560c8 100644 --- a/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/NotificationService.java +++ b/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/NotificationService.java @@ -7,7 +7,14 @@ */ package org.opendaylight.mdsal.binding.api; +import com.google.common.util.concurrent.MoreExecutors; +import java.util.EventListener; +import java.util.concurrent.Executor; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.concepts.Registration; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.Notification; import org.opendaylight.yangtools.yang.binding.NotificationListener; /** @@ -87,10 +94,58 @@ public interface NotificationService extends BindingService { * {@link NotificationListener}. The listener is registered for all notifications present in * the implemented interface. * - *

+ * @param NotificationListener type * @param listener the listener implementation that will receive notifications. * @return a {@link ListenerRegistration} instance that should be used to unregister the listener * by invoking the {@link ListenerRegistration#close()} method when no longer needed. */ - ListenerRegistration registerNotificationListener(T listener); + @NonNull ListenerRegistration registerNotificationListener(@NonNull T listener); + + /** + * Registers a {@link Listener} to receive callbacks for {@link Notification}s of a particular type. + * + * @param Notification type + * @param type Notification type class + * @param listener The listener implementation that will receive notifications + * @param executor Executor to use for invoking the listener's methods + * @return a {@link Registration} instance that should be used to unregister the listener by invoking the + * {@link Registration#close()} method when no longer needed + */ + & DataObject> @NonNull Registration registerListener(Class type, Listener listener, + Executor executor); + + /** + * Registers a {@link Listener} to receive callbacks for {@link Notification}s of a particular type. + * + * @implSpec + * This method is equivalent to {@code registerListener(type, listener, MoreExecutors.directExecutor())}, i.e. + * the listener will be invoked on some implementation-specific thread. + * + * @param Notification type + * @param type Notification type class + * @param listener The listener implementation that will receive notifications + * @return a {@link Registration} instance that should be used to unregister the listener by invoking the + * {@link Registration#close()} method when no longer needed + */ + default & DataObject> @NonNull Registration registerListener(final Class type, + final Listener listener) { + return registerListener(type, listener, MoreExecutors.directExecutor()); + } + + /** + * Interface for listeners on global (YANG 1.0) notifications. Such notifications are identified by their generated + * interface which extends {@link Notification}. Each listener instance can listen to only a single notification + * type. + * + * @param Notification type + */ + @FunctionalInterface + interface Listener & DataObject> extends EventListener { + /** + * Process a global notification. + * + * @param notification Notification body + */ + void onNotification(@NonNull N notification); + } }