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