Use YangInstanceIdentifier.EMPTY
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / md / sal / dom / broker / impl / 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.controller.md.sal.dom.broker.impl;
9
10 import com.google.common.base.Preconditions;
11 import com.google.common.util.concurrent.CheckedFuture;
12 import java.util.List;
13 import java.util.Map;
14 import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
15 import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier;
16 import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementation;
17 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
21
22 final class GlobalDOMRpcRoutingTableEntry extends AbstractDOMRpcRoutingTableEntry {
23     private final DOMRpcIdentifier rpcId;
24
25     private GlobalDOMRpcRoutingTableEntry(final DOMRpcIdentifier rpcId, final Map<YangInstanceIdentifier, 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, List<DOMRpcImplementation>> impls) {
33         super(def.getPath(), impls);
34         this.rpcId = DOMRpcIdentifier.create(def.getPath());
35     }
36
37     @Override
38     protected CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final NormalizedNode<?, ?> input) {
39         return getImplementations(YangInstanceIdentifier.EMPTY).get(0).invokeRpc(rpcId, input);
40     }
41
42     @Override
43     protected GlobalDOMRpcRoutingTableEntry newInstance(final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> impls) {
44         return new GlobalDOMRpcRoutingTableEntry(rpcId, impls);
45     }
46 }