Deprecate Clustered(DOM)DataTreeChangeListener
[mdsal.git] / dom / mdsal-dom-api / src / main / java / org / opendaylight / mdsal / dom / api / DOMDataBroker.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.dom.api;
9
10 import org.eclipse.jdt.annotation.NonNullByDefault;
11 import org.opendaylight.yangtools.concepts.Registration;
12 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
13
14 /**
15  * Data Broker which provides data transaction and data change listener functionality using {@link NormalizedNode}.
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  * </ul>
23  *
24  * <p>
25  * These transactions provide a stable isolated view of data tree, which is guaranteed to be not
26  * affected by other concurrent transactions, until transaction is committed.
27  *
28  * <p>
29  * For a detailed explanation of how transaction are isolated and how transaction-local changes are
30  * committed to global data tree, see {@link DOMDataTreeReadTransaction}, {@link DOMDataTreeWriteTransaction}
31  * and {@link DOMDataTreeWriteTransaction#commit()}.
32  *
33  *
34  * <p>
35  * It is strongly recommended to use the type of transaction, which provides only the minimal
36  * capabilities you need. This allows for optimizations at the data broker / data store level. For
37  * example, implementations may optimize the transaction for reading if they know ahead of time that
38  * you only need to read data - such as not keeping additional meta-data, which may be required for
39  * write transactions.
40  *
41  * <p>
42  * <b>Implementation Note:</b> This interface is not intended to be implemented by users of MD-SAL,
43  * but only to be consumed by them.
44  */
45 @NonNullByDefault
46 public interface DOMDataBroker extends DOMService<DOMDataBroker, DOMDataBroker.Extension>, DOMTransactionFactory {
47     /**
48      * Type capture of a {@link DOMService.Extension} applicable to {@link DOMDataBroker} implementations.
49      */
50     interface Extension extends DOMService.Extension<DOMDataBroker, Extension> {
51         // Marker interface
52     }
53
54     /**
55      * Create a new transaction chain. The chain will be initialized to read from its backing datastore, with
56      * no outstanding transaction.
57      *
58      * @return A new transaction chain.
59      */
60     DOMTransactionChain createTransactionChain();
61
62     /**
63      * Create a new transaction chain. The chain will be initialized to read from its backing datastore, with
64      * no outstanding transaction.
65      *
66      * <p>
67      * Unlike {@link #createTransactionChain()}, the transaction chain returned by this method is allowed to merge
68      * individual transactions into larger chunks. When transactions are merged, the results must be indistinguishable
69      * from the result of all operations having been performed on a single transaction.
70      *
71      * <p>
72      * When transactions are merged, {@link DOMTransactionChain#newReadOnlyTransaction()} may actually be backed by
73      * a read-write transaction, hence an additional restriction on API use is that multiple read-only transactions
74      * may not be open at the same time.
75      *
76      * @return A new transaction chain.
77      */
78     DOMTransactionChain createMergingTransactionChain();
79
80     /**
81      * Optional support for allowing a {@link DOMDataTreeCommitCohort} to participate in the process of committing
82      * {@link DOMDataTreeWriteTransaction}s.
83      */
84     interface CommitCohortExtension extends Extension {
85         /**
86          * Register commit cohort which will participate in three-phase commit protocols of
87          * {@link DOMDataTreeWriteTransaction} in data broker associated with this instance of extension.
88          *
89          * @param path Subtree path on which commit cohort operates.
90          * @param cohort A {@link DOMDataTreeCommitCohort}
91          * @return A {@link Registration}
92          * @throws NullPointerException if any argument is {@code null}
93          */
94         Registration registerCommitCohort(DOMDataTreeIdentifier path, DOMDataTreeCommitCohort cohort);
95     }
96
97     /**
98      * An {@link Extension} which allows users to register for changes to a subtree.
99      */
100     interface DataTreeChangeExtension extends Extension {
101         /**
102          * Registers a {@link DOMDataTreeChangeListener} to receive notifications when data changes under a given path
103          * in the conceptual data tree.
104          *
105          * <p>
106          * You are able to register for notifications for any node or subtree which can be represented using
107          * {@link DOMDataTreeIdentifier}.
108          *
109          * <p>
110          * You are able to register for data change notifications for a subtree or leaf even if it does not exist. You
111          * will receive notification once that node is created.
112          *
113          * <p>
114          * If there is any pre-existing data in the data tree for the path for which you are registering, you will
115          * receive an initial data change event, which will contain all pre-existing data, marked as created.
116          *
117          * <p>
118          * This method returns a {@link Registration} object. To "unregister" your listener for changes call
119          * the {@link Registration#close()} method on the returned object.
120          *
121          * <p>
122          * You MUST explicitly unregister your listener when you no longer want to receive notifications. This is
123          * especially true in OSGi environments, where failure to do so during bundle shutdown can lead to stale
124          * listeners being still registered.
125          *
126          * @param treeId Data tree identifier of the subtree which should be watched for changes.
127          * @param listener Listener instance which is being registered
128          * @return A {@link Registration} object, which may be used to unregister your listener using
129          *         {@link Registration#close()} to stop delivery of change events.
130          * @throws NullPointerException if any of the arguments is {@code null}
131          */
132         Registration registerTreeChangeListener(DOMDataTreeIdentifier treeId, DOMDataTreeChangeListener listener);
133
134         /**
135          * Registers a {@link DOMDataTreeChangeListener} to receive notifications when data changes under a given path
136          * in the conceptual data tree.
137          *
138          * <p>
139          * You are able to register for notifications for any node or subtree which can be represented using
140          * {@link DOMDataTreeIdentifier}.
141          *
142          * <p>
143          * You are able to register for data change notifications for a subtree or leaf even if it does not exist. You
144          * will receive notification once that node is created.
145          *
146          * <p>
147          * If there is any pre-existing data in the data tree for the path for which you are registering, you will
148          * receive an initial data change event, which will contain all pre-existing data, marked as created.
149          *
150          * <p>
151          * This method returns a {@link Registration} object. To "unregister" your listener for changes call
152          * the {@link Registration#close()} method on the returned object.
153          *
154          * <p>
155          * You MUST explicitly unregister your listener when you no longer want to receive notifications. This is
156          * especially true in OSGi environments, where failure to do so during bundle shutdown can lead to stale
157          * listeners being still registered.
158          *
159          * @param treeId Data tree identifier of the subtree which should be watched for changes.
160          * @param listener Listener instance which is being registered
161          * @return A {@link Registration} object, which may be used to unregister your listener using
162          *         {@link Registration#close()} to stop delivery of change events.
163          * @throws NullPointerException if any of the arguments is {@code null}
164          * @deprecated This interface relies on magic of {@link ClusteredDOMDataTreeChangeListener}. See
165          *             {@link #registerLegacyTreeChangeListener(DOMDataTreeIdentifier, DOMDataTreeChangeListener)} for
166          *             migration guidance.
167          */
168         @Deprecated(since = "13.0.0", forRemoval = true)
169         default Registration registerDataTreeChangeListener(final DOMDataTreeIdentifier treeId,
170                 final DOMDataTreeChangeListener listener) {
171             return listener instanceof ClusteredDOMDataTreeChangeListener clustered
172                 ? registerDataTreeChangeListener(treeId, clustered)
173                     : registerLegacyTreeChangeListener(treeId, listener);
174         }
175
176         /**
177          * Registers a {@link ClusteredDOMDataTreeChangeListener} to receive notifications when data changes under a
178          * given path in the conceptual data tree. This is a migration shorthand for
179          * {@code registerDataTreeListener(treeId, listener)}.
180          *
181          * @param treeId Data tree identifier of the subtree which should be watched for changes.
182          * @param listener Listener instance which is being registered
183          * @return A {@link Registration} object, which may be used to unregister your listener using
184          *         {@link Registration#close()} to stop delivery of change events.
185          * @throws NullPointerException if any of the arguments is {@code null}
186          * @deprecated Use {@link #registerTreeChangeListener(DOMDataTreeIdentifier, DOMDataTreeChangeListener)}
187          *             instead.
188          */
189         @Deprecated(since = "13.0.0", forRemoval = true)
190         default Registration registerDataTreeChangeListener(final DOMDataTreeIdentifier treeId,
191                 final ClusteredDOMDataTreeChangeListener listener) {
192             return registerTreeChangeListener(treeId, listener);
193         }
194
195         /**
196          * Registers a {@link DOMDataTreeChangeListener} to receive notifications when data changes under a given path
197          * in the conceptual data tree, with legacy semantics, where no events are delivered if this "cluster node"
198          * (further undefined) is a "leader" (also not explicitly undefined).
199          *
200          * <p>
201          * The sole known implementation, the Akka-based datastore, defines the difference in terms of RAFT, suspending
202          * even delivery when the RAFT leader is not local. Even when there may be valid use cases for this, RAFT there
203          * is a storage backend whose lifecycle is disconnected from this object.
204          *
205          * <p>
206          * Aside from the above difference, this method is equivalent to
207          * {@link #registerTreeChangeListener(DOMDataTreeIdentifier, DOMDataTreeChangeListener)}. If you are unable to
208          * migrate, please contact us on <a href="email:discuss@lists.opendaylight.org">the mailing list</a>
209          *
210          * @param treeId Data tree identifier of the subtree which should be watched for changes.
211          * @param listener Listener instance which is being registered
212          * @return A {@link Registration} object, which may be used to unregister your listener using
213          *         {@link Registration#close()} to stop delivery of change events.
214          * @throws NullPointerException if any of the arguments is {@code null}
215          */
216         @Deprecated(since = "13.0.0", forRemoval = true)
217         Registration registerLegacyTreeChangeListener(DOMDataTreeIdentifier treeId, DOMDataTreeChangeListener listener);
218     }
219 }