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.md.sal.dom.broker.impl.legacy.sharded.adapter;
10 import static com.google.common.base.Preconditions.checkNotNull;
11 import static org.opendaylight.controller.md.sal.dom.broker.impl.legacy.sharded.adapter.LegacyShardedDOMDataBrokerAdapterUtils.translateDataStoreType;
13 import com.google.common.base.Optional;
14 import com.google.common.util.concurrent.CheckedFuture;
15 import com.google.common.util.concurrent.Futures;
16 import com.google.common.util.concurrent.MoreExecutors;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
19 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
20 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
25 * Read transaction that delegates calls to {@link org.opendaylight.mdsal.dom.broker.ShardedDOMReadTransactionAdapter},
26 * which in turn translates calls to shard aware implementation of
27 * {@link org.opendaylight.mdsal.dom.api.DOMDataTreeService}.
30 * Since reading data distributed on different subshards is not guaranteed to
31 * return all relevant data, we cannot guarantee it neither. Best effort is to
32 * return all data we get from first initial data change event received.
34 class ShardedDOMDataBrokerDelegatingReadTransaction implements DOMDataReadOnlyTransaction {
35 private final DOMDataTreeReadTransaction delegateTx;
36 private final Object txIdentifier;
38 ShardedDOMDataBrokerDelegatingReadTransaction(final Object txIdentifier,
39 final DOMDataTreeReadTransaction delegateTx) {
40 this.delegateTx = checkNotNull(delegateTx);
41 this.txIdentifier = checkNotNull(txIdentifier);
45 public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final LogicalDatastoreType store,
46 final YangInstanceIdentifier path) {
47 return Futures.makeChecked(delegateTx.read(translateDataStoreType(store), path).transform(
48 Optional::fromJavaUtil, MoreExecutors.directExecutor()), ReadFailedException.MAPPER);
52 public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
53 final YangInstanceIdentifier path) {
54 return Futures.makeChecked(
55 delegateTx.exists(LegacyShardedDOMDataBrokerAdapterUtils.translateDataStoreType(store), path),
56 ReadFailedException.MAPPER);
60 public Object getIdentifier() {