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