Merge "Bug 1392: Change ReadTransaction#read to return CheckedFuture"
[controller.git] / opendaylight / md-sal / sal-binding-api / src / main / java / org / opendaylight / controller / md / sal / binding / api / ReadTransaction.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.binding.api;
9
10 import org.opendaylight.controller.md.sal.common.api.data.AsyncReadTransaction;
11 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
12 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
13 import org.opendaylight.yangtools.yang.binding.DataObject;
14 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
15
16 import com.google.common.base.Optional;
17 import com.google.common.util.concurrent.CheckedFuture;
18
19 /**
20  * A transaction that provides read access to a logical data store.
21  * <p>
22  * For more information on usage and examples, please see the documentation in {@link AsyncReadTransaction}.
23  */
24 public interface ReadTransaction extends AsyncReadTransaction<InstanceIdentifier<?>, DataObject> {
25
26     /**
27      * Reads data from the provided logical data store located at the provided path.
28      *<p>
29      * If the target is a subtree, then the whole subtree is read (and will be
30      * accessible from the returned data object).
31      *
32      * @param store
33      *            Logical data store from which read should occur.
34      * @param path
35      *            Path which uniquely identifies subtree which client want to
36      *            read
37      * @return a CheckFuture containing the result of the read. The Future blocks until the
38      *         commit operation is complete. Once complete:
39      *         <ul>
40      *         <li>If the data at the supplied path exists, the Future returns an Optional object
41      *         containing the data.</li>
42      *         <li>If the data at the supplied path does not exist, the Future returns
43      *         Optional#absent().</li>
44      *         <li>If the read of the data fails, the Future will fail with a
45      *         {@link ReadFailedException} or an exception derived from ReadFailedException.</li>
46      *         </ul>
47      */
48     <T extends DataObject> CheckedFuture<Optional<T>,ReadFailedException> read(
49             LogicalDatastoreType store, InstanceIdentifier<T> path);
50 }