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 * Provides access to a conceptual data tree store.
18 * Also provides the ability to subscribe for changes to data under a given
22 * All operations on data tree are performed via one of the transactions:
24 * <li>Read-Only - allocated using {@link #newReadOnlyTransaction()}
25 * <li>Write-Only - allocated using {@link #newWriteOnlyTransaction()}
26 * <li>Read-Write - allocated using {@link #newReadWriteTransaction()}
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.
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()}.
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.
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.
54 * Type of path (subtree identifier), which represents location in
57 * Type of data (payload), which represents data payload
59 public interface AsyncDataBroker<P extends Path<P>, D, L extends AsyncDataChangeListener<P, D>> extends //
60 AsyncDataTransactionFactory<P, D> {
64 * Scope of Data Change
67 * Represents scope of data change (addition, replacement, deletion).
69 * The terminology for scope types is reused from LDAP.
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.
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
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
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
103 * @see http://www.idevelopment.info/data/LDAP/LDAP_Resources/
104 * SEARCH_Setting_the_SCOPE_Parameter.shtml
106 public enum DataChangeScope {
109 * Represents only a direct change of the node, such as replacement of a
110 * node, addition or deletion.
115 * Represent a change (addition,replacement,deletion) of the node or one
116 * of its direct children.
118 * This scope is superset of {@link #BASE}.
123 * Represents a change of the node or any of or any of its child nodes,
126 * This scope is superset of {@link #ONE} and {@link #BASE}.
136 public AsyncReadTransaction<P, D> newReadOnlyTransaction();
142 public AsyncReadWriteTransaction<P, D> newReadWriteTransaction();
148 public AsyncWriteTransaction<P, D> newWriteOnlyTransaction();
151 * Registers a {@link AsyncDataChangeListener} to receive
152 * notifications when data changes under a given path in the conceptual data
155 * You are able to register for notifications for any node or subtree
156 * which can be reached via the supplied path.
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.
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
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.
170 * You are also able to specify the scope of the changes you want to be
173 * Supported scopes are:
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
185 * See {@link DataChangeScope} for examples.
187 * This method returns a {@link ListenerRegistration} object. To
188 * "unregister" your listener for changes call the "close" method on this
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).
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}
200 * Path (subtree identifier) on which client listener will be
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.
210 ListenerRegistration<L> registerDataChangeListener(LogicalDatastoreType store, P path, L listener,
211 DataChangeScope triggeringScope);