2 * Copyright (c) 2016 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.cluster.databroker;
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 java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
14 import javax.annotation.Nullable;
15 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientSnapshot;
16 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
17 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22 * An implementation of {@link DOMStoreReadTransaction} backed by a {@link ClientSnapshot}. Used for standalone
25 * @author Robert Varga
27 final class ClientBackedReadTransaction extends ClientBackedTransaction<ClientSnapshot>
28 implements DOMStoreReadTransaction {
29 private static final AtomicReferenceFieldUpdater<ClientBackedReadTransaction, ClientBackedTransactionChain>
30 PARENT_UPDATER = AtomicReferenceFieldUpdater.newUpdater(ClientBackedReadTransaction.class,
31 ClientBackedTransactionChain.class, "parent");
33 @SuppressWarnings("unused")
34 private volatile ClientBackedTransactionChain parent;
36 ClientBackedReadTransaction(final ClientSnapshot delegate, @Nullable final ClientBackedTransactionChain parent) {
42 public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final YangInstanceIdentifier path) {
43 return Futures.makeChecked(delegate().read(path), ReadFailedException.MAPPER);
47 public CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) {
48 return Futures.makeChecked(delegate().exists(path), ReadFailedException.MAPPER);
55 final ClientBackedTransactionChain local = PARENT_UPDATER.getAndSet(this, null);
57 local.snapshotClosed(delegate());