X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=binding%2Fmdsal-binding-dom-adapter%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fdom%2Fadapter%2FBindingDOMRpcProviderServiceAdapter.java;h=9f8f67c475ad5fc706fa18ff434136a15905c474;hb=462592633aec85d51bcc280145b47055ec10743c;hp=6a4c6e1c57c4705682025ad322ec0494b256b335;hpb=b36a95a80b1d42191d070beb376a2495d8fd1923;p=mdsal.git diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcProviderServiceAdapter.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcProviderServiceAdapter.java index 6a4c6e1c57..9f8f67c475 100644 --- a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcProviderServiceAdapter.java +++ b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcProviderServiceAdapter.java @@ -9,14 +9,13 @@ package org.opendaylight.mdsal.binding.dom.adapter; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ClassToInstanceMap; -import com.google.common.collect.ImmutableClassToInstanceMap; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.util.ArrayList; import java.util.Collection; -import java.util.Map; +import java.util.List; import java.util.Set; -import java.util.function.BiFunction; +import java.util.function.Function; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.mdsal.binding.api.RpcProviderService; import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier; @@ -51,31 +50,43 @@ public class BindingDOMRpcProviderServiceAdapter extends AbstractBindingAdapter< } @Override - public Registration registerRpcImplementations(final ClassToInstanceMap> implementations) { + public Registration registerRpcImplementations(final Collection> implementations) { return register(currentSerializer(), implementations, GLOBAL); } @Override - public Registration registerRpcImplementations(final ClassToInstanceMap> implementations, + public Registration registerRpcImplementations(final Collection> implementations, final Set> paths) { final var serializer = currentSerializer(); return register(serializer, implementations, toYangInstanceIdentifiers(serializer, paths)); } - private > Registration register(final CurrentAdapterSerializer serializer, + @Override + @Deprecated(since = "13.0.1") + public Registration registerRpcImplementations(final ClassToInstanceMap> implementations) { + return registerRpcImplementations(implementations.values()); + } + + @Override + @Deprecated(since = "13.0.1") + public Registration registerRpcImplementations(final ClassToInstanceMap> implementations, + final Set> paths) { + return registerRpcImplementations(implementations.values(), paths); + } + + private > @NonNull Registration register(final CurrentAdapterSerializer serializer, final T implementation, final Collection rpcContextPaths) { - @SuppressWarnings("unchecked") - final var type = (Class) implementation.implementedInterface(); - return register(serializer, ImmutableClassToInstanceMap.of(type, implementation), rpcContextPaths); + return register(serializer, List.of(implementation), rpcContextPaths); } - private Registration register(final CurrentAdapterSerializer serializer, - final ClassToInstanceMap> implementations, + private @NonNull Registration register(final CurrentAdapterSerializer serializer, + final Collection> implementations, // Note: unique items are implied final Collection rpcContextPaths) { final var context = serializer.getRuntimeContext(); - return register(implementations, rpcContextPaths, (type, impl) -> { + return register(implementations, rpcContextPaths, impl -> { + final var type = impl.implementedInterface(); final var def = context.getRpcDefinition(type); if (def == null) { throw new IllegalArgumentException("Cannot resolve YANG definition of " + type); @@ -85,12 +96,12 @@ public class BindingDOMRpcProviderServiceAdapter extends AbstractBindingAdapter< }); } - private @NonNull Registration register(final Map map, final Collection paths, - final BiFunction implFactory) { - final var builder = ImmutableMap.builderWithExpectedSize(map.size()); - for (var entry : map.entrySet()) { - final var impl = implFactory.apply(entry.getKey(), entry.getValue()); - paths.forEach(path -> builder.put(DOMRpcIdentifier.create(impl.qname, path), impl.impl)); + private @NonNull Registration register(final Collection impls, + final Collection paths, final Function implFactory) { + final var builder = ImmutableMap.builderWithExpectedSize(impls.size()); + for (var impl : impls) { + final var proxyImpl = implFactory.apply(impl); + paths.forEach(path -> builder.put(DOMRpcIdentifier.create(proxyImpl.qname, path), proxyImpl.impl)); } return getDelegate().registerRpcImplementations(builder.build()); } @@ -98,7 +109,7 @@ public class BindingDOMRpcProviderServiceAdapter extends AbstractBindingAdapter< private static Collection toYangInstanceIdentifiers( final CurrentAdapterSerializer serializer, final Set> identifiers) { final var ret = new ArrayList(identifiers.size()); - for (final InstanceIdentifier binding : identifiers) { + for (var binding : identifiers) { ret.add(serializer.toCachedYangInstanceIdentifier(binding)); } return ret;