2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.javav2.api;
10 import com.google.common.annotations.Beta;
11 import java.util.function.BiConsumer;
12 import org.opendaylight.mdsal.binding.javav2.spec.base.InstanceIdentifier;
13 import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
14 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
15 import org.opendaylight.mdsal.common.api.ReadFailedException;
16 import org.opendaylight.yangtools.concepts.Registration;
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.
54 public interface ReadTransaction extends Transaction, Registration {
56 * Reads data from the 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
60 * accessible from the returned data object).
63 * Logical data store from which read should occur.
65 * Path which uniquely identifies subtree which client want to
67 * @param callback result callback
68 * @param <T> result type
70 <T extends TreeNode> void read(LogicalDatastoreType store, InstanceIdentifier<T> path,
71 BiConsumer<ReadFailedException, T> callback);
74 * Closes this transaction and releases all resources associated with it.