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.mdsal.binding.api;
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.binding.DataObject;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 * A transaction that provides a stateful read-only view of the data tree.
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.
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.
30 * <h2>Transaction isolation example</h2>
31 * Lets assume initial state of data tree for <code>PATH</code> is <code>A</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;
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.
53 public interface ReadTransaction extends Transaction, Registration {
55 * Reads data from the provided logical data store located at the provided path.
58 * If the target is a subtree, then the whole subtree is read (and will be accessible from the returned data
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:
66 * <li>If the data at the supplied path exists, the Future returns an Optional object containing the data.
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>
73 <T extends DataObject> FluentFuture<Optional<T>> read(LogicalDatastoreType store, InstanceIdentifier<T> path);
76 * Closes this transaction and releases all resources associated with it.