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.spi.store;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.util.concurrent.FluentFuture;
14 import com.google.common.util.concurrent.MoreExecutors;
15 import java.util.Optional;
16 import org.opendaylight.mdsal.common.api.ReadFailedException;
17 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Implementation of Read-Write transaction which is backed by {@link DataTreeSnapshot} and executed according
26 * to {@link SnapshotBackedWriteTransaction.TransactionReadyPrototype}.
28 * @param <T> identifier type
31 public final class SnapshotBackedReadWriteTransaction<T> extends
32 SnapshotBackedWriteTransaction<T> implements DOMStoreReadWriteTransaction {
33 private static final Logger LOG = LoggerFactory.getLogger(SnapshotBackedReadWriteTransaction.class);
35 SnapshotBackedReadWriteTransaction(final T identifier, final boolean debug,
36 final DataTreeSnapshot snapshot, final TransactionReadyPrototype<T> readyImpl) {
37 super(identifier, debug, snapshot, readyImpl);
40 @SuppressWarnings("checkstyle:IllegalCatch")
42 public FluentFuture<Optional<NormalizedNode>> read(final YangInstanceIdentifier path) {
43 LOG.debug("Tx: {} Read: {}", getIdentifier(), path);
44 requireNonNull(path, "Path must not be null.");
46 final Optional<NormalizedNode> result;
49 result = readSnapshotNode(path);
50 } catch (Exception e) {
51 LOG.error("Tx: {} Failed Read of {}", getIdentifier(), path, e);
52 return FluentFutures.immediateFailedFluentFuture(new ReadFailedException("Read failed", e));
56 return FluentFutures.immediateFailedFluentFuture(new ReadFailedException("Transaction is closed"));
59 return FluentFutures.immediateFluentFuture(result);
62 @SuppressWarnings("checkstyle:IllegalCatch")
64 public FluentFuture<Boolean> exists(final YangInstanceIdentifier path) {
65 return read(path).transform(Optional::isPresent, MoreExecutors.directExecutor());