Change DOM invokeRpc to FluentFuture
[mdsal.git] / dom / mdsal-dom-broker / src / main / java / org / opendaylight / mdsal / dom / broker / GlobalDOMRpcRoutingTableEntry.java
1 /*
2  * Copyright (c) 2015 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.mdsal.dom.broker;
9
10 import com.google.common.base.Preconditions;
11 import com.google.common.util.concurrent.FluentFuture;
12 import java.util.List;
13 import java.util.Map;
14 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
15 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
16 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
20
21 final class GlobalDOMRpcRoutingTableEntry extends AbstractDOMRpcRoutingTableEntry {
22     private final DOMRpcIdentifier rpcId;
23
24     private GlobalDOMRpcRoutingTableEntry(final DOMRpcIdentifier rpcId, final Map<YangInstanceIdentifier,
25             List<DOMRpcImplementation>> impls) {
26         super(rpcId.getType(), impls);
27         this.rpcId = Preconditions.checkNotNull(rpcId);
28     }
29
30     // We do not need the RpcDefinition, but this makes sure we do not
31     // forward something we don't know to be an RPC.
32     GlobalDOMRpcRoutingTableEntry(final RpcDefinition def, final Map<YangInstanceIdentifier,
33             List<DOMRpcImplementation>> impls) {
34         super(def.getPath(), impls);
35         this.rpcId = DOMRpcIdentifier.create(def.getPath());
36     }
37
38     @Override
39     protected FluentFuture<DOMRpcResult> invokeRpc(final NormalizedNode<?, ?> input) {
40         return getImplementations(YangInstanceIdentifier.EMPTY).get(0).invokeRpc(rpcId, input);
41     }
42
43     @Override
44     protected GlobalDOMRpcRoutingTableEntry newInstance(final Map<YangInstanceIdentifier,
45             List<DOMRpcImplementation>> impls) {
46         return new GlobalDOMRpcRoutingTableEntry(rpcId, impls);
47     }
48 }