Add registerNotificationListeners()
[mdsal.git] / dom / mdsal-dom-api / src / main / java / org / opendaylight / mdsal / dom / api / DOMNotificationService.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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.dom.api;
9
10 import java.util.Arrays;
11 import java.util.Collection;
12 import java.util.Map;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.concepts.ListenerRegistration;
15 import org.opendaylight.yangtools.concepts.Registration;
16 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
17
18 /**
19  * A {@link DOMService} which allows its users to subscribe to receive top-level (YANG 1.0) {@link DOMNotification}s.
20  */
21 public interface DOMNotificationService extends DOMService {
22     /**
23      * Register a {@link DOMNotificationListener} to receive a set of notifications. As with other
24      * {@link ListenerRegistration}-based interfaces, registering an instance multiple times results in
25      * notifications being delivered for each registration.
26      *
27      * @param listener Notification instance to register
28      * @param types Notification types which should be delivered to the listener. Duplicate entries
29      *        are processed only once, null entries are ignored.
30      * @return Registration handle. Invoking {@link ListenerRegistration#close()} will stop the
31      *         delivery of notifications to the listener
32      * @throws IllegalArgumentException if types is empty or contains an invalid element, such as
33      *         null or a schema node identifier which does not represent a valid {@link DOMNotification} type.
34      * @throws NullPointerException if either of the arguments is null
35      */
36     <T extends DOMNotificationListener> @NonNull ListenerRegistration<T>
37             registerNotificationListener(@NonNull T listener, @NonNull Collection<Absolute> types);
38
39     /**
40      * Register a {@link DOMNotificationListener} to receive a set of notifications. As with other
41      * {@link ListenerRegistration}-based interfaces, registering an instance multiple times results in
42      * notifications being delivered for each registration.
43      *
44      * @param listener Notification instance to register
45      * @param types Notification types which should be delivered to the listener. Duplicate entries
46      *        are processed only once, null entries are ignored.
47      * @return Registration handle. Invoking {@link ListenerRegistration#close()} will stop the
48      *         delivery of notifications to the listener
49      * @throws IllegalArgumentException if types is empty or contains an invalid element, such as
50      *         null or a schema node identifier which does not represent a valid {@link DOMNotification} type.
51      * @throws NullPointerException if listener is null
52      */
53     default <T extends DOMNotificationListener> @NonNull ListenerRegistration<T>
54             registerNotificationListener(@NonNull final T listener, final Absolute... types) {
55         return registerNotificationListener(listener, Arrays.asList(types));
56     }
57
58     /**
59      * Register a number of {@link DOMNotificationListener}s to receive some notification notifications. As with other
60      * {@link Registration}-based interfaces, registering an instance multiple times results in
61      * notifications being delivered for each registration.
62      *
63      * @param typeToListener Specification of which types to listen to with which listeners
64      * @throws NullPointerException if {@code typeToListener} is {@code null}
65      */
66     @NonNull Registration registerNotificationListeners(@NonNull Map<Absolute, DOMNotificationListener> typeToListener);
67 }