/*
- * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
*/
package org.opendaylight.mdsal.binding.dom.adapter.invoke;
-import static java.util.Objects.requireNonNull;
+import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.annotations.Beta;
import com.google.common.util.concurrent.ListenableFuture;
import java.lang.reflect.Method;
import java.util.Map;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.RpcService;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
- * Invocation strategy for RPCs. This class is visible for migration purposes only.
+ * Provides single method invocation of RPCs on supplied instance.
+ *
+ * <p>
+ * RPC Service invoker provides common invocation interface for any subtype of {@link RpcService} via
+ * {@link #invokeRpc(RpcService, QName, DataObject)} method.
*/
-@Beta
-public final class RpcServiceInvoker {
- private final org.opendaylight.yangtools.yang.binding.util.RpcServiceInvoker delegate;
-
- private RpcServiceInvoker(final org.opendaylight.yangtools.yang.binding.util.RpcServiceInvoker delegate) {
- this.delegate = requireNonNull(delegate);
- }
+public abstract class RpcServiceInvoker {
+ private static final Logger LOG = LoggerFactory.getLogger(RpcServiceInvoker.class);
/**
* Creates an RPCServiceInvoker for specified QName-<Method mapping.
* @return An {@link RpcServiceInvoker} instance.
*/
public static RpcServiceInvoker from(final Map<QName, Method> qnameToMethod) {
- return new RpcServiceInvoker(
- org.opendaylight.yangtools.yang.binding.util.RpcServiceInvoker.from(qnameToMethod));
+ checkArgument(!qnameToMethod.isEmpty());
+ QNameModule module = null;
+
+ for (QName qname : qnameToMethod.keySet()) {
+ if (module != null) {
+ if (!module.equals(qname.getModule())) {
+ LOG.debug("QNames from different modules {} and {}, falling back to QName map", module,
+ qname.getModule());
+ return QNameRpcServiceInvoker.instanceFor(qnameToMethod);
+ }
+ } else {
+ module = qname.getModule();
+ }
+ }
+
+ // All module are equal, which means we can use localName only
+ return LocalNameRpcServiceInvoker.instanceFor(module, qnameToMethod);
}
/**
* Invokes supplied RPC on provided implementation of RPC Service.
*
- * @param impl Implementation on which RPC should be invoked.
+ * @param impl Imlementation on which RPC should be invoked.
* @param rpcName Name of RPC to be invoked.
* @param input Input data for RPC.
- * @return Future which will complete once rpc processing is finished.
+ * @return Future which will complete once rpc procesing is finished.
*/
- public ListenableFuture<RpcResult<?>> invokeRpc(@Nonnull final RpcService impl, @Nonnull final QName rpcName,
- @Nullable final DataObject input) {
- return delegate.invokeRpc(impl, rpcName, input);
- }
+ public abstract ListenableFuture<RpcResult<?>> invokeRpc(@NonNull RpcService impl, @NonNull QName rpcName,
+ @Nullable DataObject input);
}