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.dom.store.impl;
10 import static com.google.common.base.Preconditions.checkNotNull;
11 import static com.google.common.base.Preconditions.checkState;
13 import org.opendaylight.controller.md.sal.dom.store.impl.tree.DataTreeSnapshot;
14 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
15 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 import com.google.common.base.Optional;
21 import com.google.common.base.Preconditions;
22 import com.google.common.util.concurrent.Futures;
23 import com.google.common.util.concurrent.ListenableFuture;
27 * Implementation of read-only transaction backed by {@link DataTreeSnapshot}
29 * Implementation of read-only transaction backed by {@link DataTreeSnapshot}
30 * which delegates most of its calls to similar methods provided by underlying snapshot.
33 final class SnapshotBackedReadTransaction extends AbstractDOMStoreTransaction implements
34 DOMStoreReadTransaction {
35 private static final Logger LOG = LoggerFactory.getLogger(SnapshotBackedReadTransaction.class);
36 private DataTreeSnapshot stableSnapshot;
38 public SnapshotBackedReadTransaction(final Object identifier, final DataTreeSnapshot snapshot) {
40 this.stableSnapshot = Preconditions.checkNotNull(snapshot);
41 LOG.debug("ReadOnly Tx: {} allocated with snapshot {}", identifier, snapshot);
46 LOG.debug("Store transaction: {} : Closed", getIdentifier());
47 stableSnapshot = null;
51 public ListenableFuture<Optional<NormalizedNode<?, ?>>> read(final InstanceIdentifier path) {
52 checkNotNull(path, "Path must not be null.");
53 checkState(stableSnapshot != null, "Transaction is closed");
54 return Futures.immediateFuture(stableSnapshot.readNode(path));