Merge "Bug 1245: Dropped Binding prefix from Binding Data APIs."
[controller.git] / opendaylight / md-sal / sal-common-api / src / main / java / org / opendaylight / controller / md / sal / common / api / data / AsyncDataBroker.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.controller.md.sal.common.api.data;
9
10 import org.opendaylight.yangtools.concepts.ListenerRegistration;
11 import org.opendaylight.yangtools.concepts.Path;
12
13 /**
14  *
15  * Base interface that provides access to a conceptual data tree store and also provides the ability to
16  * subscribe for changes to data under a given branch of the tree.
17  *
18  * <p>
19  * All operations on the data tree are performed via one of the transactions:
20  * <ul>
21  * <li>Read-Only - allocated using {@link #newReadOnlyTransaction()}
22  * <li>Write-Only - allocated using {@link #newWriteOnlyTransaction()}
23  * <li>Read-Write - allocated using {@link #newReadWriteTransaction()}
24  * </ul>
25  *
26  * <p>
27  * These transactions provide a stable isolated view of data tree, which is
28  * guaranteed to be not affected by other concurrent transactions, until
29  * transaction is committed.
30  *
31  * <p>
32  * For a detailed explanation of how transaction are isolated and how transaction-local
33  * changes are committed to global data tree, see
34  * {@link AsyncReadTransaction}, {@link AsyncWriteTransaction},
35  * {@link AsyncReadWriteTransaction} and {@link AsyncWriteTransaction#commit()}.
36  *
37  *
38  * <p>
39  * It is strongly recommended to use the type of transaction, which
40  * provides only the minimal capabilities you need. This allows for
41  * optimizations at the data broker / data store level. For example,
42  * implementations may optimize the transaction for reading if they know ahead
43  * of time that you only need to read data - such as not keeping additional meta-data,
44  * which may be required for write transactions.
45  *
46  * <p>
47  * <b>Implementation Note:</b> This interface is not intended to be implemented
48  * by users of MD-SAL, but only to be consumed by them.
49  *
50  * @param <P>
51  *            Type of path (subtree identifier), which represents location in
52  *            tree
53  * @param <D>
54  *            Type of data (payload), which represents data payload
55  */
56 public interface AsyncDataBroker<P extends Path<P>, D, L extends AsyncDataChangeListener<P, D>> extends //
57         AsyncDataTransactionFactory<P, D> {
58
59     /**
60      *
61      * Scope of Data Change
62      *
63      * <p>
64      * Represents scope of data change (addition, replacement, deletion).
65      *
66      * The terminology for scope types is reused from LDAP.
67      *
68      * <h2>Examples</h2>
69      *
70      * Following is an example model with comments describing what notifications
71      * you would receive based on the scope you specify, when you are
72      * registering for changes on container a.
73      *
74      * <pre>
75      * container a              // scope BASE, ONE, SUBTREE
76      *    leaf "foo"            // scope ONE, SUBTREE
77      *    container             // scope ONE, SUBTREE
78      *       leaf  "bar"        // scope SUBTREE
79      *    list list             // scope ONE, SUBTREE
80      *      list [a]            // scope SUBTREE
81      *        id "a"            // scope SUBTREE
82      *      list [b]            // scope SUBTREE
83      *        id "b"            // scope SUBTREE
84      * </pre>
85      *
86      * Following is an example model with comments describing what notifications
87      * you would receive based on the scope you specify, when you are
88      * registering for changes on list list (without specifying concrete item in
89      * the list).
90      *
91      * <pre>
92      *  list list               // scope BASE, ONE, SUBTREE
93      *      list [a]            // scope ONE, SUBTREE
94      *        id "a"            // scope SUBTREE
95      *      list [b]            // scope ONE, SUBTREE
96      *        id "b"            // scope SUBTREE
97      * </pre>
98      *
99      *
100      * @see http://www.idevelopment.info/data/LDAP/LDAP_Resources/
101      *      SEARCH_Setting_the_SCOPE_Parameter.shtml
102      */
103     public enum DataChangeScope {
104
105         /**
106          * Represents only a direct change of the node, such as replacement of a
107          * node, addition or deletion.
108          *
109          */
110         BASE,
111         /**
112          * Represent a change (addition,replacement,deletion) of the node or one
113          * of its direct children.
114          *
115          * This scope is superset of {@link #BASE}.
116          *
117          */
118         ONE,
119         /**
120          * Represents a change of the node or any of or any of its child nodes,
121          * direct and nested.
122          *
123          * This scope is superset of {@link #ONE} and {@link #BASE}.
124          *
125          */
126         SUBTREE
127     }
128
129     /**
130      * {@inheritDoc}
131      */
132     @Override
133     public AsyncReadOnlyTransaction<P, D> newReadOnlyTransaction();
134
135     /**
136      * {@inheritDoc}
137      */
138     @Override
139     public AsyncReadWriteTransaction<P, D> newReadWriteTransaction();
140
141     /**
142      * {@inheritDoc}
143      */
144     @Override
145     public AsyncWriteTransaction<P, D> newWriteOnlyTransaction();
146
147     /**
148      * Registers a {@link AsyncDataChangeListener} to receive
149      * notifications when data changes under a given path in the conceptual data
150      * tree.
151      * <p>
152      * You are able to register for notifications  for any node or subtree
153      * which can be reached via the supplied path.
154      * <p>
155      * If path type <code>P</code> allows it, you may specify paths up to the leaf nodes
156      * then it is possible to listen on leaf nodes.
157      * <p>
158      * You are able to register for data change notifications for a subtree even
159      * if it does not exist. You will receive notification once that node is
160      * created.
161      * <p>
162      * If there is any preexisting data in data tree on path for which you are
163      * registering, you will receive initial data change event, which will
164      * contain all preexisting data, marked as created.
165      *
166      * <p>
167      * You are also able to specify the scope of the changes you want to be
168      * notified.
169      * <p>
170      * Supported scopes are:
171      * <ul>
172      * <li>{@link DataChangeScope#BASE} - notification events will only be
173      * triggered when a node referenced by path is created, removed or replaced.
174      * <li>{@link DataChangeScope#ONE} - notifications events will only be
175      * triggered when a node referenced by path is created, removed or replaced,
176      * or any or any of its immediate children are created, updated or removed.
177      * <li>{@link DataChangeScope#SUBTREE} - notification events will be
178      * triggered when a node referenced by the path is created, removed
179      * or replaced or any of the children in its subtree are created, removed
180      * or replaced.
181      * </ul>
182      * See {@link DataChangeScope} for examples.
183      * <p>
184      * This method returns a {@link ListenerRegistration} object. To
185      * "unregister" your listener for changes call the "close" method on this
186      * returned object.
187      * <p>
188      * You MUST call close when you no longer need to receive notifications
189      * (such as during shutdown or for example if your bundle is shutting down).
190      *
191      * @param store
192      *            Logical Data Store - Logical Datastore you want to listen for
193      *            changes in. For example
194      *            {@link LogicalDatastoreType#OPERATIONAL} or
195      *            {@link LogicalDatastoreType#CONFIGURATION}
196      * @param path
197      *            Path (subtree identifier) on which client listener will be
198      *            invoked.
199      * @param listener
200      *            Instance of listener which should be invoked on
201      * @param triggeringScope
202      *            Scope of change which triggers callback.
203      * @return Listener registration object, which may be used to unregister
204      *         your listener using {@link ListenerRegistration#close()} to stop
205      *         delivery of change events.
206      */
207     ListenerRegistration<L> registerDataChangeListener(LogicalDatastoreType store, P path, L listener,
208             DataChangeScope triggeringScope);
209 }