Clean up (DOM)DataTreeIdentifier methods
[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.concurrent.Executor;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.concepts.Registration;
15 import org.opendaylight.yangtools.yang.binding.DataObject;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17 import org.opendaylight.yangtools.yang.binding.InstanceNotification;
18 import org.opendaylight.yangtools.yang.binding.Key;
19 import org.opendaylight.yangtools.yang.binding.KeyAware;
20 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.binding.KeyedListNotification;
22
23 /**
24  * A {@link BindingService} which allows clients to subscribe to (YANG 1.1) {@link InstanceNotification}s and
25  * {@link KeyedListNotification}s.
26  */
27 @Beta
28 public interface InstanceNotificationService extends BindingService {
29
30     <P extends DataObject, N extends InstanceNotification<N, P>> @NonNull Registration registerListener(
31         InstanceNotificationSpec<N, P> spec, InstanceIdentifier<P> path, Listener<P, N> listener, Executor executor);
32
33     default <P extends DataObject, N extends InstanceNotification<N, P>> @NonNull Registration registerListener(
34             final InstanceNotificationSpec<N, P> spec, final InstanceIdentifier<P> path,
35             final Listener<P, N> listener) {
36         return registerListener(spec, path, listener, MoreExecutors.directExecutor());
37     }
38
39     <P extends DataObject & KeyAware<K>, N extends KeyedListNotification<N, P, K>, K extends Key<P>>
40         @NonNull Registration registerListener(InstanceNotificationSpec<N, P> spec, KeyedInstanceIdentifier<P, K> path,
41             KeyedListListener<P, N, K> listener, Executor executor);
42
43     default <P extends DataObject & KeyAware<K>, N extends KeyedListNotification<N, P, K>, K extends Key<P>>
44             @NonNull Registration registerListener(final InstanceNotificationSpec<N, P> spec,
45                 final KeyedInstanceIdentifier<P, K> path, final KeyedListListener<P, N, K> 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>> {
54         /**
55          * Process an instance notification.
56          *
57          * @param path Instance path
58          * @param notification Notification body
59          */
60         void onNotification(@NonNull InstanceIdentifier<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 & KeyAware<K>, N extends KeyedListNotification<N, P, K>,
68             K extends Key<P>> {
69         /**
70          * Process an instance notification.
71          *
72          * @param path Instance path
73          * @param notification Notification body
74          */
75         void onNotification(@NonNull KeyedInstanceIdentifier<P, K> path, @NonNull N notification);
76     }
77 }