b8fb57828f562a44bc4a1102d6b177b64beb1c88
[mdsal.git] / binding / mdsal-binding-api / src / main / java / org / opendaylight / mdsal / binding / api / InstanceNotificationService.java
1 /*
2  * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.api;
9
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;
21
22 /**
23  * A {@link BindingService} which allows clients to subscribe to (YANG 1.1) {@link InstanceNotification}s and
24  * {@link KeyedListNotification}s.
25  */
26 @Beta
27 public interface InstanceNotificationService extends BindingService {
28
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);
32
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());
37     }
38
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);
42
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());
47     }
48
49     /*
50      * Interface for listeners on instance (YANG 1.1) notifications.
51      */
52     @FunctionalInterface
53     interface Listener<P extends DataObject, N extends InstanceNotification<N, P>> extends EventListener {
54         /**
55          * Process an instance notification.
56          *
57          * @param path Instance path
58          * @param notification Notification body
59          */
60         void onNotification(@NonNull DataTreeIdentifier<P> path, @NonNull N notification);
61     }
62
63     /**
64      * Interface for listeners on instance (YANG 1.1) notifications defined in a {@code list} with a {@code key}.
65      */
66     @FunctionalInterface
67     interface KeyedListListener<P extends DataObject & Identifiable<K>, N extends KeyedListNotification<N, P, K>,
68             K extends Identifier<P>> extends EventListener {
69         /**
70          * Process an instance notification.
71          *
72          * @param path Instance path
73          * @param notification Notification body
74          */
75         // FIXME: DataTreeIdentifier does not have a Keyed flavor
76         void onNotification(@NonNull DataTreeIdentifier<P> path, @NonNull N notification);
77     }
78 }