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