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.dom.api;
10 import com.google.common.util.concurrent.FluentFuture;
11 import java.util.Optional;
12 import org.opendaylight.mdsal.common.api.AsyncReadTransaction;
13 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
14 import org.opendaylight.mdsal.common.api.ReadFailedException;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 * A transaction that provides read access to a logical data store.
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 DOMDataTreeReadTransaction extends DOMDataTreeTransaction,
54 AsyncReadTransaction<YangInstanceIdentifier, NormalizedNode<?, ?>> {
56 * Reads data from provided logical data store located at the provided path.
59 * If the target is a subtree, then the whole subtree is read (and will be accessible from the returned data
62 * @param store Logical data store from which read should occur.
63 * @param path Path which uniquely identifies subtree which client want to read
64 * @return a FluentFuture containing the result of the read. The Future blocks until the commit operation is
65 * complete. Once complete:
67 * <li>If the data at the supplied path exists, the Future returns an Optional object containing the data.
69 * <li>If the data at the supplied path does not exist, the Future returns Optional.empty().</li>
70 * <li>If the read of the data fails, the Future will fail with a {@link ReadFailedException} or
71 * an exception derived from ReadFailedException.</li>
74 FluentFuture<Optional<NormalizedNode<?,?>>> read(LogicalDatastoreType store, YangInstanceIdentifier path);
77 * Checks if data is available in the logical data store located at provided path.
80 * Note: a successful result from this method makes no guarantee that a subsequent call to {@link #read} will
81 * succeed. It is possible that the data resides in a data store on a remote node and, if that node goes down or
82 * a network failure occurs, a subsequent read would fail. Another scenario is if the data is deleted in between
83 * the calls to <code>exists</code> and <code>read</code>
85 * @param store Logical data store from which read should occur.
86 * @param path Path which uniquely identifies subtree which client want to check existence of
87 * @return a FluentFuture containing the result of the check.
89 * <li>If the data at the supplied path exists, the Future returns a Boolean whose value is true,
90 * false otherwise</li>
91 * <li>If checking for the data fails, the Future will fail with a {@link ReadFailedException} or
92 * an exception derived from ReadFailedException.</li>
95 FluentFuture<Boolean> exists(LogicalDatastoreType store, YangInstanceIdentifier path);
98 * Closes this transaction and releases all resources associated with it.