74c4ae48b0cdf70fcd00ef7e8f2179961f508e05
[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.util.concurrent.FluentFuture;
12 import java.util.Optional;
13 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16
17 /**
18  * Snapshot of the datastore state. Note this snapshot is not consistent across shards because sub-shard snapshots are
19  * created lazily.
20  *
21  * @author Robert Varga
22  */
23 @Beta
24 public class ClientSnapshot extends AbstractClientHandle<AbstractProxyTransaction> {
25     // Hidden to prevent outside instantiation
26     ClientSnapshot(final AbstractClientHistory parent, final TransactionIdentifier transactionId) {
27         super(parent, transactionId);
28     }
29
30     private AbstractProxyTransaction createProxy(final Long shard) {
31         return parent().createSnapshotProxy(getIdentifier(), shard);
32     }
33
34     private AbstractProxyTransaction ensureSnapshotProxy(final YangInstanceIdentifier path) {
35         return ensureProxy(path, this::createProxy);
36     }
37
38     public FluentFuture<Boolean> exists(final YangInstanceIdentifier path) {
39         return ensureSnapshotProxy(path).exists(path);
40     }
41
42     public FluentFuture<Optional<NormalizedNode<?, ?>>> read(final YangInstanceIdentifier path) {
43         return ensureSnapshotProxy(path).read(path);
44     }
45 }