c7a13836b8f0ebe015606f57a1e2183a16d9f7ac
[mdsal.git] / dom / mdsal-dom-api / src / main / java / org / opendaylight / mdsal / dom / api / DOMDataTreeChangeService.java
1 /*
2  * Copyright (c) 2015 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 org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.yangtools.concepts.ListenerRegistration;
12
13 /**
14  * A {@link DOMServiceExtension} which allows users to register for changes to a
15  * subtree.
16  */
17 public interface DOMDataTreeChangeService extends DOMDataBrokerExtension {
18     /**
19      * Registers a {@link DOMDataTreeChangeListener} to receive notifications when data changes
20      * under a given path in the conceptual data tree.
21      *
22      * <p>
23      * You are able to register for notifications for any node or subtree which can be represented
24      * using {@link DOMDataTreeIdentifier}.
25      *
26      * <p>
27      * You are able to register for data change notifications for a subtree or leaf even if it does
28      * not exist. You will receive notification once that node is created.
29      *
30      * <p>
31      * If there is any pre-existing data in the data tree for the path for which you are
32      * registering, you will receive an initial data change event, which will contain all
33      * pre-existing data, marked as created.
34      *
35      * <p>
36      * This method returns a {@link ListenerRegistration} object. To "unregister" your listener for
37      * changes call the {@link ListenerRegistration#close()} method on the returned object.
38      *
39      * <p>
40      * You MUST explicitly unregister your listener when you no longer want to receive
41      * notifications. This is especially true in OSGi environments, where failure to do so during
42      * bundle shutdown can lead to stale listeners being still registered.
43      *
44      * @param treeId Data tree identifier of the subtree which should be watched for changes.
45      * @param listener Listener instance which is being registered
46      * @param <L> Listener type
47      * @return Listener registration object, which may be used to unregister your listener using
48      *         {@link ListenerRegistration#close()} to stop delivery of change events.
49      * @throws NullPointerException if any of the arguments is null
50      */
51     <L extends DOMDataTreeChangeListener> @NonNull ListenerRegistration<L> registerDataTreeChangeListener(
52             @NonNull DOMDataTreeIdentifier treeId, @NonNull L listener);
53 }