package org.opendaylight.mdsal.binding.api;
import com.google.common.collect.ClassToInstanceMap;
+import com.google.common.collect.ImmutableClassToInstanceMap;
+import java.util.Collection;
+import java.util.List;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Registration;
*/
@NonNull Registration registerRpcImplementation(Rpc<?, ?> implementation, Set<InstanceIdentifier<?>> paths);
+ /**
+ * Register a set of {@link Rpc} implementations.
+ *
+ * @param implementations implementation objects
+ * @return A {@link Registration} controlling unregistration
+ * @throws NullPointerException if {@code implementations} is, or contains, {@code null}
+ * @throws IllegalArgumentException if there are implementations contains {@link Rpc#implementedInterface()}
+ * duplicates
+ */
+ default @NonNull Registration registerRpcImplementations(final Rpc<?, ?>... implementations) {
+ return registerRpcImplementations(List.of(implementations));
+ }
+
+ /**
+ * Register a set of {@link Rpc} implementations.
+ *
+ * @param implementations implementation objects
+ * @return A {@link Registration} controlling unregistration
+ * @throws NullPointerException if {@code implementations} is, or contains, {@code null}
+ * @throws IllegalArgumentException if there are implementations contains {@link Rpc#implementedInterface()}
+ * duplicates
+ */
+ default @NonNull Registration registerRpcImplementations(final Collection<Rpc<?, ?>> implementations) {
+ return registerRpcImplementations(indexImplementations(implementations));
+ }
+
+ /**
+ * Register a set of {@link Rpc} implementations on a set of datastore context paths. Note that this method does not
+ * support registering multiple implementations of the same {@link Rpc} and hence we require specifying them through
+ * a {@link ClassToInstanceMap}.
+ *
+ * @param implementations implementation objects
+ * @return A {@link Registration} controlling unregistration
+ * @throws NullPointerException if any argument is, or contains, {@code null}
+ * @throws IllegalArgumentException if there are implementations contains {@link Rpc#implementedInterface()}
+ * duplicates
+ */
+ default @NonNull Registration registerRpcImplementations(final Collection<Rpc<?, ?>> implementations,
+ final Set<InstanceIdentifier<?>> paths) {
+ return registerRpcImplementations(indexImplementations(implementations), paths);
+ }
+
/**
* Register a set of {@link Rpc} implementations. Note that this method does not support registering multiple
* implementations of the same {@link Rpc} and hence we require specifying them through a
*/
@NonNull Registration registerRpcImplementations(ClassToInstanceMap<Rpc<?, ?>> implementations,
Set<InstanceIdentifier<?>> paths);
+
+ @SuppressWarnings("unchecked")
+ private static @NonNull ImmutableClassToInstanceMap<Rpc<?, ?>> indexImplementations(
+ final Collection<Rpc<?, ?>> impls) {
+ final var builder = ImmutableClassToInstanceMap.<Rpc<?, ?>>builder();
+ for (var impl : impls) {
+ builder.put((Class<Rpc<?, ?>>) impl.implementedInterface(), impl);
+ }
+ return builder.build();
+ }
}
package org.opendaylight.mdsal.binding.dom.adapter.osgi;
import com.google.common.collect.ClassToInstanceMap;
+import java.util.Collection;
import java.util.Map;
import java.util.Set;
import org.opendaylight.mdsal.binding.api.RpcProviderService;
return delegate.registerRpcImplementation(implementation, paths);
}
+ @Override
+ public Registration registerRpcImplementations(final Collection<Rpc<?, ?>> implementations) {
+ return delegate.registerRpcImplementations(implementations);
+ }
+
+ @Override
+ public Registration registerRpcImplementations(final Collection<Rpc<?, ?>> implementations,
+ final Set<InstanceIdentifier<?>> paths) {
+ return delegate.registerRpcImplementations(implementations, paths);
+ }
+
@Override
public Registration registerRpcImplementations(final ClassToInstanceMap<Rpc<?, ?>> implementations) {
return delegate.registerRpcImplementations(implementations);