Simplify ListenableFuture translation
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / md / sal / dom / broker / impl / legacy / sharded / adapter / ShardedDOMDataBrokerDelegatingReadTransaction.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.md.sal.dom.broker.impl.legacy.sharded.adapter;
9
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;
12
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;
23
24 /**
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}.
28  *
29  * <p>
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.
33  */
34 class ShardedDOMDataBrokerDelegatingReadTransaction implements DOMDataReadOnlyTransaction {
35     private final DOMDataTreeReadTransaction delegateTx;
36     private final Object txIdentifier;
37
38     ShardedDOMDataBrokerDelegatingReadTransaction(final Object txIdentifier,
39                                                          final DOMDataTreeReadTransaction delegateTx) {
40         this.delegateTx = checkNotNull(delegateTx);
41         this.txIdentifier = checkNotNull(txIdentifier);
42     }
43
44     @Override
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);
49     }
50
51     @Override
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);
57     }
58
59     @Override
60     public Object getIdentifier() {
61         return txIdentifier;
62     }
63
64     @Override
65     public void close() {
66         delegateTx.close();
67     }
68 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.