2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.javav2.dom.adapter.impl.operation.invoker;
10 import com.google.common.annotations.Beta;
11 import com.google.common.base.Preconditions;
12 import java.lang.reflect.Method;
14 import java.util.concurrent.Future;
15 import javax.annotation.Nonnull;
16 import javax.annotation.Nullable;
17 import org.opendaylight.mdsal.binding.javav2.spec.base.Instantiable;
18 import org.opendaylight.mdsal.binding.javav2.spec.base.Operation;
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 operations on supplied instance.
29 * Operation Service invoker provides common invocation interface for any subtype of operation. via
30 * {@link #invoke(Operation, QName, Instantiable)} method.
33 public abstract class OperationServiceInvoker {
35 private static final Logger LOG = LoggerFactory.getLogger(OperationServiceInvoker.class);
38 * Creates OperationServiceInvoker for specified operation type.
41 * operation interface, which was generated from model.
42 * @return Cached instance of {@link OperationServiceInvoker} for supplied operation type.
45 public static OperationServiceInvoker from(final Class<? extends Operation> type) {
46 return ClassBasedOperationServiceInvoker.instanceFor(type);
50 * Creates an OperationServiceInvoker for specified QName-<Method mapping.
52 * @param qnameToMethod
53 * translation mapping, must not be null nor empty.
54 * @return An {@link OperationMethodInvoker} instance.
56 public static OperationServiceInvoker from(final Map<QName, Method> qnameToMethod) {
57 Preconditions.checkArgument(!qnameToMethod.isEmpty());
58 QNameModule module = null;
60 for (final QName qname : qnameToMethod.keySet()) {
62 if (!module.equals(qname.getModule())) {
63 LOG.debug("QNames from different modules {} and {}, falling back to QName map", module,
65 return QNameOperationServiceInvoker.instanceFor(qnameToMethod);
68 module = qname.getModule();
72 // All module are equal, which means we can use localName only
73 return LocalNameOperationServiceInvoker.instanceFor(module, qnameToMethod);
77 * Invokes supplied operation on provided implementation of Operation Service.
82 * Implementation on which operation should be invoked.
83 * @param operationName
84 * Name of operation to be invoked.
86 * Input data for operation.
87 * @return Future which will complete once operation processing is finished.
89 public abstract <T extends Operation> Future<RpcResult<?>> invoke(@Nonnull T impl, @Nonnull QName operationName,
90 @Nullable Instantiable<?> input);