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.controller.md.sal.binding.api;
10 import com.google.common.base.Optional;
11 import com.google.common.util.concurrent.CheckedFuture;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.MoreExecutors;
14 import org.opendaylight.controller.md.sal.common.api.MappingCheckedFuture;
15 import org.opendaylight.controller.md.sal.common.api.data.AsyncReadTransaction;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 * A transaction that provides read access to a logical data store.
25 * For more information on usage and examples, please see the documentation in {@link AsyncReadTransaction}.
27 public interface ReadTransaction extends AsyncReadTransaction<InstanceIdentifier<?>, DataObject> {
29 * Reads data from the provided logical data store located at the provided path.
32 * If the target is a subtree, then the whole subtree is read (and will be accessible from the returned data
35 * @param store Logical data store from which read should occur.
36 * @param path Path which uniquely identifies subtree which client want to read
37 * @return a CheckFuture containing the result of the read. The Future blocks until the
38 * commit operation is complete. Once complete:
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>
48 <T extends DataObject> CheckedFuture<Optional<T>, ReadFailedException> read(
49 LogicalDatastoreType store, InstanceIdentifier<T> path);
52 * Checks if data is available in the logical data store located at provided path.
55 * Note: a successful result from this method makes no guarantee that a subsequent call to {@link #read}
56 * will succeed. It is possible that the data resides in a data store on a remote node and, if that
57 * node goes down or a network failure occurs, a subsequent read would fail. Another scenario is if
58 * the data is deleted in between the calls to <code>exists</code> and <code>read</code>
61 * Default implementation delegates to {@link #read(LogicalDatastoreType, InstanceIdentifier)}, implementations
62 * are advised to provide a more efficient override.
64 * @param store Logical data store from which read should occur.
65 * @param path Path which uniquely identifies subtree which client want to check existence of
66 * @return a CheckFuture containing the result of the check.
68 * <li>If the data at the supplied path exists, the Future returns a Boolean
69 * whose value is true, false otherwise</li>
70 * <li>If checking for the data fails, the Future will fail with a
71 * {@link ReadFailedException} or an exception derived from ReadFailedException.</li>
74 default CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
75 final InstanceIdentifier<?> path) {
76 return MappingCheckedFuture.create(Futures.transform(read(store, path), Optional::isPresent,
77 MoreExecutors.directExecutor()), ReadFailedException.MAPPER);