2 * Copyright (c) 2015 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.mdsal.binding.dom.adapter.invoke;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.annotations.VisibleForTesting;
14 import com.google.common.collect.ImmutableMap;
15 import com.google.common.collect.ImmutableMap.Builder;
16 import com.google.common.util.concurrent.ListenableFuture;
17 import java.lang.reflect.Method;
19 import java.util.Map.Entry;
20 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
21 import org.opendaylight.yangtools.yang.binding.DataObject;
22 import org.opendaylight.yangtools.yang.binding.RpcService;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.common.RpcResult;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 @Deprecated(since = "11.0.0", forRemoval = true)
29 abstract class AbstractMappedRpcInvoker<T> extends RpcServiceInvoker {
30 private static final Logger LOG = LoggerFactory.getLogger(AbstractMappedRpcInvoker.class);
33 final Map<T, RpcMethodInvoker> map;
35 protected AbstractMappedRpcInvoker(final Map<T, Method> map) {
36 final Builder<T, RpcMethodInvoker> b = ImmutableMap.builder();
38 for (Entry<T, Method> e : map.entrySet()) {
39 if (BindingReflections.isRpcMethod(e.getValue())) {
40 b.put(e.getKey(), RpcMethodInvoker.from(e.getValue()));
42 LOG.debug("Method {} is not an RPC method, ignoring it", e.getValue());
49 protected abstract T qnameToKey(QName qname);
52 public final ListenableFuture<RpcResult<?>> invokeRpc(final RpcService impl, final QName rpcName,
53 final DataObject input) {
54 requireNonNull(impl, "Implementation must be supplied");
56 RpcMethodInvoker invoker = map.get(qnameToKey(rpcName));
57 checkArgument(invoker != null, "Supplied RPC is not valid for implementation %s", impl);
58 return invoker.invokeOn(impl, input);