2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.common.api;
10 import org.opendaylight.yangtools.concepts.ListenerRegistration;
11 import org.opendaylight.yangtools.concepts.Path;
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.
19 * All operations on the data tree are performed via one of the transactions:
21 * <li>Read-Only - allocated using {@link #newReadOnlyTransaction()}
22 * <li>Write-Only - allocated using {@link #newWriteOnlyTransaction()}
26 * These transactions provide a stable isolated view of data tree, which is guaranteed to be not
27 * affected by other concurrent transactions, until transaction is committed.
30 * For a detailed explanation of how transaction are isolated and how transaction-local changes are
31 * committed to global data tree, see {@link AsyncReadTransaction}, {@link AsyncWriteTransaction}
32 * and {@link AsyncWriteTransaction#submit()}.
36 * It is strongly recommended to use the type of transaction, which provides only the minimal
37 * capabilities you need. This allows for optimizations at the data broker / data store level. For
38 * example, implementations may optimize the transaction for reading if they know ahead of time that
39 * you only need to read data - such as not keeping additional meta-data, which may be required for
43 * <b>Implementation Note:</b> This interface is not intended to be implemented by users of MD-SAL,
44 * but only to be consumed by them.
46 * @param <P> Type of path (subtree identifier), which represents location in tree
47 * @param <D> Type of data (payload), which represents data payload
49 public interface AsyncDataBroker<P extends Path<P>, D, L extends AsyncDataChangeListener<P, D>> extends
50 AsyncDataTransactionFactory<P, D> {
54 * Scope of Data Change
57 * Represents scope of data change (addition, replacement, deletion).
59 * The terminology for scope types is reused from LDAP.
63 * Following is an example model with comments describing what notifications you would receive
64 * based on the scope you specify, when you are registering for changes on container a.
67 * container a // scope BASE, ONE, SUBTREE
68 * leaf "foo" // scope ONE, SUBTREE
69 * container // scope ONE, SUBTREE
70 * leaf "bar" // scope SUBTREE
71 * list list // scope ONE, SUBTREE
72 * list [a] // scope SUBTREE
73 * id "a" // scope SUBTREE
74 * list [b] // scope SUBTREE
75 * id "b" // scope SUBTREE
78 * Following is an example model with comments describing what notifications you would receive
79 * based on the scope you specify, when you are registering for changes on list list (without
80 * specifying concrete item in the list).
83 * list list // scope BASE, ONE, SUBTREE
84 * list [a] // scope ONE, SUBTREE
85 * id "a" // scope SUBTREE
86 * list [b] // scope ONE, SUBTREE
87 * id "b" // scope SUBTREE
92 * "http://www.idevelopment.info/data/LDAP/LDAP_Resources/SEARCH_Setting_the_SCOPE_Parameter.shtml"
93 * >LDAP Scope</a> for scope reference.
95 public enum DataChangeScope {
98 * Represents only a direct change of the node, such as replacement of a
99 * node, addition or deletion.
104 * Represent a change (addition,replacement,deletion) of the node or one
105 * of its direct children.
107 * This scope is superset of {@link #BASE}.
112 * Represents a change of the node or any of or any of its child nodes,
115 * This scope is superset of {@link #ONE} and {@link #BASE}.
125 AsyncReadTransaction<P, D> newReadOnlyTransaction();
132 AsyncWriteTransaction<P, D> newWriteOnlyTransaction();
135 * Registers a {@link AsyncDataChangeListener} to receive
136 * notifications when data changes under a given path in the conceptual data
139 * You are able to register for notifications for any node or subtree
140 * which can be reached via the supplied path.
142 * If path type <code>P</code> allows it, you may specify paths up to the leaf nodes
143 * then it is possible to listen on leaf nodes.
145 * You are able to register for data change notifications for a subtree even
146 * if it does not exist. You will receive notification once that node is
149 * If there is any preexisting data in data tree on path for which you are
150 * registering, you will receive initial data change event, which will
151 * contain all preexisting data, marked as created.
154 * You are also able to specify the scope of the changes you want to be
157 * Supported scopes are:
159 * <li>{@link DataChangeScope#BASE} - notification events will only be
160 * triggered when a node referenced by path is created, removed or replaced.
161 * <li>{@link DataChangeScope#ONE} - notifications events will only be
162 * triggered when a node referenced by path is created, removed or replaced,
163 * or any or any of its immediate children are created, updated or removed.
164 * <li>{@link DataChangeScope#SUBTREE} - notification events will be
165 * triggered when a node referenced by the path is created, removed
166 * or replaced or any of the children in its subtree are created, removed
169 * See {@link DataChangeScope} for examples.
171 * This method returns a {@link ListenerRegistration} object. To
172 * "unregister" your listener for changes call the "close" method on this
175 * You MUST call close when you no longer need to receive notifications
176 * (such as during shutdown or for example if your bundle is shutting down).
179 * Logical Data Store - Logical Datastore you want to listen for
180 * changes in. For example
181 * {@link LogicalDatastoreType#OPERATIONAL} or
182 * {@link LogicalDatastoreType#CONFIGURATION}
184 * Path (subtree identifier) on which client listener will be
187 * Instance of listener which should be invoked on
188 * @param triggeringScope
189 * Scope of change which triggers callback.
190 * @return Listener registration object, which may be used to unregister
191 * your listener using {@link ListenerRegistration#close()} to stop
192 * delivery of change events.
194 ListenerRegistration<L> registerDataChangeListener(LogicalDatastoreType store, P path, L listener,
195 DataChangeScope triggeringScope);