2 * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.mdsal.binding.api;
10 import com.google.common.annotations.Beta;
11 import com.google.common.util.concurrent.MoreExecutors;
12 import java.util.EventListener;
13 import java.util.concurrent.Executor;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.yangtools.concepts.Registration;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.Identifiable;
18 import org.opendaylight.yangtools.yang.binding.Identifier;
19 import org.opendaylight.yangtools.yang.binding.InstanceNotification;
20 import org.opendaylight.yangtools.yang.binding.KeyedListNotification;
23 * A {@link BindingService} which allows clients to subscribe to (YANG 1.1) {@link InstanceNotification}s and
24 * {@link KeyedListNotification}s.
27 public interface InstanceNotificationService extends BindingService {
29 <P extends DataObject, N extends InstanceNotification<N, P>, T extends Listener<P, N>>
30 @NonNull Registration registerListener(InstanceNotificationSpec<N, P> spec, DataTreeIdentifier<P> path,
31 T listener, Executor executor);
33 default <P extends DataObject, N extends InstanceNotification<N, P>, T extends Listener<P, N>>
34 @NonNull Registration registerListener(final InstanceNotificationSpec<N, P> spec,
35 final DataTreeIdentifier<P> path, final T listener) {
36 return registerListener(spec, path, listener, MoreExecutors.directExecutor());
39 <P extends DataObject & Identifiable<K>, N extends KeyedListNotification<N, P, K>, K extends Identifier<P>,
40 T extends KeyedListListener<P, N, K>> @NonNull Registration registerListener(
41 InstanceNotificationSpec<N, P> spec, DataTreeIdentifier<P> path, T listener, Executor executor);
43 default <P extends DataObject & Identifiable<K>, N extends KeyedListNotification<N, P, K>, K extends Identifier<P>,
44 T extends KeyedListListener<P, N, K>> @NonNull Registration registerListener(
45 final InstanceNotificationSpec<N, P> spec, final DataTreeIdentifier<P> path, final T listener) {
46 return registerListener(spec, path, listener, MoreExecutors.directExecutor());
50 * Interface for listeners on instance (YANG 1.1) notifications.
53 interface Listener<P extends DataObject, N extends InstanceNotification<N, P>> extends EventListener {
55 * Process an instance notification.
57 * @param path Instance path
58 * @param notification Notification body
60 void onNotification(@NonNull DataTreeIdentifier<P> path, @NonNull N notification);
64 * Interface for listeners on instance (YANG 1.1) notifications defined in a {@code list} with a {@code key}.
67 interface KeyedListListener<P extends DataObject & Identifiable<K>, N extends KeyedListNotification<N, P, K>,
68 K extends Identifier<P>> extends EventListener {
70 * Process an instance notification.
72 * @param path Instance path
73 * @param notification Notification body
75 // FIXME: DataTreeIdentifier does not have a Keyed flavor
76 void onNotification(@NonNull DataTreeIdentifier<P> path, @NonNull N notification);