Remove AsyncDataBroker and related classes
[mdsal.git] / dom / mdsal-dom-api / src / main / java / org / opendaylight / mdsal / dom / api / DOMDataTreeReadTransaction.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 com.google.common.util.concurrent.FluentFuture;
11 import java.util.Optional;
12 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
13 import org.opendaylight.mdsal.common.api.ReadFailedException;
14 import org.opendaylight.yangtools.concepts.Registration;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17
18 /**
19  * A transaction that provides read access to a logical data store.
20  *
21  * <p>
22  * View of the data tree is a stable point-in-time snapshot of the current data tree state when the
23  * transaction was created. It's state and underlying data tree is not affected by other
24  * concurrently running transactions.
25  *
26  * <p>
27  * <b>Implementation Note:</b> This interface is not intended to be implemented by users of MD-SAL,
28  * but only to be consumed by them.
29  *
30  * <h2>Transaction isolation example</h2>
31  * Lets assume initial state of data tree for <code>PATH</code> is <code>A</code>.
32  *
33  * <code>
34  * txRead = broker.newReadOnlyTransaction(); // read Transaction is snapshot of data
35  * txWrite = broker.newReadWriteTransactoin(); // concurrent write transaction
36  * txRead.read(OPERATIONAL, PATH).get(); // will return Optional containing A
37  * txWrite = broker.put(OPERATIONAL, PATH, B); // writes B to PATH
38  * txRead.read(OPERATIONAL, PATH).get(); // still returns Optional containing A
39  * txWrite.submit().get(); // data tree is updated, PATH contains B
40  * txRead.read(OPERATIONAL, PATH).get(); // still returns Optional containing A
41  * txAfterCommit = broker.newReadOnlyTransaction(); // read Transaction is snapshot of new state
42  * txAfterCommit.read(OPERATIONAL, PATH).get(); // returns Optional containing B;
43  * </code>
44  *
45  * <p>
46  * <b>Note:</b> example contains blocking calls on future only to illustrate that action happened after other
47  * asynchronous action. Use of blocking call {@link com.google.common.util.concurrent.FluentFuture#get()} is
48  * discouraged for most uses and you should use
49  * {@link com.google.common.util.concurrent.FluentFuture#addCallback(com.google.common.util.concurrent.FutureCallback,
50  * java.util.concurrent.Executor)} or other functions from {@link com.google.common.util.concurrent.Futures} to register
51  * more specific listeners.
52  */
53 public interface DOMDataTreeReadTransaction extends DOMDataTreeTransaction, Registration {
54     /**
55      * Reads data from provided logical data store located at the provided path.
56      *
57      *<p>
58      * If the target is a subtree, then the whole subtree is read (and will be accessible from the returned data
59      * object).
60      *
61      * @param store Logical data store from which read should occur.
62      * @param path Path which uniquely identifies subtree which client want to read
63      * @return a FluentFuture containing the result of the read. The Future blocks until the commit operation is
64      *         complete. Once complete:
65      *         <ul>
66      *         <li>If the data at the supplied path exists, the Future returns an Optional object containing the data.
67      *         </li>
68      *         <li>If the data at the supplied path does not exist, the Future returns Optional.empty().</li>
69      *         <li>If the read of the data fails, the Future will fail with a {@link ReadFailedException} or
70      *         an exception derived from ReadFailedException.</li>
71      *         </ul>
72      */
73     FluentFuture<Optional<NormalizedNode<?,?>>> read(LogicalDatastoreType store, YangInstanceIdentifier path);
74
75     /**
76      * Checks if data is available in the logical data store located at provided path.
77      *
78      * <p>
79      * Note: a successful result from this method makes no guarantee that a subsequent call to {@link #read} will
80      * succeed. It is possible that the data resides in a data store on a remote node and, if that node goes down or
81      * a network failure occurs, a subsequent read would fail. Another scenario is if the data is deleted in between
82      * the calls to <code>exists</code> and <code>read</code>
83      *
84      * @param store Logical data store from which read should occur.
85      * @param path Path which uniquely identifies subtree which client want to check existence of
86      * @return a FluentFuture containing the result of the check.
87      *         <ul>
88      *         <li>If the data at the supplied path exists, the Future returns a Boolean whose value is true,
89      *         false otherwise</li>
90      *         <li>If checking for the data fails, the Future will fail with a {@link ReadFailedException} or
91      *         an exception derived from ReadFailedException.</li>
92      *         </ul>
93      */
94     FluentFuture<Boolean> exists(LogicalDatastoreType store, YangInstanceIdentifier path);
95
96     /**
97      * Closes this transaction and releases all resources associated with it.
98      */
99     @Override
100     void close();
101 }