Remove yang.binding.RpcService 96/108696/10
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 26 Oct 2023 22:35:19 +0000 (00:35 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 14 Nov 2023 10:58:39 +0000 (11:58 +0100)
RpcService is a base marker for generated interfaces representing
the collection of 'rpc' statements in a module.

This interface and its uses have been deprecated, as their design
assumptions are based on Java 7, that is do not consider lambdas.

Since we have yang.binding.Rpc and related interfaces to cleanly
represent RPCs in lambda-cognizant world, remove RpcService and all its
related codegen/runtime support.

JIRA: MDSAL-772
Change-Id: I41b3c6513869a43b6373ad588336ebed2dc873d4
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
39 files changed:
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/RpcConsumerRegistry.java
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/RpcProviderService.java
binding/mdsal-binding-dom-adapter/src/main/java/module-info.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/AbstractDOMRpcImplementationAdapter.java [deleted file]
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/AbstractRpcAdapter.java [deleted file]
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcAdapterRegistration.java [deleted file]
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcImplementationAdapter.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcProviderServiceAdapter.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcServiceAdapter.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingRpcAdapterRegistration.java [deleted file]
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/CurrentAdapterSerializer.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/LegacyDOMRpcImplementationAdapter.java [deleted file]
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/RpcAdapter.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/RpcInvocationStrategy.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/RpcServiceAdapter.java [deleted file]
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/StaticConfiguration.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/OSGiRpcConsumerRegistry.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/OSGiRpcProviderService.java
binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcAdapterRegistrationTest.java [deleted file]
binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcIntegrationTest.java
binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/BindingNormalizedCodecTest.java [deleted file]
binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/BindingRpcAdapterRegistrationTest.java [deleted file]
binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/Mdsal500Test.java
binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/Mdsal739Test.java
binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/RpcServiceAdapterTest.java [deleted file]
binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/reactor/AbstractCompositeGenerator.java
binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/reactor/RpcServiceGenerator.java [deleted file]
binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/reactor/StatementNamespace.java
binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/generator/impl/GeneratedTypesTest.java
binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal302Test.java
binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal500Test.java
binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal552Test.java
binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal666Test.java
binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal810Test.java
binding/mdsal-binding-model-ri/src/main/java/org/opendaylight/mdsal/binding/model/ri/BindingTypes.java
binding/mdsal-binding-model-ri/src/test/java/org/opendaylight/mdsal/binding/model/ri/BindingTypesTest.java
binding/mdsal-binding-spec-util/src/test/java/org/opendaylight/mdsal/binding/spec/reflect/BindingReflectionsTest.java
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/RpcService.java [deleted file]
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/contract/Naming.java

index 8dca81db9d561d66eff646464eabd170b62341a5..bf0f1e296e17e637e3eb5697fcdc1f1a5159f02f 100644 (file)
@@ -9,68 +9,12 @@ package org.opendaylight.mdsal.binding.api;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.binding.Rpc;
-import org.opendaylight.yangtools.yang.binding.RpcService;
 
 /**
  * Provides access to registered Remote Procedure Call (RPC) service implementations. The RPCs are defined in YANG
  * models. {@link RpcProviderService} is this inferface's counterpart allowing registering RPC implementations.
  */
 public interface RpcConsumerRegistry extends BindingService {
-    /**
-     * Returns an implementation of a requested RPC service.
-     *
-     * <p>
-     * The returned instance is not an actual implementation of the RPC service interface, but a proxy implementation of
-     * the interface that forwards to an actual implementation, if any.
-     *
-     * <p>
-     * The following describes the behavior of the proxy when invoking RPC methods:
-     * <ul>
-     *   <li>If an actual implementation is registered with the MD-SAL, all invocations are forwarded to the registered
-     *       implementation.</li>
-     *   <li>If no actual implementation is registered, all invocations will fail by throwing
-     *       {@link IllegalStateException}.</li>
-     *   <li>Prior to invoking the actual implementation, the method arguments are are validated. If any are invalid, an
-     *       {@link IllegalArgumentException} is thrown.</li>
-     * </ul>
-     * The returned proxy is automatically updated with the most recent registered implementation.
-     *
-     * <p>
-     * The generated RPC method APIs require implementors to return a
-     * {@link java.util.concurrent.Future Future} instance that wraps the
-     * {@link org.opendaylight.yangtools.yang.common.RpcResult RpcResult}. Since RPC methods may be
-     * implemented asynchronously, callers should avoid blocking on the
-     * {@link java.util.concurrent.Future Future} result. Instead, it is recommended to use
-     * {@link com.google.common.util.concurrent.JdkFutureAdapters#listenInPoolThread(java.util.concurrent.Future)}
-     * or
-     * {@link com.google.common.util.concurrent.JdkFutureAdapters#listenInPoolThread(java.util.concurrent.Future,
-     * java.util.concurrent.Executor)} to listen for Rpc Result. This will asynchronously listen for future result
-     * in executor and will not block current thread.
-     *
-     * <pre>
-     *   final Future&lt;RpcResult&lt;SomeRpcOutput&gt;&gt; future = someRpcService.someRpc( ... );
-     *   Futures.addCallback(JdkFutureAdapters.listenInThreadPool(future), new FutureCallback&lt;RpcResult&lt;
-     *   SomeRpcOutput&gt;&gt;() {
-     *
-     *       public void onSuccess(RpcResult&lt;SomeRpcOutput&gt; result) {
-     *          // process result ...
-     *       }
-     *
-     *       public void onFailure(Throwable t) {
-     *          // RPC failed
-     *       }
-     *   );
-     * </pre>
-     *
-     * @param <S> {@link RpcService} type
-     * @param serviceInterface the interface of the RPC Service. Typically this is an interface
-     *        generated from a YANG model.
-     * @return the proxy for the requested RPC service. This method never returns null.
-     * @deprecated Use {@link #getRpc(Class)} instead.
-     */
-    @Deprecated(since = "11.0.0", forRemoval = true)
-    <S extends RpcService> @NonNull S getRpcService(@NonNull Class<S> serviceInterface);
-
     /**
      * Returns an implementation of a requested RPC service.
      *
index 8108a14c622fb0bb15e29874bfd9ef6545cf03d4..8de4f78950c2c3c4678c4c2171fae345676afe7b 100644 (file)
@@ -10,50 +10,15 @@ package org.opendaylight.mdsal.binding.api;
 import com.google.common.collect.ClassToInstanceMap;
 import java.util.Set;
 import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.Rpc;
-import org.opendaylight.yangtools.yang.binding.RpcService;
 
 /**
  * Provides ability to registered Remote Procedure Call (RPC) service implementations. The RPCs are defined in YANG
  * models.
  */
 public interface RpcProviderService extends BindingService {
-    /**
-     * Register RPCs combined in a {@link RpcService} interface.
-     *
-     * @param <R> {@link RpcService} type
-     * @param <I> {@link RpcService} implementation type
-     * @param type {@link RpcService} class
-     * @param implementation implementation object
-     * @return An {@link ObjectRegistration} controlling unregistration
-     * @throws NullPointerException if any argument is {@code null}
-     * @deprecated Use {@link #registerRpcImplementation(Rpc)} or
-     *             {@link #registerRpcImplementations(ClassToInstanceMap)} instead.
-     */
-    @Deprecated(since = "11.0.0", forRemoval = true)
-    <R extends RpcService, I extends R> @NonNull ObjectRegistration<I> registerRpcImplementation(Class<R> type,
-        I implementation);
-
-    /**
-     * Register RPCs combined in a {@link RpcService} interface on a set of datastore context paths.
-     *
-     * @param <R> {@link RpcService} type
-     * @param <I> {@link RpcService} implementation type
-     * @param type {@link RpcService} class
-     * @param implementation implementation object
-     * @param paths Datastore paths to service
-     * @return An {@link ObjectRegistration} controlling unregistration
-     * @throws NullPointerException if any argument is {@code null}
-     * @deprecated Use {@link #registerRpcImplementation(Rpc, Set)} or
-     *             {@link #registerRpcImplementations(ClassToInstanceMap, Set)} instead.
-     */
-    @Deprecated(since = "11.0.0", forRemoval = true)
-    <R extends RpcService, I extends R> @NonNull ObjectRegistration<I> registerRpcImplementation(Class<R> type,
-        I implementation, Set<InstanceIdentifier<?>> paths);
-
     /**
      * Register an {@link Rpc} implementation.
      *
index 7856a49496a8f0436338b274e210ce47b712f443..40bca155a9ca0c57fb092e8bd43248323c9b8821 100644 (file)
@@ -5,6 +5,7 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
+import org.opendaylight.mdsal.binding.api.query.QueryFactory;
 import org.opendaylight.mdsal.binding.dom.adapter.AdapterContext;
 import org.opendaylight.mdsal.binding.dom.adapter.BindingAdapterFactory;
 import org.opendaylight.mdsal.binding.dom.adapter.ConstantAdapterContext;
@@ -12,7 +13,6 @@ import org.opendaylight.mdsal.binding.dom.adapter.query.DefaultQueryFactory;
 import org.opendaylight.mdsal.binding.dom.adapter.spi.AdapterFactory;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
 import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecFactory;
-import org.opendaylight.mdsal.binding.api.query.QueryFactory;
 
 module org.opendaylight.mdsal.binding.dom.adapter {
     exports org.opendaylight.mdsal.binding.dom.adapter;
diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/AbstractDOMRpcImplementationAdapter.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/AbstractDOMRpcImplementationAdapter.java
deleted file mode 100644 (file)
index 9fc1ad1..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.adapter;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Verify.verifyNotNull;
-import static java.util.Objects.requireNonNull;
-import static org.opendaylight.mdsal.binding.dom.adapter.StaticConfiguration.ENABLE_CODEC_SHORTCUT;
-
-import com.google.common.util.concurrent.ListenableFuture;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.mdsal.binding.dom.codec.api.BindingLazyContainerNode;
-import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
-import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
-import org.opendaylight.mdsal.dom.api.DOMRpcResult;
-import org.opendaylight.yangtools.yang.binding.RpcInput;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.YangConstants;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
-
-abstract sealed class AbstractDOMRpcImplementationAdapter implements DOMRpcImplementation
-        permits BindingDOMRpcImplementationAdapter, LegacyDOMRpcImplementationAdapter {
-    private final AdapterContext adapterContext;
-    private final @NonNull QName inputName;
-    private final @NonNull QName rpcName;
-
-    AbstractDOMRpcImplementationAdapter(final AdapterContext adapterContext, final QName rpcName) {
-        this.adapterContext = requireNonNull(adapterContext);
-        this.rpcName = requireNonNull(rpcName);
-        inputName = YangConstants.operationInputQName(rpcName.getModule()).intern();
-    }
-
-    @Override
-    public final long invocationCost() {
-        // Default implementations are 0, we need to perform some translation, hence we have a slightly higher cost
-        return 1;
-    }
-
-    @Override
-    public final ListenableFuture<DOMRpcResult> invokeRpc(final DOMRpcIdentifier rpc, final ContainerNode input) {
-        final var serializer = adapterContext.currentSerializer();
-        return LazyDOMRpcResultFuture.create(serializer, invokeRpc(deserialize(serializer, input)));
-    }
-
-    abstract @NonNull ListenableFuture<RpcResult<?>> invokeRpc(@NonNull RpcInput input);
-
-    private @NonNull RpcInput deserialize(final @NonNull CurrentAdapterSerializer serializer,
-            final @NonNull ContainerNode input) {
-        if (ENABLE_CODEC_SHORTCUT && input instanceof BindingLazyContainerNode<?> lazy) {
-            return (RpcInput) lazy.getDataObject();
-        }
-
-        checkArgument(inputName.equals(input.name().getNodeType()),
-            "Unexpected RPC %s input %s", rpcName, input);
-
-        // TODO: this is a bit inefficient: typically we get the same CurrentAdapterSerializer and the path is also
-        //       constant, hence we should be able to cache this lookup and just have the appropriate
-        //       BindingDataObjectCodecTreeNode and reuse it directly
-        // FIXME: should be a guaranteed return, as innput is @NonNull
-        return verifyNotNull((RpcInput) serializer.fromNormalizedNodeRpcData(Absolute.of(rpcName, inputName), input));
-    }
-}
diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/AbstractRpcAdapter.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/AbstractRpcAdapter.java
deleted file mode 100644 (file)
index 26cff28..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.adapter;
-
-import static java.util.Objects.requireNonNull;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.mdsal.binding.dom.adapter.RpcInvocationStrategy.ContentRouted;
-import org.opendaylight.mdsal.binding.runtime.api.RpcRuntimeType;
-import org.opendaylight.mdsal.dom.api.DOMRpcService;
-import org.opendaylight.mdsal.dom.spi.ContentRoutedRpcContext;
-
-abstract sealed class AbstractRpcAdapter implements InvocationHandler permits RpcAdapter, RpcServiceAdapter {
-    private final @NonNull DOMRpcService delegate;
-    private final @NonNull AdapterContext adapterContext;
-    private final @NonNull Object facade;
-    private final String name;
-
-    AbstractRpcAdapter(final AdapterContext adapterContext, final DOMRpcService delegate, final Class<?> type) {
-        this.adapterContext = requireNonNull(adapterContext);
-        this.delegate = requireNonNull(delegate);
-        facade = Proxy.newProxyInstance(type.getClassLoader(), new Class<?>[] { type }, this);
-        name = type.getName();
-    }
-
-    final @NonNull CurrentAdapterSerializer currentSerializer() {
-        return adapterContext.currentSerializer();
-    }
-
-    final @NonNull DOMRpcService delegate() {
-        return delegate;
-    }
-
-    final @NonNull Object facade() {
-        return facade;
-    }
-
-    final @NonNull RpcInvocationStrategy createStrategy(final CurrentAdapterSerializer serializer,
-            final RpcRuntimeType rpcType) {
-        final var rpc = rpcType.statement();
-        final var contentContext = ContentRoutedRpcContext.forRpc(rpc);
-        if (contentContext != null) {
-            final var extractor = serializer.findExtractor(rpcType.input());
-            if (extractor != null) {
-                return new ContentRouted(this, rpc.argument(), contentContext.leaf(), extractor);
-            }
-        }
-        return new RpcInvocationStrategy(this, rpc.argument());
-    }
-
-    @SuppressWarnings("checkstyle:illegalThrows")
-    final Object defaultInvoke(final Object proxy, final Method method, final Object [] args) throws Throwable {
-        switch (method.getName()) {
-            case "toString":
-                if (method.getReturnType().equals(String.class) && method.getParameterCount() == 0) {
-                    return name + "$Adapter{delegate=" + delegate() + "}";
-                }
-                break;
-            case "hashCode":
-                if (method.getReturnType().equals(int.class) && method.getParameterCount() == 0) {
-                    return System.identityHashCode(proxy);
-                }
-                break;
-            case "equals":
-                if (method.getReturnType().equals(boolean.class) && method.getParameterCount() == 1
-                        && method.getParameterTypes()[0] == Object.class) {
-                    return proxy == args[0];
-                }
-                break;
-            default:
-                break;
-        }
-
-        if (method.isDefault()) {
-            return InvocationHandler.invokeDefault(proxy, method, args);
-        }
-        throw new UnsupportedOperationException("Method " + method.toString() + " is not supported");
-    }
-}
\ No newline at end of file
diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcAdapterRegistration.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcAdapterRegistration.java
deleted file mode 100644 (file)
index 973d766..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2014 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.adapter;
-
-import org.opendaylight.mdsal.dom.api.DOMRpcImplementationRegistration;
-import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
-import org.opendaylight.yangtools.yang.binding.RpcService;
-
-@Deprecated(since = "11.0.0", forRemoval = true)
-class BindingDOMRpcAdapterRegistration<T extends RpcService> extends AbstractObjectRegistration<T> {
-    private final DOMRpcImplementationRegistration<?> reg;
-
-    BindingDOMRpcAdapterRegistration(T instance, DOMRpcImplementationRegistration<?> reg) {
-        super(instance);
-        this.reg = reg;
-    }
-
-    @Override
-    protected void removeRegistration() {
-        reg.close();
-    }
-}
index 63f0b7d73132ff6e5f0c111f7d612ae0e26ddd60..5e995dc6ca01d15acb73581804dc1a5a7d17c874 100644 (file)
@@ -7,28 +7,64 @@
  */
 package org.opendaylight.mdsal.binding.dom.adapter;
 
+import static com.google.common.base.Verify.verifyNotNull;
 import static java.util.Objects.requireNonNull;
+import static org.opendaylight.mdsal.binding.dom.adapter.StaticConfiguration.ENABLE_CODEC_SHORTCUT;
 
 import com.google.common.util.concurrent.ListenableFuture;
 import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingLazyContainerNode;
+import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
+import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
+import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.yangtools.yang.binding.Rpc;
 import org.opendaylight.yangtools.yang.binding.RpcInput;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
 
-final class BindingDOMRpcImplementationAdapter extends AbstractDOMRpcImplementationAdapter {
+final class BindingDOMRpcImplementationAdapter implements DOMRpcImplementation {
+    private final @NonNull AdapterContext adapterContext;
+    private final @NonNull QName rpcName;
     @SuppressWarnings("rawtypes")
     private final @NonNull Rpc delegate;
 
     BindingDOMRpcImplementationAdapter(final AdapterContext adapterContext, final QName rpcName,
             final Rpc<?, ?> delegate) {
-        super(adapterContext, rpcName);
+        this.adapterContext = requireNonNull(adapterContext);
+        this.rpcName = requireNonNull(rpcName);
         this.delegate = requireNonNull(delegate);
     }
 
     @Override
-    @SuppressWarnings("unchecked")
-    ListenableFuture<RpcResult<?>> invokeRpc(final RpcInput input) {
-        return delegate.invoke(input);
+    public long invocationCost() {
+        // Default implementations are 0, we need to perform some translation, hence we have a slightly higher cost
+        return 1;
+    }
+
+    @Override
+    public ListenableFuture<DOMRpcResult> invokeRpc(final DOMRpcIdentifier rpc, final ContainerNode input) {
+        final var serializer = adapterContext.currentSerializer();
+        @SuppressWarnings("unchecked")
+        final var future = delegate.invoke(deserialize(serializer, input));
+        return LazyDOMRpcResultFuture.create(serializer, future);
+    }
+
+    private @NonNull RpcInput deserialize(final @NonNull CurrentAdapterSerializer serializer,
+            final @NonNull ContainerNode input) {
+        if (ENABLE_CODEC_SHORTCUT && input instanceof BindingLazyContainerNode<?> lazy) {
+            return (RpcInput) lazy.getDataObject();
+        }
+
+        final var inputName = input.name().getNodeType();
+        if (!"input".equals(inputName.getLocalName()) || !rpcName.getModule().equals(inputName.getModule())) {
+            throw new IllegalArgumentException("Unexpected RPC " + rpcName + " input " + input.prettyTree());
+        }
+
+        // TODO: this is a bit inefficient: typically we get the same CurrentAdapterSerializer and the path is also
+        //       constant, hence we should be able to cache this lookup and just have the appropriate
+        //       BindingDataObjectCodecTreeNode and reuse it directly
+        // FIXME: should be a guaranteed return, as input is @NonNull
+        return verifyNotNull((RpcInput) serializer.fromNormalizedNodeRpcData(Absolute.of(rpcName, inputName), input));
     }
 }
index b6fc9b99048d0c40143d53ff0732eb78e0874610..6a4c6e1c57c4705682025ad322ec0494b256b335 100644 (file)
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.mdsal.binding.dom.adapter;
 
-import static java.util.Objects.requireNonNull;
-
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ClassToInstanceMap;
 import com.google.common.collect.ImmutableClassToInstanceMap;
@@ -24,11 +22,9 @@ import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
 import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
-import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.Rpc;
-import org.opendaylight.yangtools.yang.binding.RpcService;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
@@ -42,21 +38,6 @@ public class BindingDOMRpcProviderServiceAdapter extends AbstractBindingAdapter<
         super(adapterContext, domRpcRegistry);
     }
 
-    @Override
-    @Deprecated
-    public <R extends RpcService, I extends R> ObjectRegistration<I> registerRpcImplementation(final Class<R> type,
-            final I implementation) {
-        return register(currentSerializer(), type, implementation, GLOBAL);
-    }
-
-    @Override
-    @Deprecated
-    public <R extends RpcService, I extends R> ObjectRegistration<I> registerRpcImplementation(final Class<R> type,
-            final I implementation, final Set<InstanceIdentifier<?>> paths) {
-        final var serializer = currentSerializer();
-        return register(serializer, type, implementation, toYangInstanceIdentifiers(serializer, paths));
-    }
-
     @Override
     public Registration registerRpcImplementation(final Rpc<?, ?> implementation) {
         return register(currentSerializer(), implementation, GLOBAL);
@@ -104,16 +85,6 @@ public class BindingDOMRpcProviderServiceAdapter extends AbstractBindingAdapter<
         });
     }
 
-    @Deprecated
-    private <S extends RpcService, T extends S> ObjectRegistration<T> register(
-            final CurrentAdapterSerializer serializer, final Class<S> type, final T implementation,
-            // Note: unique items are implied
-            final Collection<YangInstanceIdentifier> paths) {
-        return new BindingRpcAdapterRegistration<>(implementation, register(
-            serializer.getRpcMethods(requireNonNull(type)), paths, (rpcName, mh) -> new Impl(requireNonNull(rpcName),
-                new LegacyDOMRpcImplementationAdapter(adapterContext(), rpcName, mh.bindTo(implementation)))));
-    }
-
     private <K, V> @NonNull Registration register(final Map<K, V> map, final Collection<YangInstanceIdentifier> paths,
             final BiFunction<K, V, Impl> implFactory) {
         final var builder = ImmutableMap.<DOMRpcIdentifier, DOMRpcImplementation>builderWithExpectedSize(map.size());
index ed5af7ffeb2b68853b0566f6e4c3764852e96cfb..7266b38f96da895c4697b3106b5cc1481cc74ef9 100644 (file)
@@ -20,12 +20,10 @@ import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.api.DOMService;
 import org.opendaylight.yangtools.yang.binding.Rpc;
-import org.opendaylight.yangtools.yang.binding.RpcService;
 
 @VisibleForTesting
 public final class BindingDOMRpcServiceAdapter
-        extends AbstractBindingLoadingAdapter<DOMRpcService, Class<?>, AbstractRpcAdapter>
-        implements RpcConsumerRegistry {
+        extends AbstractBindingLoadingAdapter<DOMRpcService, Class<?>, RpcAdapter> implements RpcConsumerRegistry {
     static final Factory<RpcConsumerRegistry> BUILDER_FACTORY = Builder::new;
 
     public BindingDOMRpcServiceAdapter(final AdapterContext adapterContext, final DOMRpcService domService) {
@@ -38,19 +36,11 @@ public final class BindingDOMRpcServiceAdapter
     }
 
     @Override
-    @Deprecated
-    public <T extends RpcService> T getRpcService(final Class<T> rpcService) {
-        return rpcService.cast(getAdapter(requireNonNull(rpcService)).facade());
-    }
-
-    @Override
-    AbstractRpcAdapter loadAdapter(final Class<?> key) {
+    RpcAdapter loadAdapter(final Class<?> key) {
         checkArgument(BindingReflections.isBindingClass(key));
         checkArgument(key.isInterface(), "Supplied RPC service type must be interface.");
-        if (RpcService.class.isAssignableFrom(key)) {
-            return new RpcServiceAdapter(key.asSubclass(RpcService.class), adapterContext(), getDelegate());
-        } else if (Rpc.class.isAssignableFrom(key)) {
-            return new RpcAdapter<>(adapterContext(), getDelegate(), key.asSubclass(Rpc.class));
+        if (Rpc.class.isAssignableFrom(key)) {
+            return new RpcAdapter(adapterContext(), getDelegate(), key.asSubclass(Rpc.class));
         } else {
             throw new IllegalStateException("Unhandled key " + key);
         }
diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingRpcAdapterRegistration.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingRpcAdapterRegistration.java
deleted file mode 100644 (file)
index f4e7111..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2014 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.adapter;
-
-import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
-import org.opendaylight.yangtools.concepts.Registration;
-import org.opendaylight.yangtools.yang.binding.RpcService;
-
-@Deprecated(since = "11.0.0", forRemoval = true)
-class BindingRpcAdapterRegistration<T extends RpcService> extends AbstractObjectRegistration<T> {
-    private final Registration reg;
-
-    BindingRpcAdapterRegistration(final T instance, final Registration reg) {
-        super(instance);
-        this.reg = reg;
-    }
-
-    @Override
-    protected void removeRegistration() {
-        reg.close();
-    }
-}
index c5512ca321a7263ee6b81257cdf78a32ca012dd4..53c7720dd2f281bf95d32040d00744de31788ad2 100644 (file)
@@ -16,14 +16,6 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
-import com.google.common.collect.ImmutableBiMap;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-import com.google.common.util.concurrent.ListenableFuture;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
-import java.lang.reflect.Method;
 import java.util.Collection;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -43,10 +35,6 @@ import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.RpcInput;
-import org.opendaylight.yangtools.yang.binding.RpcService;
-import org.opendaylight.yangtools.yang.binding.contract.Naming;
-import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@@ -62,9 +50,6 @@ import org.slf4j.LoggerFactory;
 @VisibleForTesting
 public final class CurrentAdapterSerializer extends ForwardingBindingDOMCodecServices {
     private static final Logger LOG = LoggerFactory.getLogger(CurrentAdapterSerializer.class);
-    @Deprecated
-    private static final MethodType RPC_SERVICE_METHOD_SIGNATURE = MethodType.methodType(ListenableFuture.class,
-        RpcService.class, RpcInput.class);
 
     private final LoadingCache<InstanceIdentifier<?>, YangInstanceIdentifier> cache = CacheBuilder.newBuilder()
             .softValues().build(new CacheLoader<InstanceIdentifier<?>, YangInstanceIdentifier>() {
@@ -75,9 +60,6 @@ public final class CurrentAdapterSerializer extends ForwardingBindingDOMCodecSer
             });
 
     private final ConcurrentMap<JavaTypeName, ContextReferenceExtractor> extractors = new ConcurrentHashMap<>();
-    @Deprecated
-    private final ConcurrentMap<Class<? extends RpcService>, ImmutableMap<QName, MethodHandle>> rpcMethods =
-        new ConcurrentHashMap<>();
     private final @NonNull BindingDOMCodecServices delegate;
 
     public CurrentAdapterSerializer(final BindingDOMCodecServices delegate) {
@@ -148,48 +130,6 @@ public final class CurrentAdapterSerializer extends ForwardingBindingDOMCodecSer
         return raced != null ? raced : created;
     }
 
-    @Deprecated
-    @NonNull ImmutableMap<QName, MethodHandle> getRpcMethods(final @NonNull Class<? extends RpcService> serviceType) {
-        return rpcMethods.computeIfAbsent(serviceType, ignored -> {
-            final var lookup = MethodHandles.publicLookup();
-            return ImmutableMap.copyOf(Maps.transformValues(createQNameToMethod(serviceType), method -> {
-                final MethodHandle raw;
-                try {
-                    raw = lookup.unreflect(method);
-                } catch (IllegalAccessException e) {
-                    throw new IllegalStateException("Lookup on public method failed", e);
-                }
-                return raw.asType(RPC_SERVICE_METHOD_SIGNATURE);
-            }));
-        });
-    }
-
-    @Deprecated
-    @VisibleForTesting
-    // FIXME: This should be probably part of Binding Runtime context
-    ImmutableMap<QName, Method> createQNameToMethod(final Class<? extends RpcService> key) {
-        final var moduleName = BindingReflections.getQNameModule(key);
-        final var runtimeContext = getRuntimeContext();
-        final var module = runtimeContext.getEffectiveModelContext().findModule(moduleName).orElse(null);
-        if (module == null) {
-            LOG.trace("Schema for {} is not available; expected module name: {}; BindingRuntimeContext: {}",
-                key, moduleName, runtimeContext);
-            throw new IllegalStateException(String.format("Schema for %s is not available; expected module name: %s;"
-                + " full BindingRuntimeContext available in trace log", key, moduleName));
-        }
-
-        final var ret = ImmutableBiMap.<QName, Method>builder();
-        try {
-            for (var rpcDef : module.getRpcs()) {
-                final var rpcName = rpcDef.getQName();
-                ret.put(rpcName, key.getMethod(Naming.getRpcMethodName(rpcName), runtimeContext.getRpcInput(rpcName)));
-            }
-        } catch (NoSuchMethodException e) {
-            throw new IllegalStateException("Rpc defined in model does not have representation in generated class.", e);
-        }
-        return ret.build();
-    }
-
     private @NonNull Entry<SchemaInferenceStack, QNameModule> resolvePath(final @NonNull InstanceIdentifier<?> path) {
         final var stack = SchemaInferenceStack.of(getRuntimeContext().getEffectiveModelContext());
         final var it = toYangInstanceIdentifier(path).getPathArguments().iterator();
diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/LegacyDOMRpcImplementationAdapter.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/LegacyDOMRpcImplementationAdapter.java
deleted file mode 100644 (file)
index 5c1dadf..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2015 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.adapter;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.base.Throwables;
-import com.google.common.util.concurrent.ListenableFuture;
-import java.lang.invoke.MethodHandle;
-import org.opendaylight.yangtools.yang.binding.RpcInput;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-
-@Deprecated(since = "11.0.0", forRemoval = true)
-final class LegacyDOMRpcImplementationAdapter extends AbstractDOMRpcImplementationAdapter {
-    private final MethodHandle handle;
-
-    LegacyDOMRpcImplementationAdapter(final AdapterContext adapterContext, final QName rpcName,
-            final MethodHandle handle) {
-        super(adapterContext, rpcName);
-        this.handle = requireNonNull(handle);
-    }
-
-    @Override
-    @SuppressWarnings("checkstyle:illegalCatch")
-    ListenableFuture<RpcResult<?>> invokeRpc(final RpcInput input) {
-        try {
-            return (ListenableFuture<RpcResult<?>>) handle.invokeExact(input);
-        } catch (Throwable e) {
-            Throwables.throwIfUnchecked(e);
-            throw new IllegalStateException(e);
-        }
-    }
-}
index 186a50371e1f80e5a199632915b683e075e3ec4a..624d8ffe9a9eb8b7fbc4ddce7bc17025b25dbba9 100644 (file)
@@ -9,18 +9,30 @@ package org.opendaylight.mdsal.binding.dom.adapter;
 
 import static java.util.Objects.requireNonNull;
 
+import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.mdsal.binding.dom.adapter.RpcInvocationStrategy.ContentRouted;
+import org.opendaylight.mdsal.binding.runtime.api.RpcRuntimeType;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.mdsal.dom.spi.ContentRoutedRpcContext;
 import org.opendaylight.yangtools.yang.binding.Rpc;
 import org.opendaylight.yangtools.yang.binding.RpcInput;
 import org.opendaylight.yangtools.yang.binding.contract.Naming;
 
-final class RpcAdapter<T extends Rpc<?, ?>> extends AbstractRpcAdapter {
+final class RpcAdapter implements InvocationHandler {
+    private final @NonNull AdapterContext adapterContext;
+    private final @NonNull DOMRpcService delegate;
     private final RpcInvocationStrategy strategy;
+    private final @NonNull Rpc<?, ?> facade;
     private final Method invokeMethod;
+    private final String name;
 
-    RpcAdapter(final AdapterContext adapterContext, final DOMRpcService delegate, final Class<T> type) {
-        super(adapterContext, delegate, type);
+    <T extends Rpc<?, ?>> RpcAdapter(final AdapterContext adapterContext, final DOMRpcService delegate,
+            final Class<T> type) {
+        this.adapterContext = requireNonNull(adapterContext);
+        this.delegate = requireNonNull(delegate);
 
         final var serializer = adapterContext.currentSerializer();
         final var rpcType = serializer.getRuntimeContext().getRpcDefinition(type);
@@ -34,12 +46,67 @@ final class RpcAdapter<T extends Rpc<?, ?>> extends AbstractRpcAdapter {
             throw new IllegalStateException("Failed to find invoke method in " + type, e);
         }
 
+        facade = type.cast(Proxy.newProxyInstance(type.getClassLoader(), new Class<?>[] { type }, this));
+        name = type.getName();
+
         strategy = createStrategy(serializer, rpcType);
     }
 
+    private @NonNull RpcInvocationStrategy createStrategy(final CurrentAdapterSerializer serializer,
+            final RpcRuntimeType rpcType) {
+        final var rpc = rpcType.statement();
+        final var contentContext = ContentRoutedRpcContext.forRpc(rpc);
+        if (contentContext != null) {
+            final var extractor = serializer.findExtractor(rpcType.input());
+            if (extractor != null) {
+                return new ContentRouted(this, rpc.argument(), contentContext.leaf(), extractor);
+            }
+        }
+        return new RpcInvocationStrategy(this, rpc.argument());
+    }
+
     @Override
     public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
-        return invokeMethod.equals(method) ? strategy.invoke((RpcInput) requireNonNull(args[0]))
-            : defaultInvoke(proxy, method, args);
+        if (invokeMethod.equals(method)) {
+            return strategy.invoke((RpcInput) requireNonNull(args[0]));
+        }
+
+        switch (method.getName()) {
+            case "toString":
+                if (method.getReturnType().equals(String.class) && method.getParameterCount() == 0) {
+                    return name + "$Adapter{delegate=" + delegate + "}";
+                }
+                break;
+            case "hashCode":
+                if (method.getReturnType().equals(int.class) && method.getParameterCount() == 0) {
+                    return System.identityHashCode(proxy);
+                }
+                break;
+            case "equals":
+                if (method.getReturnType().equals(boolean.class) && method.getParameterCount() == 1
+                        && method.getParameterTypes()[0] == Object.class) {
+                    return proxy == args[0];
+                }
+                break;
+            default:
+                break;
+        }
+
+        if (method.isDefault()) {
+            return InvocationHandler.invokeDefault(proxy, method, args);
+        }
+        throw new UnsupportedOperationException("Method " + method.toString() + " is not supported");
+    }
+
+    @NonNull CurrentAdapterSerializer currentSerializer() {
+        return adapterContext.currentSerializer();
+    }
+
+    @NonNull DOMRpcService delegate() {
+        return delegate;
+    }
+
+    @NonNull Rpc<?, ?> facade() {
+        return facade;
     }
 }
index 8e5d1b344ed43f536e10392598ee4302844a5fab..57280bb44b69b7eed4167a8e5de1e05db6874e02 100644 (file)
@@ -31,7 +31,7 @@ sealed class RpcInvocationStrategy {
         private final ContextReferenceExtractor refExtractor;
         private final NodeIdentifier contextName;
 
-        ContentRouted(final AbstractRpcAdapter adapter, final QName rpcName, final QName leafName,
+        ContentRouted(final RpcAdapter adapter, final QName rpcName, final QName leafName,
                 final ContextReferenceExtractor refExtractor) {
             super(adapter, rpcName);
             contextName = NodeIdentifier.create(leafName);
@@ -52,11 +52,11 @@ sealed class RpcInvocationStrategy {
         }
     }
 
-    private final @NonNull AbstractRpcAdapter adapter;
+    private final @NonNull RpcAdapter adapter;
     private final @NonNull NodeIdentifier inputIdentifier;
     private final @NonNull Absolute outputPath;
 
-    RpcInvocationStrategy(final AbstractRpcAdapter adapter, final QName rpcName) {
+    RpcInvocationStrategy(final RpcAdapter adapter, final QName rpcName) {
         this.adapter = requireNonNull(adapter);
         final var namespace = rpcName.getModule();
         outputPath = Absolute.of(rpcName, YangConstants.operationOutputQName(namespace).intern()).intern();
diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/RpcServiceAdapter.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/RpcServiceAdapter.java
deleted file mode 100644 (file)
index 0659d4f..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 2015 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.adapter;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.collect.ImmutableMap;
-import java.lang.reflect.Method;
-import java.util.Map;
-import java.util.Map.Entry;
-import org.opendaylight.mdsal.binding.runtime.api.RpcRuntimeType;
-import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
-import org.opendaylight.mdsal.dom.api.DOMRpcService;
-import org.opendaylight.yangtools.yang.binding.RpcInput;
-import org.opendaylight.yangtools.yang.binding.RpcService;
-import org.opendaylight.yangtools.yang.binding.contract.Naming;
-import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
-
-@Deprecated
-final class RpcServiceAdapter extends AbstractRpcAdapter {
-    private final ImmutableMap<Method, RpcInvocationStrategy> rpcNames;
-
-    RpcServiceAdapter(final Class<? extends RpcService> type, final AdapterContext adapterContext,
-            final DOMRpcService domService) {
-        super(adapterContext, domService, type);
-
-        // FIXME: This should be probably part of BindingRuntimeContext and RpcServices perhaps should have their own
-        //        RuntimeType. At any rate, we are dancing around to reconstruct information RpcServiceRuntimeType would
-        //        carry and the runtime context would bind to actual classes.
-        final var serializer = adapterContext.currentSerializer();
-        final var runtimeContext = serializer.getRuntimeContext();
-        final var types = runtimeContext.getTypes();
-        final var qnameModule = BindingReflections.getQNameModule(type);
-
-        // We are dancing a bit here to reconstruct things a RpcServiceRuntimeType could easily hold
-        final var module = runtimeContext.getEffectiveModelContext().findModuleStatement(qnameModule)
-            .orElseThrow(() -> new IllegalStateException("No module found for " + qnameModule + " service " + type));
-        rpcNames = module.streamEffectiveSubstatements(RpcEffectiveStatement.class)
-            .map(rpc -> {
-                final var rpcName = rpc.argument();
-                final var inputClz = runtimeContext.getRpcInput(rpcName);
-                final var methodName = Naming.getRpcMethodName(rpcName);
-
-                final Method method;
-                try {
-                    method = type.getMethod(methodName, inputClz);
-                } catch (NoSuchMethodException e) {
-                    throw new IllegalStateException("Cannot find RPC method for " + rpc, e);
-                }
-
-                final var runtimeType = types.schemaTreeChild(rpcName);
-                if (!(runtimeType instanceof RpcRuntimeType rpcType)) {
-                    throw new IllegalStateException("Unexpected run-time type " + runtimeType + " for " + rpcName);
-                }
-
-                return Map.entry(method, createStrategy(serializer, rpcType));
-            })
-            .collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue));
-    }
-
-    @Override
-    public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
-        final var strategy = rpcNames.get(method);
-        return strategy != null ? strategy.invoke((RpcInput) requireNonNull(args[0]))
-            : defaultInvoke(proxy, method, args);
-    }
-}
index f2c006f4c92176d0c5ef10c681c5352468afc4cc..ef7ada52be26201a16ddb816f70a88845ed7e9fe 100644 (file)
@@ -11,7 +11,6 @@ import com.google.common.annotations.Beta;
 import java.util.Map;
 import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
 import org.opendaylight.yangtools.yang.binding.Rpc;
-import org.opendaylight.yangtools.yang.binding.RpcService;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Deactivate;
@@ -32,12 +31,6 @@ public final class OSGiRpcConsumerRegistry extends AbstractAdaptedService<RpcCon
         return delegate().getRpc(rpcInterface);
     }
 
-    @Override
-    @Deprecated
-    public <T extends RpcService> T getRpcService(final Class<T> serviceInterface) {
-        return delegate().getRpcService(serviceInterface);
-    }
-
     @Activate
     void activate(final Map<String, ?> properties) {
         start(properties);
index d1f6880944c070afa7d5c0653b36208a61ee49ba..932968b0020074b1a0620812d26055ec20173a6d 100644 (file)
@@ -12,11 +12,9 @@ import com.google.common.collect.ClassToInstanceMap;
 import java.util.Map;
 import java.util.Set;
 import org.opendaylight.mdsal.binding.api.RpcProviderService;
-import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.Rpc;
-import org.opendaylight.yangtools.yang.binding.RpcService;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Deactivate;
@@ -32,20 +30,6 @@ public final class OSGiRpcProviderService extends AbstractAdaptedService<RpcProv
         super(RpcProviderService.class);
     }
 
-    @Override
-    @Deprecated
-    public <R extends RpcService, I extends R> ObjectRegistration<I> registerRpcImplementation(final Class<R> type,
-            final I implementation) {
-        return delegate().registerRpcImplementation(type, implementation);
-    }
-
-    @Override
-    @Deprecated
-    public <R extends RpcService, I extends R> ObjectRegistration<I> registerRpcImplementation(final Class<R> type,
-            final I implementation, final Set<InstanceIdentifier<?>> paths) {
-        return delegate().registerRpcImplementation(type, implementation, paths);
-    }
-
     @Override
     public Registration registerRpcImplementation(final Rpc<?, ?> implementation) {
         return delegate().registerRpcImplementation(implementation);
diff --git a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcAdapterRegistrationTest.java b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcAdapterRegistrationTest.java
deleted file mode 100644 (file)
index 05b5ef2..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2016 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.adapter;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-import org.junit.Test;
-import org.opendaylight.mdsal.dom.api.DOMRpcImplementationRegistration;
-import org.opendaylight.yangtools.yang.binding.RpcService;
-
-@Deprecated(since = "11.0.0", forRemoval = true)
-public class BindingDOMRpcAdapterRegistrationTest {
-    @Test
-    public void removeRegistration() {
-        final DOMRpcImplementationRegistration<?> registration = mock(DOMRpcImplementationRegistration.class);
-        final BindingDOMRpcAdapterRegistration<?> adapterReg =
-                new BindingDOMRpcAdapterRegistration<>(mock(RpcService.class), registration);
-        adapterReg.close();
-        verify(registration).close();
-    }
-}
\ No newline at end of file
index 21959b833c101189b84a5d9c114caf000cf30d54..334ef79f5b25258ae0f481dad04fd8b7c7d06dd1 100644 (file)
@@ -19,7 +19,6 @@ import com.google.common.collect.Multimap;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
-import java.util.concurrent.Future;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
@@ -29,7 +28,6 @@ import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingTestContext;
 import org.opendaylight.mdsal.binding.runtime.spi.BindingRuntimeHelpers;
 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
 import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
-import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.knock.knock.rev180723.KnockKnock;
@@ -37,11 +35,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.k
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.knock.knock.rev180723.KnockKnockInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.knock.knock.rev180723.KnockKnockOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.knock.knock.rev180723.KnockKnockOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.knock.knock.rev180723.OpendaylightKnockKnockRpcService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListKey;
-import org.opendaylight.yangtools.concepts.ObjectRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -60,7 +57,7 @@ public class BindingDOMRpcIntegrationTest {
     private DOMRpcProviderService biRpcProviderService;
     private BindingTestContext testContext;
     private DOMRpcService biRpcService;
-    private final OpendaylightKnockKnockRpcServiceImpl knockRpcImpl = new OpendaylightKnockKnockRpcServiceImpl();
+    private final KnockKnockImpl knockRpcImpl = new KnockKnockImpl();
 
     @Before
     public void setup() throws Exception {
@@ -69,7 +66,7 @@ public class BindingDOMRpcIntegrationTest {
         testContext = testFactory.getTestContext();
 
         testContext.setSchemaModuleInfos(ImmutableSet.of(
-            BindingRuntimeHelpers.getYangModuleInfo(OpendaylightKnockKnockRpcService.class),
+            BindingRuntimeHelpers.getYangModuleInfo(KnockKnock.class),
             BindingRuntimeHelpers.getYangModuleInfo(Top.class)));
         testContext.start();
         baRpcProviderService = testContext.getBindingRpcProviderRegistry();
@@ -82,14 +79,13 @@ public class BindingDOMRpcIntegrationTest {
     public void testBindingRegistrationWithDOMInvocation() throws Exception {
         knockRpcImpl.registerTo(baRpcProviderService, BA_NODE_ID).setKnockKnockResult(knockResult(true, "open"));
 
-        final OpendaylightKnockKnockRpcService baKnockService =
-                baRpcConsumerService.getRpcService(OpendaylightKnockKnockRpcService.class);
+        final var baKnockService = baRpcConsumerService.getRpc(KnockKnock.class);
         assertNotSame(knockRpcImpl, baKnockService);
 
-        KnockKnockInput baKnockKnockInput = knockKnock(BA_NODE_ID).setQuestion("who's there?").build();
+        final var baKnockKnockInput = knockKnock(BA_NODE_ID).setQuestion("who's there?").build();
 
-        ContainerNode biKnockKnockInput = toDOMKnockKnockInput(baKnockKnockInput);
-        DOMRpcResult domResult = Futures.getDone(biRpcService.invokeRpc(KNOCK_KNOCK_QNAME, biKnockKnockInput));
+        final var biKnockKnockInput = toDOMKnockKnockInput(baKnockKnockInput);
+        final var domResult = Futures.getDone(biRpcService.invokeRpc(KNOCK_KNOCK_QNAME, biKnockKnockInput));
         assertNotNull(domResult);
         assertNotNull(domResult.value());
         assertTrue("Binding KnockKnock service was not invoked",
@@ -99,7 +95,7 @@ public class BindingDOMRpcIntegrationTest {
 
     @Test
     public void testDOMRegistrationWithBindingInvocation() throws Exception {
-        KnockKnockOutput baKnockKnockOutput = new KnockKnockOutputBuilder().setAnswer("open").build();
+        final var baKnockKnockOutput = new KnockKnockOutputBuilder().setAnswer("open").build();
 
         biRpcProviderService.registerRpcImplementation((rpc, input) ->
             FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(testContext.getCodec()
@@ -107,25 +103,22 @@ public class BindingDOMRpcIntegrationTest {
             DOMRpcIdentifier.create(KNOCK_KNOCK_QNAME, testContext.getCodec().currentSerializer()
                 .toYangInstanceIdentifier(BA_NODE_ID)));
 
-        final OpendaylightKnockKnockRpcService baKnockService =
-                baRpcConsumerService.getRpcService(OpendaylightKnockKnockRpcService.class);
-        Future<RpcResult<KnockKnockOutput>> baResult = baKnockService.knockKnock(knockKnock(BA_NODE_ID)
-            .setQuestion("Who's there?").build());
+        final var baKnockService = baRpcConsumerService.getRpc(KnockKnock.class);
+        final var baResult = baKnockService.invoke(knockKnock(BA_NODE_ID).setQuestion("Who's there?").build());
         assertNotNull(baResult);
         assertEquals(baKnockKnockOutput, Futures.getDone(baResult).getResult());
     }
 
     @Test
     public void testBindingRpcShortcut() throws Exception {
-        final ListenableFuture<RpcResult<KnockKnockOutput>> baKnockResult = knockResult(true, "open");
+        final var baKnockResult = knockResult(true, "open");
         knockRpcImpl.registerTo(baRpcProviderService, BA_NODE_ID).setKnockKnockResult(baKnockResult);
 
-        final OpendaylightKnockKnockRpcService baKnockService =
-                baRpcConsumerService.getRpcService(OpendaylightKnockKnockRpcService.class);
+        final var baKnockService = baRpcConsumerService.getRpc(KnockKnock.class);
 
-        KnockKnockInput baKnockKnockInput = knockKnock(BA_NODE_ID).setQuestion("who's there?").build();
+        final var baKnockKnockInput = knockKnock(BA_NODE_ID).setQuestion("who's there?").build();
 
-        final RpcResult<KnockKnockOutput> rpcResult = Futures.getDone(baKnockService.knockKnock(baKnockKnockInput));
+        final var rpcResult = Futures.getDone(baKnockService.invoke(baKnockKnockInput));
 
         assertEquals(baKnockResult.get().getResult().getClass(), rpcResult.getResult().getClass());
         assertSame(baKnockResult.get().getResult(), rpcResult.getResult());
@@ -136,8 +129,8 @@ public class BindingDOMRpcIntegrationTest {
     public void testSimpleRpc() throws Exception {
         baRpcProviderService.registerRpcImplementation((KnockKnock) input -> knockResult(true, "open"));
 
-        final KnockKnock baKnockService = baRpcConsumerService.getRpc(KnockKnock.class);
-        final RpcResult<KnockKnockOutput> rpcResult = Futures.getDone(
+        final var baKnockService = baRpcConsumerService.getRpc(KnockKnock.class);
+        final var rpcResult = Futures.getDone(
             baKnockService.invoke(knockKnock(BA_NODE_ID).setQuestion("who's there?").build()));
 
         assertEquals(rpcResult.getResult().getClass(), rpcResult.getResult().getClass());
@@ -161,12 +154,12 @@ public class BindingDOMRpcIntegrationTest {
         return testContext.getCodec().currentSerializer().toNormalizedNodeRpcData(from);
     }
 
-    private static final class OpendaylightKnockKnockRpcServiceImpl implements OpendaylightKnockKnockRpcService {
+    private static final class KnockKnockImpl implements KnockKnock {
         private final Multimap<InstanceIdentifier<?>, KnockKnockInput> receivedKnocks = HashMultimap.create();
         private ListenableFuture<RpcResult<KnockKnockOutput>> knockKnockResult;
-        private ObjectRegistration<OpendaylightKnockKnockRpcServiceImpl> registration;
+        private Registration registration;
 
-        OpendaylightKnockKnockRpcServiceImpl setKnockKnockResult(
+        KnockKnockImpl setKnockKnockResult(
                 final ListenableFuture<RpcResult<KnockKnockOutput>> kkOutput) {
             knockKnockResult = kkOutput;
             return this;
@@ -176,16 +169,14 @@ public class BindingDOMRpcIntegrationTest {
             return receivedKnocks;
         }
 
-        OpendaylightKnockKnockRpcServiceImpl registerTo(final RpcProviderService registry,
-                final InstanceIdentifier<?>... paths) {
-            registration = registry.registerRpcImplementation(OpendaylightKnockKnockRpcService.class, this,
-                    ImmutableSet.copyOf(paths));
+        KnockKnockImpl registerTo(final RpcProviderService registry, final InstanceIdentifier<?>... paths) {
+            registration = registry.registerRpcImplementation(this, ImmutableSet.copyOf(paths));
             assertNotNull(registration);
             return this;
         }
 
         @Override
-        public ListenableFuture<RpcResult<KnockKnockOutput>> knockKnock(final KnockKnockInput input) {
+        public ListenableFuture<RpcResult<KnockKnockOutput>> invoke(final KnockKnockInput input) {
             receivedKnocks.put(input.getKnockerId(), input);
             return knockKnockResult;
         }
diff --git a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/BindingNormalizedCodecTest.java b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/BindingNormalizedCodecTest.java
deleted file mode 100644 (file)
index 82808c2..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2014, 2015 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.adapter;
-
-import static org.junit.Assert.assertTrue;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSetMultimap;
-import com.google.common.collect.SetMultimap;
-import java.lang.reflect.Method;
-import java.util.Map;
-import java.util.ServiceLoader;
-import java.util.Set;
-import org.junit.Test;
-import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractSchemaAwareTest;
-import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecFactory;
-import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.OpendaylightTestRpcServiceService;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.XMLNamespace;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.spi.AbstractSchemaContext;
-
-public class BindingNormalizedCodecTest extends AbstractSchemaAwareTest {
-
-    private CurrentAdapterSerializer serializer;
-
-    @Override
-    protected void setupWithRuntimeContext(final BindingRuntimeContext runtimeContext) {
-        serializer = new CurrentAdapterSerializer(ServiceLoader.load(BindingDOMCodecFactory.class)
-                .findFirst().orElseThrow().createBindingDOMCodec(runtimeContext));
-    }
-
-    @Test
-    public void testGetRpcMethodToQName() {
-        assertTrue(serializer.createQNameToMethod(OpendaylightTestRpcServiceService.class)
-            .values().stream()
-            .map(Method::getName)
-            .anyMatch("rockTheHouse"::equals));
-    }
-
-    static class EmptyEffectiveModelContext extends AbstractSchemaContext implements EffectiveModelContext {
-        @Override
-        public Set<Module> getModules() {
-            return ImmutableSet.of();
-        }
-
-        @Override
-        protected Map<QNameModule, Module> getModuleMap() {
-            return ImmutableMap.of();
-        }
-
-        @Override
-        protected SetMultimap<XMLNamespace, Module> getNamespaceToModules() {
-            return ImmutableSetMultimap.of();
-        }
-
-        @Override
-        protected SetMultimap<String, Module> getNameToModules() {
-            return ImmutableSetMultimap.of();
-        }
-
-        @Override
-        public Map<QNameModule, ModuleEffectiveStatement> getModuleStatements() {
-            return ImmutableMap.of();
-        }
-    }
-}
diff --git a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/BindingRpcAdapterRegistrationTest.java b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/BindingRpcAdapterRegistrationTest.java
deleted file mode 100644 (file)
index fd66190..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2016 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.adapter;
-
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-import org.junit.Test;
-import org.opendaylight.mdsal.dom.api.DOMRpcImplementationRegistration;
-import org.opendaylight.yangtools.yang.binding.RpcService;
-
-@Deprecated(since = "11.0.0", forRemoval = true)
-public class BindingRpcAdapterRegistrationTest {
-    @Test
-    public void removeRegistrationTest() throws Exception {
-        final RpcService rpcService = mock(RpcService.class);
-        final DOMRpcImplementationRegistration<?> domRpcImplementationRegistration =
-                mock(DOMRpcImplementationRegistration.class);
-        final BindingRpcAdapterRegistration<?> bindingRpcAdapterRegistration =
-                new BindingRpcAdapterRegistration<>(rpcService, domRpcImplementationRegistration);
-        doNothing().when(domRpcImplementationRegistration).close();
-        bindingRpcAdapterRegistration.close();
-        verify(domRpcImplementationRegistration).close();
-    }
-}
\ No newline at end of file
index edc30400d2ea8d0771fa369163822b43e901f6d4..238ba6466918273db941f8b894b79f2ab8a107d0 100644 (file)
@@ -20,7 +20,6 @@ import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import org.junit.Before;
@@ -29,18 +28,17 @@ import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
 import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingBrokerTestFactory;
 import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingTestContext;
-import org.opendaylight.mdsal.binding.runtime.spi.BindingRuntimeHelpers;
 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
 import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
-import org.opendaylight.yang.gen.v1.rpc.norev.Mdsal500Service;
+import org.opendaylight.yang.gen.v1.rpc.norev.$YangModuleInfoImpl;
+import org.opendaylight.yang.gen.v1.rpc.norev.Switch;
 import org.opendaylight.yang.gen.v1.rpc.norev.SwitchInput;
 import org.opendaylight.yang.gen.v1.rpc.norev.SwitchInputBuilder;
 import org.opendaylight.yang.gen.v1.rpc.norev.SwitchOutput;
 import org.opendaylight.yang.gen.v1.rpc.norev.SwitchOutputBuilder;
-import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -57,7 +55,7 @@ public class Mdsal500Test {
     private DOMRpcProviderService biRpcProviderService;
     private BindingTestContext testContext;
     private DOMRpcService biRpcService;
-    private final Mdsal500ServiceImpl switchRpcImpl = new Mdsal500ServiceImpl();
+    private final SwitchImpl switchRpcImpl = new SwitchImpl();
 
     @Before
     public void setup() throws Exception {
@@ -65,8 +63,7 @@ public class Mdsal500Test {
         testFactory.setExecutor(MoreExecutors.newDirectExecutorService());
         testContext = testFactory.getTestContext();
 
-        testContext.setSchemaModuleInfos(Set.of(
-            BindingRuntimeHelpers.getYangModuleInfo(Mdsal500Service.class)));
+        testContext.setSchemaModuleInfos(Set.of($YangModuleInfoImpl.getInstance()));
         testContext.start();
         baRpcProviderService = testContext.getBindingRpcProviderRegistry();
         baRpcConsumerService = testContext.getBindingRpcConsumerRegistry();
@@ -78,7 +75,7 @@ public class Mdsal500Test {
     public void testBindingRegistrationWithDOMInvocation() throws Exception {
         switchRpcImpl.registerTo(baRpcProviderService).setSwitchResult(switchResult(true));
 
-        final Mdsal500Service baSwitchService = baRpcConsumerService.getRpcService(Mdsal500Service.class);
+        final var baSwitchService = baRpcConsumerService.getRpc(Switch.class);
         assertNotSame(switchRpcImpl, baSwitchService);
 
         SwitchInput baSwitchInput = switchBuilder(FOO).build();
@@ -102,25 +99,23 @@ public class Mdsal500Test {
                     .toNormalizedNodeRpcData(baSwitchOutput))),
             DOMRpcIdentifier.create(SWITCH_QNAME));
 
-        final Mdsal500Service baSwitchService =
-                baRpcConsumerService.getRpcService(Mdsal500Service.class);
-        Future<RpcResult<SwitchOutput>> baResult = baSwitchService.switch$(switchBuilder(FOO)
-            .build());
+        final var baSwitchService = baRpcConsumerService.getRpc(Switch.class);
+        final var baResult = baSwitchService.invoke(switchBuilder(FOO).build());
         assertNotNull(baResult);
         assertEquals(baSwitchOutput, baResult.get(5, TimeUnit.SECONDS).getResult());
     }
 
     @Test
     public void testBindingRpcShortcut() throws InterruptedException, ExecutionException, TimeoutException {
-        final ListenableFuture<RpcResult<SwitchOutput>> baSwitchResult = switchResult(true);
+        final var baSwitchResult = switchResult(true);
         switchRpcImpl.registerTo(baRpcProviderService).setSwitchResult(baSwitchResult);
 
-        final Mdsal500Service baSwitchService = baRpcConsumerService.getRpcService(Mdsal500Service.class);
+        final var baSwitchService = baRpcConsumerService.getRpc(Switch.class);
 
-        SwitchInput baSwitchInput = switchBuilder(FOO).build();
-        ListenableFuture<RpcResult<SwitchOutput>> future = baSwitchService.switch$(baSwitchInput);
+        final var baSwitchInput = switchBuilder(FOO).build();
+        final var future = baSwitchService.invoke(baSwitchInput);
 
-        final RpcResult<SwitchOutput> rpcResult = future.get(5, TimeUnit.SECONDS);
+        final var rpcResult = future.get(5, TimeUnit.SECONDS);
 
         assertEquals(baSwitchResult.get().getResult().getClass(), rpcResult.getResult().getClass());
         assertSame(baSwitchResult.get().getResult(), rpcResult.getResult());
@@ -141,11 +136,11 @@ public class Mdsal500Test {
         return testContext.getCodec().currentSerializer().toNormalizedNodeRpcData(from);
     }
 
-    private static final class Mdsal500ServiceImpl implements Mdsal500Service {
+    private static final class SwitchImpl implements Switch {
         private final Multimap<String, SwitchInput> receivedSwitch = HashMultimap.create();
         private ListenableFuture<RpcResult<SwitchOutput>> switchResult;
 
-        Mdsal500ServiceImpl setSwitchResult(final ListenableFuture<RpcResult<SwitchOutput>> switchOutput) {
+        SwitchImpl setSwitchResult(final ListenableFuture<RpcResult<SwitchOutput>> switchOutput) {
             switchResult = switchOutput;
             return this;
         }
@@ -154,15 +149,14 @@ public class Mdsal500Test {
             return receivedSwitch;
         }
 
-        Mdsal500ServiceImpl registerTo(final RpcProviderService registry) {
-            final ObjectRegistration<Mdsal500ServiceImpl> registration =
-                    registry.registerRpcImplementation(Mdsal500Service.class, this);
+        SwitchImpl registerTo(final RpcProviderService registry) {
+            final var registration = registry.registerRpcImplementation(this);
             assertNotNull(registration);
             return this;
         }
 
         @Override
-        public ListenableFuture<RpcResult<SwitchOutput>> switch$(final SwitchInput switchInput) {
+        public ListenableFuture<RpcResult<SwitchOutput>> invoke(final SwitchInput switchInput) {
             receivedSwitch.put(switchInput.getFoo(), switchInput);
             return switchResult;
         }
index b3ed0e0ae68e4894c5969478e62fb6f86c4f584f..d52bd826cfb7371e576c1a4fd1756418acedb3a8 100644 (file)
@@ -7,14 +7,11 @@
  */
 package org.opendaylight.mdsal.binding.dom.adapter;
 
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertSame;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
 
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListeningExecutorService;
@@ -25,11 +22,12 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingBrokerTestFactory;
-import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingTestContext;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.OpendaylightTestRpcServiceService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouse;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInputBuilder;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -38,40 +36,39 @@ import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 
 @ExtendWith(MockitoExtension.class)
-public class Mdsal739Test {
-    private ListeningExecutorService executorService;
+class Mdsal739Test {
+    private final ListeningExecutorService executorService = MoreExecutors.newDirectExecutorService();
+
+    @Mock
+    private DOMRpcService rpcService;
+    @Captor
+    private ArgumentCaptor<ContainerNode> captor;
+
     private AdapterContext adapterContext;
 
     @BeforeEach
-    public void before() {
-        executorService = MoreExecutors.newDirectExecutorService();
-
-        final BindingBrokerTestFactory bindingBrokerTestFactory = new BindingBrokerTestFactory();
+    void before() {
+        final var bindingBrokerTestFactory = new BindingBrokerTestFactory();
         bindingBrokerTestFactory.setExecutor(executorService);
-        final BindingTestContext bindingTestContext = bindingBrokerTestFactory.getTestContext();
+        final var bindingTestContext = bindingBrokerTestFactory.getTestContext();
         bindingTestContext.start();
 
         adapterContext = bindingTestContext.getCodec();
     }
 
     @AfterEach
-    public void after() {
+    void after() {
         executorService.shutdownNow();
     }
 
     @Test
-    public void testRpcInputName() {
-        final var rpcService = mock(DOMRpcService.class);
-
-        final var captor = ArgumentCaptor.forClass(ContainerNode.class);
+    void testRpcInputName() {
         doReturn(Futures.immediateFailedFuture(new Throwable())).when(rpcService).invokeRpc(any(), captor.capture());
-        final var adapter = (OpendaylightTestRpcServiceService) new RpcServiceAdapter(
-            OpendaylightTestRpcServiceService.class, adapterContext, rpcService).facade();
+        final var adapter = (RockTheHouse) new RpcAdapter(adapterContext, rpcService, RockTheHouse.class).facade();
 
-        final var result = adapter.rockTheHouse(new RockTheHouseInputBuilder().setZipCode("12345").build());
+        final var result = adapter.invoke(new RockTheHouseInputBuilder().setZipCode("12345").build());
         assertThrows(ExecutionException.class, () -> Futures.getDone(result));
         final var input = captor.getValue();
-        assertThat(input, instanceOf(ContainerNode.class));
         assertSame(NodeIdentifier.create(RockTheHouseInput.QNAME), input.name());
         final var body = input.body();
         assertEquals(1, body.size());
diff --git a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/RpcServiceAdapterTest.java b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/RpcServiceAdapterTest.java
deleted file mode 100644 (file)
index e834d6e..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (c) 2016 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.adapter;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import com.google.common.util.concurrent.MoreExecutors;
-import java.lang.reflect.Method;
-import org.junit.Test;
-import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingBrokerTestFactory;
-import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingTestContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.OpendaylightTestRpcServiceService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.OpendaylightTestRoutedRpcService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInputBuilder;
-import org.opendaylight.yangtools.yang.binding.RpcService;
-
-@Deprecated(since = "11.0.0", forRemoval = true)
-public class RpcServiceAdapterTest {
-
-    @SuppressWarnings("checkstyle:IllegalThrows")
-    @Test
-    public void invoke() throws Throwable {
-        final BindingBrokerTestFactory bindingBrokerTestFactory = new BindingBrokerTestFactory();
-        bindingBrokerTestFactory.setExecutor(MoreExecutors.newDirectExecutorService());
-        final BindingTestContext bindingTestContext = bindingBrokerTestFactory.getTestContext();
-        bindingTestContext.start();
-
-        RpcServiceAdapter rpcServiceAdapter = new RpcServiceAdapter(OpendaylightTestRpcServiceService.class,
-                bindingTestContext.getCodec(), bindingTestContext.getDomRpcInvoker());
-
-        Method method = TestRpcService.class.getMethod("equals", Object.class);
-        assertTrue((boolean) rpcServiceAdapter.invoke(rpcServiceAdapter.facade(), method,
-                new Object[]{ rpcServiceAdapter.facade() }));
-        assertFalse((boolean) rpcServiceAdapter.invoke(rpcServiceAdapter.facade(), method,
-                new Object[]{ new Object() }));
-
-        method = TestRpcService.class.getMethod("hashCode");
-        assertEquals(rpcServiceAdapter.facade().hashCode(), rpcServiceAdapter.invoke(rpcServiceAdapter.facade(),
-                method, new Object[]{ }));
-
-        method = TestRpcService.class.getMethod("toString");
-        assertEquals(rpcServiceAdapter.facade().toString(), rpcServiceAdapter.invoke(rpcServiceAdapter.facade(),
-                method, new Object[]{ }));
-
-        method = OpendaylightTestRpcServiceService.class.getMethod("rockTheHouse", RockTheHouseInput.class);
-        assertNotNull(rpcServiceAdapter.invoke(rpcServiceAdapter.facade(), method,
-            new Object[]{ new RockTheHouseInputBuilder().build() }));
-
-        rpcServiceAdapter = new RpcServiceAdapter(OpendaylightTestRoutedRpcService.class,
-                bindingTestContext.getCodec(), bindingTestContext.getDomRpcInvoker());
-        method = OpendaylightTestRoutedRpcService.class.getMethod("routedSimpleRoute", RoutedSimpleRouteInput.class);
-        assertNotNull(rpcServiceAdapter.invoke(rpcServiceAdapter.facade(), method,
-                new Object[]{ new RoutedSimpleRouteInputBuilder().build() }));
-    }
-
-    private interface TestRpcService extends RpcService {
-
-        @Override
-        String toString();
-
-        @Override
-        int hashCode();
-
-        @Override
-        boolean equals(Object object);
-    }
-}
\ No newline at end of file
index 93f8dbde3c1ad4fe9fa36b6c33d567e85335f61c..9fe590e9a543c837f9450311ef4d3a22aa5badc9 100644 (file)
@@ -573,21 +573,13 @@ public abstract class AbstractCompositeGenerator<S extends EffectiveStatement<?,
 
         // Compatibility FooService and FooListener interfaces, only generated for modules.
         if (this instanceof ModuleGenerator moduleGen) {
-            final List<NotificationGenerator> notifs = tmp.stream()
+            final var notifs = tmp.stream()
                 .filter(NotificationGenerator.class::isInstance)
                 .map(NotificationGenerator.class::cast)
                 .collect(Collectors.toUnmodifiableList());
             if (!notifs.isEmpty()) {
                 tmp.add(new NotificationServiceGenerator(moduleGen, notifs));
             }
-
-            final List<RpcGenerator> rpcs = tmp.stream()
-                .filter(RpcGenerator.class::isInstance)
-                .map(RpcGenerator.class::cast)
-                .collect(Collectors.toUnmodifiableList());
-            if (!rpcs.isEmpty()) {
-                tmp.add(new RpcServiceGenerator(moduleGen, rpcs));
-            }
         }
 
         return List.copyOf(tmp);
diff --git a/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/reactor/RpcServiceGenerator.java b/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/reactor/RpcServiceGenerator.java
deleted file mode 100644 (file)
index 2660805..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 2021 PANTHEON.tech, s.r.o. 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.generator.impl.reactor;
-
-import static java.util.Objects.requireNonNull;
-
-import java.util.List;
-import org.opendaylight.mdsal.binding.model.api.GeneratedType;
-import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
-import org.opendaylight.mdsal.binding.model.api.TypeMemberComment;
-import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder;
-import org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder;
-import org.opendaylight.mdsal.binding.model.ri.BindingTypes;
-import org.opendaylight.mdsal.binding.model.ri.Types;
-import org.opendaylight.yangtools.yang.binding.contract.Naming;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.InputEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.OutputEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
-
-/**
- * Aggregate service for top-level {@code rpc} statements for a particular module.
- */
-// FIXME: eventually remove this generator
-@Deprecated(since = "11.0.0", forRemoval = true)
-final class RpcServiceGenerator extends AbstractImplicitGenerator {
-    private static final JavaTypeName CHECK_RETURN_VALUE_ANNOTATION =
-        // Do not refer to annotation class, as it may not be available at runtime
-        JavaTypeName.create("edu.umd.cs.findbugs.annotations", "CheckReturnValue");
-
-    private final List<RpcGenerator> rpcs;
-
-    RpcServiceGenerator(final ModuleGenerator parent, final List<RpcGenerator> rpcs) {
-        super(parent);
-        this.rpcs = requireNonNull(rpcs);
-    }
-
-    @Override
-    StatementNamespace namespace() {
-        return StatementNamespace.RPC_SERVICE;
-    }
-
-    @Override
-    String classSuffix() {
-        return Naming.RPC_SERVICE_SUFFIX;
-    }
-
-    @Override
-    GeneratedType createTypeImpl(final TypeBuilderFactory builderFactory) {
-        final GeneratedTypeBuilder builder = builderFactory.newGeneratedTypeBuilder(typeName());
-        builder.addImplementsType(BindingTypes.RPC_SERVICE);
-
-        for (RpcGenerator rpcGen : rpcs) {
-            final RpcEffectiveStatement rpc = rpcGen.statement();
-            final QName qname = rpc.argument();
-
-            // FIXME: this may still conflict in theory
-            final MethodSignatureBuilder method = builder.addMethod(Naming.getRpcMethodName(qname));
-
-            method.addParameter(getChild(rpcGen, InputEffectiveStatement.class).getGeneratedType(builderFactory),
-                "input");
-            method.setReturnType(Types.listenableFutureTypeFor(BindingTypes.rpcResult(
-                getChild(rpcGen, OutputEffectiveStatement.class).getGeneratedType(builderFactory))));
-
-            // FIXME: this should not be part of runtime types
-            method.addAnnotation(CHECK_RETURN_VALUE_ANNOTATION);
-            final String rpcName = qname.getLocalName();
-            method.setComment(new TypeMemberComment("Invoke {@code " + rpcName + "} RPC.",
-                rpc.findFirstEffectiveSubstatementArgument(DescriptionEffectiveStatement.class).orElse(null),
-                "@param input of {@code " + rpcName + "}\n"
-                    + "@return output of {@code " + rpcName + '}'));
-        }
-
-        // FIXME: activate this
-        //      addCodegenInformation(interfaceBuilder, module, "RPCs", rpcDefinitions);
-
-        return builder.build();
-    }
-}
index d8401b27cb21efe6a6ec7c5565990d3a86fd321c..f25df47efa0055dfbfff1d4937596c77f044037a 100644 (file)
@@ -12,7 +12,6 @@ import static java.util.Objects.requireNonNull;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.binding.NotificationListener;
-import org.opendaylight.yangtools.yang.binding.RpcService;
 
 /**
  * <a href="https://www.rfc-editor.org/rfc/rfc6020#section-6.2.1">YANG statement namespaces</a> which we process.
@@ -106,24 +105,7 @@ enum StatementNamespace {
      */
     // FIXME: MDSAL-497: remove this value
     @Deprecated
-    NOTIFICATION_LISTENER("$LL", true),
-    /**
-     * The namespace for combined {@link RpcService} interface. This typically does not conflict, but could in case of
-     * <code>
-     *   <pre>
-     *     module foo {
-     *       container foo-service; // results in FooService
-     *       rpc bar; // Triggers FooService generation for module
-     *     }
-     *   </pre>
-     * </code>
-     * In this case the module-derived FooService gets shifted to {@code $LR}.
-     *
-     * @deprecated This will be removed once {@link RpcServiceGenerator} is gone.
-     */
-    // FIXME: MDSAL-497: remove this value
-    @Deprecated
-    RPC_SERVICE("$LR", true);
+    NOTIFICATION_LISTENER("$LL", true);
 
     private final @NonNull String suffix;
     private final boolean resistant;
index 2602285d28045ce743e837ec3993b7758edc6e4e..be676b8670aaf36e7f7bfcb5b62cf084f224237c 100644 (file)
@@ -11,12 +11,8 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import java.util.List;
 import org.junit.Test;
-import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
-import org.opendaylight.mdsal.binding.model.api.GeneratedType;
-import org.opendaylight.mdsal.binding.model.api.MethodSignature;
 import org.opendaylight.yangtools.yang.binding.contract.Naming;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
@@ -31,15 +27,15 @@ public class GeneratedTypesTest {
 
     @Test
     public void testContainerResolving() {
-        final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
+        final var genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
             "/simple-container-demo.yang"));
 
         assertNotNull(genTypes);
         assertEquals(3, genTypes.size());
 
-        GeneratedType simpleContainer = genTypes.get(1);
-        GeneratedType nestedContainer = genTypes.get(2);
-        for (GeneratedType t : genTypes) {
+        var simpleContainer = genTypes.get(1);
+        var nestedContainer = genTypes.get(2);
+        for (var t : genTypes) {
             if ("SimpleContainer".equals(t.getName())) {
                 simpleContainer = t;
             } else if ("NestedContainer".equals(t.getName())) {
@@ -60,7 +56,7 @@ public class GeneratedTypesTest {
         String getFooMethodReturnTypeName = "";
         String getBarMethodReturnTypeName = "";
         String getNestedContainerReturnTypeName = "";
-        for (final MethodSignature method : simpleContainer.getMethodDefinitions()) {
+        for (var method : simpleContainer.getMethodDefinitions()) {
             if (method.getName().equals("getFoo")) {
                 getFooMethodCounter++;
                 getFooMethodReturnTypeName = method.getReturnType().getName();
@@ -92,8 +88,7 @@ public class GeneratedTypesTest {
         getFooMethodReturnTypeName = "";
         getBarMethodReturnTypeName = "";
 
-        for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {
-
+        for (var method : nestedContainer.getMethodDefinitions()) {
             if (method.getName().equals("getFoo")) {
                 getFooMethodCounter++;
                 getFooMethodReturnTypeName = method.getReturnType().getName();
@@ -114,15 +109,15 @@ public class GeneratedTypesTest {
 
     @Test
     public void testLeafListResolving() {
-        final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
+        final var genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
             "/simple-leaf-list-demo.yang"));
 
         assertNotNull(genTypes);
         assertEquals(3, genTypes.size());
 
-        GeneratedType simpleContainer = genTypes.get(1);
-        GeneratedType nestedContainer = genTypes.get(2);
-        for (GeneratedType t : genTypes) {
+        var simpleContainer = genTypes.get(1);
+        var nestedContainer = genTypes.get(2);
+        for (var t : genTypes) {
             if ("SimpleContainer".equals(t.getName())) {
                 simpleContainer = t;
             } else if ("NestedContainer".equals(t.getName())) {
@@ -143,7 +138,7 @@ public class GeneratedTypesTest {
         String getFooMethodReturnTypeName = "";
         String getBarMethodReturnTypeName = "";
         String getNestedContainerReturnTypeName = "";
-        for (final MethodSignature method : simpleContainer.getMethodDefinitions()) {
+        for (var method : simpleContainer.getMethodDefinitions()) {
             if (method.isDefault()) {
                 continue;
             }
@@ -178,7 +173,7 @@ public class GeneratedTypesTest {
         getFooMethodReturnTypeName = "";
         getBarMethodReturnTypeName = "";
 
-        for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {
+        for (var method : nestedContainer.getMethodDefinitions()) {
             if (method.getName().equals("getFoo")) {
                 getFooMethodCounter++;
                 getFooMethodReturnTypeName = method.getReturnType().getName();
@@ -199,7 +194,7 @@ public class GeneratedTypesTest {
 
     @Test
     public void testListResolving() {
-        final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
+        final var genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
             "/simple-list-demo.yang"));
 
         assertNotNull(genTypes);
@@ -221,14 +216,13 @@ public class GeneratedTypesTest {
         String getSimpleListKeyMethodReturnTypeName = "";
         String getListChildContainerMethodReturnTypeName = "";
 
-        for (final GeneratedType genType : genTypes) {
+        for (var genType : genTypes) {
             if (!(genType instanceof GeneratedTransferObject genTO)) {
                 if (genType.getName().equals("ListParentContainer")) {
                     listParentContainerMethodsCount = genType.getMethodDefinitions().size();
                 } else if (genType.getName().equals("SimpleList")) {
                     simpleListMethodsCount = genType.getMethodDefinitions().size();
-                    final List<MethodSignature> methods = genType.getMethodDefinitions();
-                    for (final MethodSignature method : methods) {
+                    for (var method : genType.getMethodDefinitions()) {
                         switch (method.getName()) {
                             case Naming.KEY_AWARE_KEY_NAME:
                                 getSimpleListKeyMethodCount++;
@@ -260,9 +254,9 @@ public class GeneratedTypesTest {
                     listChildContainerMethodsCount = genType.getMethodDefinitions().size();
                 }
             } else {
-                final List<GeneratedProperty> properties = genTO.getProperties();
-                final List<GeneratedProperty> hashProps = genTO.getHashCodeIdentifiers();
-                final List<GeneratedProperty> equalProps = genTO.getEqualsIdentifiers();
+                final var properties = genTO.getProperties();
+                final var hashProps = genTO.getHashCodeIdentifiers();
+                final var equalProps = genTO.getEqualsIdentifiers();
 
                 assertEquals("Unexpected key", 0, listKeyClassCount++);
                 assertEquals(1, properties.size());
@@ -303,7 +297,7 @@ public class GeneratedTypesTest {
 
     @Test
     public void testListCompositeKeyResolving() {
-        final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
+        final var genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
             "/list-composite-key.yang"));
 
         assertNotNull(genTypes);
@@ -316,21 +310,19 @@ public class GeneratedTypesTest {
         int compositeKeyListKeyCount = 0;
         int innerListKeyPropertyCount = 0;
 
-        for (final GeneratedType type : genTypes) {
+        for (var type : genTypes) {
             if (!(type instanceof GeneratedTransferObject genTO)) {
                 genTypesCount++;
             } else if (genTO.getName().equals("CompositeKeyListKey")) {
                 compositeKeyListKeyCount++;
-                final List<GeneratedProperty> properties = genTO.getProperties();
-                for (final GeneratedProperty prop : properties) {
+                for (var prop : genTO.getProperties()) {
                     if (prop.getName().equals("key1") || prop.getName().equals("key2")) {
                         compositeKeyListKeyPropertyCount++;
                     }
                 }
                 genTOsCount++;
             } else if (genTO.getName().equals("InnerListKey")) {
-                final List<GeneratedProperty> properties = genTO.getProperties();
-                innerListKeyPropertyCount = properties.size();
+                innerListKeyPropertyCount =  genTO.getProperties().size();
                 genTOsCount++;
             }
         }
@@ -345,7 +337,7 @@ public class GeneratedTypesTest {
 
     @Test
     public void testGeneratedTypes() {
-        final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
+        final var genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
             "/demo-topology.yang"));
 
         assertNotNull(genTypes);
@@ -353,7 +345,7 @@ public class GeneratedTypesTest {
 
         int genTypesCount = 0;
         int genTOsCount = 0;
-        for (final GeneratedType type : genTypes) {
+        for (var type : genTypes) {
             if (type instanceof GeneratedTransferObject) {
                 genTOsCount++;
             } else {
@@ -367,8 +359,8 @@ public class GeneratedTypesTest {
 
     @Test
     public void testAugmentRpcInput() {
-        final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
+        final var genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
             "/augment-rpc-input.yang"));
-        assertEquals(7, genTypes.size());
+        assertEquals(6, genTypes.size());
     }
 }
index 79339ff003754b22f178307c101b9fc1926c068f..57b4b81284a43a260fc03a471df9663ca36fde6c 100644 (file)
@@ -18,6 +18,6 @@ public class Mdsal302Test {
     public void testRpcUsesAugment() {
         final var types = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource("/mdsal302.yang"));
         assertNotNull(types);
-        assertEquals(16, types.size());
+        assertEquals(15, types.size());
     }
 }
index ee83c8cfa0fe53f95b690682cf6da628d09a8b0c..0e4cef3b1ed60f594559b0d435027291486b8456 100644 (file)
@@ -10,26 +10,14 @@ package org.opendaylight.mdsal.binding.generator.impl;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
-import java.util.List;
 import org.junit.Test;
-import org.opendaylight.mdsal.binding.model.api.GeneratedType;
-import org.opendaylight.mdsal.binding.model.api.MethodSignature;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public class Mdsal500Test {
     @Test
     public void testAugmentedAction() {
-        final List<GeneratedType> types = DefaultBindingGenerator.generateFor(
-                YangParserTestUtils.parseYangResource("/mdsal500.yang"));
+        final var types = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource("/mdsal500.yang"));
         assertNotNull(types);
-        assertEquals(5, types.size());
-
-        final GeneratedType rpcService = types.get(4);
-        assertEquals("Mdsal500Service", rpcService.getName());
-        final List<MethodSignature> methods = rpcService.getMethodDefinitions();
-        assertEquals(1, methods.size());
-
-        final MethodSignature signature = methods.get(0);
-        assertEquals("switch$", signature.getName());
+        assertEquals(4, types.size());
     }
 }
index 3e19020df2152adf579b77dcc270818a88849a9c..a77a9e7ed0cad1d7a8316cb3447db428ecd62599 100644 (file)
@@ -10,11 +10,8 @@ package org.opendaylight.mdsal.binding.generator.impl;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
-import java.util.List;
 import org.junit.Test;
-import org.opendaylight.mdsal.binding.model.api.GeneratedType;
 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
-import org.opendaylight.mdsal.binding.model.api.MethodSignature;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public class Mdsal552Test {
@@ -27,23 +24,22 @@ public class Mdsal552Test {
 
     @Test
     public void enumLeafrefTest() {
-        final List<GeneratedType> types = DefaultBindingGenerator.generateFor(
-                YangParserTestUtils.parseYangResource("/mdsal552.yang"));
+        final var types = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource("/mdsal552.yang"));
         assertNotNull(types);
-        assertEquals(6, types.size());
+        assertEquals(5, types.size());
 
-        final GeneratedType baz = types.stream()
+        final var baz = types.stream()
                 .filter(type -> BAZ.equals(type.getIdentifier()))
                 .findFirst().orElseThrow();
-        final MethodSignature bazGetRef = baz.getMethodDefinitions().stream()
+        final var bazGetRef = baz.getMethodDefinitions().stream()
                 .filter(method -> method.getName().equals("getRef"))
                 .findFirst().orElseThrow();
         assertEquals(ENUMERATION, bazGetRef.getReturnType().getIdentifier());
 
-        final GeneratedType input = types.stream()
+        final var input = types.stream()
                 .filter(type -> BAR_INPUT.equals(type.getIdentifier()))
                 .findFirst().orElseThrow();
-        final MethodSignature inputGetRef = input.getMethodDefinitions().stream()
+        final var inputGetRef = input.getMethodDefinitions().stream()
                 .filter(method -> method.getName().equals("getRef"))
                 .findFirst().orElseThrow();
         assertEquals(ENUMERATION, inputGetRef.getReturnType().getIdentifier());
index 9f0ff562e3ea7465fc8f11633455aa07e3c146d4..3a0318380a04fe7a731d648fba90e842032b5cc0 100644 (file)
@@ -27,7 +27,7 @@ public class Mdsal666Test {
         final var generatedNames = DefaultBindingGenerator.generateFor(
             YangParserTestUtils.parseYangResource("/mdsal666.yang")).stream().map(GeneratedType::getIdentifier)
             .collect(Collectors.toUnmodifiableList());
-        assertEquals(11, generatedNames.size());
+        assertEquals(10, generatedNames.size());
 
         // 'rpc foo' ...
         assertTrue(generatedNames.stream().anyMatch(FOO::equals));
index 18eb5307fb5e75fca69d4cc8104862c62a1b110c..65d2799703bb71e2c7e015517db1c70ae942d138 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.mdsal.binding.generator.impl;
 
 import static org.junit.Assert.assertEquals;
 
-import java.util.Arrays;
+import java.util.List;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
@@ -43,11 +43,10 @@ public class Mdsal810Test {
     public void testServiceConflict() {
         assertGeneratedNames("service-conflict.yang",
             "org.opendaylight.yang.gen.v1.service.conflict.norev.ServiceConflictData",
-            "org.opendaylight.yang.gen.v1.service.conflict.norev.ServiceConflictService$CO",
+            "org.opendaylight.yang.gen.v1.service.conflict.norev.ServiceConflictService",
             "org.opendaylight.yang.gen.v1.service.conflict.norev.Bar",
             "org.opendaylight.yang.gen.v1.service.conflict.norev.BarInput",
-            "org.opendaylight.yang.gen.v1.service.conflict.norev.BarOutput",
-            "org.opendaylight.yang.gen.v1.service.conflict.norev.ServiceConflictService");
+            "org.opendaylight.yang.gen.v1.service.conflict.norev.BarOutput");
     }
 
     @Test
@@ -58,8 +57,7 @@ public class Mdsal810Test {
             "org.opendaylight.yang.gen.v1.io.conflict.norev.Foo$RPInput",
             "org.opendaylight.yang.gen.v1.io.conflict.norev.Foo$RPOutput",
             "org.opendaylight.yang.gen.v1.io.conflict.norev.FooInput",
-            "org.opendaylight.yang.gen.v1.io.conflict.norev.FooOutput",
-            "org.opendaylight.yang.gen.v1.io.conflict.norev.IoConflictService");
+            "org.opendaylight.yang.gen.v1.io.conflict.norev.FooOutput");
     }
 
     @Test
@@ -74,12 +72,11 @@ public class Mdsal810Test {
             "org.opendaylight.yang.gen.v1.schema.conflict.norev.FooBar$RP",
             "org.opendaylight.yang.gen.v1.schema.conflict.norev.FooBar$RPInput",
             "org.opendaylight.yang.gen.v1.schema.conflict.norev.FooBar$RPOutput",
-            "org.opendaylight.yang.gen.v1.schema.conflict.norev.SchemaConflictListener",
-            "org.opendaylight.yang.gen.v1.schema.conflict.norev.SchemaConflictService");
+            "org.opendaylight.yang.gen.v1.schema.conflict.norev.SchemaConflictListener");
     }
 
     private static void assertGeneratedNames(final String yangFile, final String... fqcns) {
-        assertEquals(Arrays.asList(fqcns),
+        assertEquals(List.of(fqcns),
             DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource("/mdsal-810/" + yangFile))
                 .stream().map(type -> type.getIdentifier().toString()).toList());
     }
index 606bd9a0347adb41c2095daaa909e51013798af0..b5d6d8cb225ca6aa4e90c98e969c08f80ddfafce 100644 (file)
@@ -44,7 +44,6 @@ import org.opendaylight.yangtools.yang.binding.OpaqueObject;
 import org.opendaylight.yangtools.yang.binding.Rpc;
 import org.opendaylight.yangtools.yang.binding.RpcInput;
 import org.opendaylight.yangtools.yang.binding.RpcOutput;
-import org.opendaylight.yangtools.yang.binding.RpcService;
 import org.opendaylight.yangtools.yang.binding.ScalarTypeObject;
 import org.opendaylight.yangtools.yang.binding.UnionTypeObject;
 import org.opendaylight.yangtools.yang.binding.YangData;
@@ -66,8 +65,6 @@ public final class BindingTypes {
     public static final ConcreteType QNAME = typeForClass(QName.class);
     public static final ConcreteType RPC_INPUT = typeForClass(RpcInput.class);
     public static final ConcreteType RPC_OUTPUT = typeForClass(RpcOutput.class);
-    @Deprecated(since = "11.0.0", forRemoval = true)
-    public static final ConcreteType RPC_SERVICE = typeForClass(RpcService.class);
     public static final ConcreteType SCALAR_TYPE_OBJECT = typeForClass(ScalarTypeObject.class);
     public static final ConcreteType BITS_TYPE_OBJECT = typeForClass(BitsTypeObject.class);
     public static final ConcreteType UNION_TYPE_OBJECT = typeForClass(UnionTypeObject.class);
index 6b8bbbeb156bc4e2ac4265fff8032643e8cc744b..6ac6e289ab418a313510c0ac9ece6d1073a4577e 100644 (file)
@@ -25,7 +25,6 @@ import org.opendaylight.yangtools.yang.binding.Key;
 import org.opendaylight.yangtools.yang.binding.KeyAware;
 import org.opendaylight.yangtools.yang.binding.Notification;
 import org.opendaylight.yangtools.yang.binding.NotificationListener;
-import org.opendaylight.yangtools.yang.binding.RpcService;
 
 public class BindingTypesTest {
     @Test
@@ -40,7 +39,6 @@ public class BindingTypesTest {
         assertEquals("INSTANCE_IDENTIFIER", typeForClass(InstanceIdentifier.class), BindingTypes.INSTANCE_IDENTIFIER);
         assertEquals("NOTIFICATION_LISTENER", typeForClass(NotificationListener.class),
             BindingTypes.NOTIFICATION_LISTENER);
-        assertEquals("RPC_SERVICE", typeForClass(RpcService.class), BindingTypes.RPC_SERVICE);
     }
 
     @Test
index 7a9427c83ad34094a891a1c3cef41e2b923b8db1..ec41e1e91b827124a484ff7e531f56bd75e8a57f 100644 (file)
@@ -10,30 +10,18 @@ package org.opendaylight.mdsal.binding.spec.reflect;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import com.google.common.util.concurrent.ListenableFuture;
-import java.util.List;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.binding.Augmentation;
 import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.RpcService;
-import org.opendaylight.yangtools.yang.common.QName;
 
 public class BindingReflectionsTest {
-
     @Test
     public void testBindingWithDummyObject() throws Exception {
-        assertFalse("Should not be RpcType", BindingReflections.isRpcType(DataObject.class));
-        assertTrue("Should be BindingClass", BindingReflections.isBindingClass(DataObject.class));
+        assertFalse(BindingReflections.isRpcType(DataObject.class));
+        assertTrue(BindingReflections.isBindingClass(DataObject.class));
     }
 
-    static final class TestImplementation implements Augmentation<TestImplementation>, RpcService {
-        public static final QName QNAME = QName.create("test", "test");
-
-        @SuppressWarnings("static-method")
-        ListenableFuture<List<Object>> rpcMethodTest() {
-            return null;
-        }
-
+    static final class TestImplementation implements Augmentation<TestImplementation> {
         @Override
         public Class<TestImplementation> implementedInterface() {
             return TestImplementation.class;
diff --git a/binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/RpcService.java b/binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/RpcService.java
deleted file mode 100644 (file)
index 835f4e9..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.binding;
-
-/**
- * Marker interface for tagging generated YANG Modules.
- */
-@Deprecated(since = "11.0.0", forRemoval = true)
-public interface RpcService {
-
-}
index a0c422d105922348b65b62492867b024ae759194..a43790cd372a882d0e20b6b63313b3425016e061 100644 (file)
@@ -358,18 +358,6 @@ public final class Naming {
         return str.substring(0, 1).toLowerCase(Locale.ENGLISH) + str.substring(1);
     }
 
-    /**
-     * Returns the {@link String} {@code s} with a '$' character as suffix.
-     *
-     * @param qname RPC QName
-     * @return The RPC method name as determined by considering the localname against the JLS.
-     * @throws NullPointerException if {@code qname} is null
-     */
-    public static @NonNull String getRpcMethodName(final @NonNull QName qname) {
-        final String methodName = getMethodName(qname);
-        return JAVA_RESERVED_WORDS.contains(methodName) ? methodName + "$" : methodName;
-    }
-
     /**
      * Returns root package name for supplied package name.
      *