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