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