/* * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.controller.cluster.databroker.actors.dds; import com.google.common.annotations.Beta; import com.google.common.util.concurrent.FluentFuture; import java.util.Optional; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.utils.RootScatterGather; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; /** * Snapshot of the datastore state. Note this snapshot is not consistent across shards because sub-shard snapshots are * created lazily. * * @author Robert Varga */ @Beta public class ClientSnapshot extends AbstractClientHandle { // Hidden to prevent outside instantiation ClientSnapshot(final AbstractClientHistory parent, final TransactionIdentifier transactionId) { super(parent, transactionId); } public FluentFuture exists(final YangInstanceIdentifier path) { return ensureProxy(path).exists(path); } public FluentFuture> read(final YangInstanceIdentifier path) { return path.isEmpty() ? readRoot() : ensureProxy(path).read(path); } private FluentFuture> readRoot() { return RootScatterGather.gather(parent().actorUtils(), ensureAllProxies() .map(proxy -> proxy.read(YangInstanceIdentifier.empty()))); } @Override final AbstractProxyTransaction createProxy(final Long shard) { return parent().createSnapshotProxy(getIdentifier(), shard); } }