BUG-5280: handle TransactionPurgeRequest replay
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / ClientSnapshot.java
1 /*
2  * Copyright (c) 2016 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.cluster.databroker.actors.dds;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.base.Optional;
12 import com.google.common.util.concurrent.CheckedFuture;
13 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
14 import org.opendaylight.mdsal.common.api.ReadFailedException;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17
18 /**
19  * Snapshot of the datastore state. Note this snapshot is not consistent across shards because sub-shard snapshots are
20  * created lazily.
21  *
22  * @author Robert Varga
23  */
24 @Beta
25 public class ClientSnapshot extends AbstractClientHandle<AbstractProxyTransaction> {
26     // Hidden to prevent outside instantiation
27     ClientSnapshot(final AbstractClientHistory parent, final TransactionIdentifier transactionId) {
28         super(parent, transactionId);
29     }
30
31     private AbstractProxyTransaction createProxy(final Long shard) {
32         return parent().createSnapshotProxy(getIdentifier(), shard);
33     }
34
35     private AbstractProxyTransaction ensureSnapshotProxy(final YangInstanceIdentifier path) {
36         return ensureProxy(path, this::createProxy);
37     }
38
39     public final CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) {
40         return ensureSnapshotProxy(path).exists(path);
41     }
42
43     public final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(
44             final YangInstanceIdentifier path) {
45         return ensureSnapshotProxy(path).read(path);
46     }
47 }