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