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.sal.core.spi.data;
10 import static com.google.common.base.Preconditions.checkNotNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.Optional;
14 import com.google.common.util.concurrent.CheckedFuture;
15 import com.google.common.util.concurrent.Futures;
16 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * Implementation of Read-Write transaction which is backed by {@link DataTreeSnapshot}
25 * and executed according to {@link TransactionReadyPrototype}.
27 * @param <T> identifier type
28 * @deprecated Use {@link org.opendaylight.mdsal.dom.spi.store.SnapshotBackedReadWriteTransaction} instead.
32 public final class SnapshotBackedReadWriteTransaction<T> extends SnapshotBackedWriteTransaction<T>
33 implements DOMStoreReadWriteTransaction {
34 private static final Logger LOG = LoggerFactory.getLogger(SnapshotBackedReadWriteTransaction.class);
36 SnapshotBackedReadWriteTransaction(final T identifier, final boolean debug,
37 final DataTreeSnapshot snapshot, final TransactionReadyPrototype<T> readyImpl) {
38 super(identifier, debug, snapshot, readyImpl);
42 @SuppressWarnings("checkstyle:IllegalCatch")
43 public CheckedFuture<Optional<NormalizedNode<?,?>>, ReadFailedException> read(final YangInstanceIdentifier path) {
44 LOG.debug("Tx: {} Read: {}", getIdentifier(), path);
45 checkNotNull(path, "Path must not be null.");
47 final Optional<NormalizedNode<?, ?>> result;
49 result = readSnapshotNode(path);
50 } catch (RuntimeException e) {
51 LOG.error("Tx: {} Failed Read of {}", getIdentifier(), path, e);
52 return Futures.immediateFailedCheckedFuture(new ReadFailedException("Read failed", e));
56 return Futures.immediateFailedCheckedFuture(new ReadFailedException("Transaction is closed"));
58 return Futures.immediateCheckedFuture(result);
63 public CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) {
65 return Futures.immediateCheckedFuture(
66 read(path).checkedGet().isPresent());
67 } catch (ReadFailedException e) {
68 return Futures.immediateFailedCheckedFuture(e);