Merge "Bug 1245: Dropped Binding prefix from Binding Data APIs."
[controller.git] / opendaylight / md-sal / sal-common-api / src / main / java / org / opendaylight / controller / md / sal / common / api / data / AsyncReadTransaction.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.controller.md.sal.common.api.data;
9
10 import org.opendaylight.yangtools.concepts.Path;
11
12 import com.google.common.base.Optional;
13 import com.google.common.util.concurrent.ListenableFuture;
14
15 /**
16  *
17  * Provides a stateful read view of the data tree.
18  *
19  * <p>
20  * View of the data tree is a stable point-in-time snapshot of the current data tree state when
21  * the transaction was created. It's state and underlying data tree
22  * is not affected by other concurrently running transactions.
23  *
24  * <p>
25  * <b>Implementation Note:</b> This interface is not intended to be implemented
26  * by users of MD-SAL, but only to be consumed by them.
27  *
28  * <h2>Transaction isolation example</h2>
29  * Lets assume initial state of data tree for <code>PATH</code> is <code>A</code>.
30  *
31  * <pre>
32  * txRead = broker.newReadOnlyTransaction();   // read Transaction is snapshot of data
33  * txWrite = broker.newReadWriteTransactoin(); // concurrent write transaction
34  *
35  * txRead.read(OPERATIONAL,PATH).get();        // will return Optional containing A
36  * txWrite = broker.put(OPERATIONAL,PATH,B);   // writes B to PATH
37  *
38  * txRead.read(OPERATIONAL,PATH).get();        // still returns Optional containing A
39  *
40  * txWrite.commit().get();                     // data tree is updated, PATH contains B
41  * txRead.read(OPERATIONAL,PATH).get();        // still returns Optional containing A
42  *
43  * txAfterCommit = broker.newReadOnlyTransaction(); // read Transaction is snapshot of new state
44  * txAfterCommit.read(OPERATIONAL,PATH).get(); // returns Optional containing B;
45  * </pre>
46  *
47  * <p>
48  * <b>Note:</b> example contains blocking calls on future only to illustrate
49  * that action happened after other asynchronous action. Use of blocking call
50  * {@link ListenableFuture#get()} is discouraged for most uses and you should
51  * use
52  * {@link com.google.common.util.concurrent.Futures#addCallback(ListenableFuture, com.google.common.util.concurrent.FutureCallback)}
53  * or other functions from {@link com.google.common.util.concurrent.Futures} to
54  * register more specific listeners.
55  *
56  * @param <P>
57  *            Type of path (subtree identifier), which represents location in
58  *            tree
59  * @param <D>
60  *            Type of data (payload), which represents data payload
61  */
62 public interface AsyncReadTransaction<P extends Path<P>, D> extends AsyncTransaction<P, D> {
63
64     /**
65      *
66      * Reads data from provided logical data store located at the provided path.
67      *<p>
68      * If the target is a subtree, then the whole subtree is read (and will be
69      * accessible from the returned data object).
70      *
71      * @param store
72      *            Logical data store from which read should occur.
73      * @param path
74      *            Path which uniquely identifies subtree which client want to
75      *            read
76      * @return Listenable Future which contains read result
77      *         <ul>
78      *         <li>If data at supplied path exists the
79      *         {@link ListeblaFuture#get()} returns Optional object containing
80      *         data once read is done.
81      *         <li>If data at supplied path does not exists the
82      *         {@link ListenbleFuture#get()} returns {@link Optional#absent()}.
83      *         </ul>
84      */
85     ListenableFuture<Optional<D>> read(LogicalDatastoreType store, P path);
86
87 }