2 * Copyright (c) 2013 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;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import java.lang.reflect.Method;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.binding.RpcService;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.common.QNameModule;
21 import org.opendaylight.yangtools.yang.common.RpcResult;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Provides single method invocation of RPCs on supplied instance.
29 * RPC Service invoker provides common invocation interface for any subtype of {@link RpcService} via
30 * {@link #invokeRpc(RpcService, QName, DataObject)} method.
32 public abstract class RpcServiceInvoker {
33 private static final Logger LOG = LoggerFactory.getLogger(RpcServiceInvoker.class);
36 * Creates an RPCServiceInvoker for specified QName-<Method mapping.
38 * @param qnameToMethod translation mapping, must not be null nor empty.
39 * @return An {@link RpcServiceInvoker} instance.
41 public static RpcServiceInvoker from(final Map<QName, Method> qnameToMethod) {
42 checkArgument(!qnameToMethod.isEmpty());
43 QNameModule module = null;
45 for (QName qname : qnameToMethod.keySet()) {
47 if (!module.equals(qname.getModule())) {
48 LOG.debug("QNames from different modules {} and {}, falling back to QName map", module,
50 return QNameRpcServiceInvoker.instanceFor(qnameToMethod);
53 module = qname.getModule();
57 // All module are equal, which means we can use localName only
58 return LocalNameRpcServiceInvoker.instanceFor(module, qnameToMethod);
62 * Invokes supplied RPC on provided implementation of RPC Service.
64 * @param impl Imlementation on which RPC should be invoked.
65 * @param rpcName Name of RPC to be invoked.
66 * @param input Input data for RPC.
67 * @return Future which will complete once rpc procesing is finished.
69 public abstract ListenableFuture<RpcResult<?>> invokeRpc(@NonNull RpcService impl, @NonNull QName rpcName,
70 @Nullable DataObject input);