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.controller.md.sal.common.api.data;
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 to
16 * 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()}
23 * <li>Read-Write - allocated using {@link #newReadWriteTransaction()}
27 * These transactions provide a stable isolated view of data tree, which is
28 * guaranteed to be not affected by other concurrent transactions, until
29 * transaction is committed.
32 * For a detailed explanation of how transaction are isolated and how transaction-local
33 * changes are committed to global data tree, see
34 * {@link AsyncReadTransaction}, {@link AsyncWriteTransaction},
35 * {@link AsyncReadWriteTransaction} and {@link AsyncWriteTransaction#commit()}.
39 * It is strongly recommended to use the type of transaction, which
40 * provides only the minimal capabilities you need. This allows for
41 * optimizations at the data broker / data store level. For example,
42 * implementations may optimize the transaction for reading if they know ahead
43 * of time that you only need to read data - such as not keeping additional meta-data,
44 * which may be required for write transactions.
47 * <b>Implementation Note:</b> This interface is not intended to be implemented
48 * by users of MD-SAL, but only to be consumed by them.
51 * Type of path (subtree identifier), which represents location in
54 * Type of data (payload), which represents data payload
56 public interface AsyncDataBroker<P extends Path<P>, D, L extends AsyncDataChangeListener<P, D>> extends //
57 AsyncDataTransactionFactory<P, D> {
61 * Scope of Data Change
64 * Represents scope of data change (addition, replacement, deletion).
66 * The terminology for scope types is reused from LDAP.
70 * Following is an example model with comments describing what notifications you would receive
71 * based on the scope you specify, when you are registering for changes on container a.
74 * container a // scope BASE, ONE, SUBTREE
75 * leaf "foo" // scope ONE, SUBTREE
76 * container // scope ONE, SUBTREE
77 * leaf "bar" // scope SUBTREE
78 * list list // scope ONE, SUBTREE
79 * list [a] // scope SUBTREE
80 * id "a" // scope SUBTREE
81 * list [b] // scope SUBTREE
82 * id "b" // scope SUBTREE
85 * Following is an example model with comments describing what notifications you would receive
86 * based on the scope you specify, when you are registering for changes on list list (without
87 * specifying concrete item in the list).
90 * list list // scope BASE, ONE, SUBTREE
91 * list [a] // scope ONE, SUBTREE
92 * id "a" // scope SUBTREE
93 * list [b] // scope ONE, SUBTREE
94 * id "b" // scope SUBTREE
99 * "http://www.idevelopment.info/data/LDAP/LDAP_Resources/SEARCH_Setting_the_SCOPE_Parameter.shtml"
100 * >LDAP Scope</a> for scope reference.
102 public enum DataChangeScope {
105 * Represents only a direct change of the node, such as replacement of a
106 * node, addition or deletion.
111 * Represent a change (addition,replacement,deletion) of the node or one
112 * of its direct children.
114 * This scope is superset of {@link #BASE}.
119 * Represents a change of the node or any of or any of its child nodes,
122 * This scope is superset of {@link #ONE} and {@link #BASE}.
132 public AsyncReadOnlyTransaction<P, D> newReadOnlyTransaction();
138 public AsyncReadWriteTransaction<P, D> newReadWriteTransaction();
144 public AsyncWriteTransaction<P, D> newWriteOnlyTransaction();
147 * Registers a {@link AsyncDataChangeListener} to receive
148 * notifications when data changes under a given path in the conceptual data
151 * You are able to register for notifications for any node or subtree
152 * which can be reached via the supplied path.
154 * If path type <code>P</code> allows it, you may specify paths up to the leaf nodes
155 * then it is possible to listen on leaf nodes.
157 * You are able to register for data change notifications for a subtree even
158 * if it does not exist. You will receive notification once that node is
161 * If there is any preexisting data in data tree on path for which you are
162 * registering, you will receive initial data change event, which will
163 * contain all preexisting data, marked as created.
166 * You are also able to specify the scope of the changes you want to be
169 * Supported scopes are:
171 * <li>{@link DataChangeScope#BASE} - notification events will only be
172 * triggered when a node referenced by path is created, removed or replaced.
173 * <li>{@link DataChangeScope#ONE} - notifications events will only be
174 * triggered when a node referenced by path is created, removed or replaced,
175 * or any or any of its immediate children are created, updated or removed.
176 * <li>{@link DataChangeScope#SUBTREE} - notification events will be
177 * triggered when a node referenced by the path is created, removed
178 * or replaced or any of the children in its subtree are created, removed
181 * See {@link DataChangeScope} for examples.
183 * This method returns a {@link ListenerRegistration} object. To
184 * "unregister" your listener for changes call the "close" method on this
187 * You MUST call close when you no longer need to receive notifications
188 * (such as during shutdown or for example if your bundle is shutting down).
191 * Logical Data Store - Logical Datastore you want to listen for
192 * changes in. For example
193 * {@link LogicalDatastoreType#OPERATIONAL} or
194 * {@link LogicalDatastoreType#CONFIGURATION}
196 * Path (subtree identifier) on which client listener will be
199 * Instance of listener which should be invoked on
200 * @param triggeringScope
201 * Scope of change which triggers callback.
202 * @return Listener registration object, which may be used to unregister
203 * your listener using {@link ListenerRegistration#close()} to stop
204 * delivery of change events.
206 ListenerRegistration<L> registerDataChangeListener(LogicalDatastoreType store, P path, L listener,
207 DataChangeScope triggeringScope);