BUG-1092: adjust to YangInstanceIdentifier
[controller.git] / opendaylight / md-sal / sal-inmemory-datastore / src / main / java / org / opendaylight / controller / md / sal / dom / store / impl / SnapshotBackedReadTransaction.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.md.sal.dom.store.impl;
9
10 import static com.google.common.base.Preconditions.checkNotNull;
11 import static com.google.common.base.Preconditions.checkState;
12
13 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
14 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
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;
24
25 /**
26  *
27  * Implementation of read-only transaction backed by {@link DataTreeSnapshot}
28  *
29  * Implementation of read-only transaction backed by {@link DataTreeSnapshot}
30  * which delegates most of its calls to similar methods provided by underlying snapshot.
31  *
32  */
33 final class SnapshotBackedReadTransaction extends AbstractDOMStoreTransaction implements
34 DOMStoreReadTransaction {
35     private static final Logger LOG = LoggerFactory.getLogger(SnapshotBackedReadTransaction.class);
36     private DataTreeSnapshot stableSnapshot;
37
38     public SnapshotBackedReadTransaction(final Object identifier, final DataTreeSnapshot snapshot) {
39         super(identifier);
40         this.stableSnapshot = Preconditions.checkNotNull(snapshot);
41         LOG.debug("ReadOnly Tx: {} allocated with snapshot {}", identifier, snapshot);
42     }
43
44     @Override
45     public void close() {
46         LOG.debug("Store transaction: {} : Closed", getIdentifier());
47         stableSnapshot = null;
48     }
49
50     @Override
51     public ListenableFuture<Optional<NormalizedNode<?, ?>>> read(final YangInstanceIdentifier path) {
52         checkNotNull(path, "Path must not be null.");
53         checkState(stableSnapshot != null, "Transaction is closed");
54         return Futures.immediateFuture(stableSnapshot.readNode(path));
55     }
56 }