2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.binding.api;
10 import com.google.common.collect.ClassToInstanceMap;
11 import com.google.common.collect.ImmutableClassToInstanceMap;
12 import java.util.Collection;
13 import java.util.List;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.yangtools.binding.DataObjectIdentifier;
17 import org.opendaylight.yangtools.binding.Rpc;
18 import org.opendaylight.yangtools.concepts.Registration;
21 * Provides ability to registered Remote Procedure Call (RPC) service implementations. The RPCs are defined in YANG
24 public interface RpcProviderService extends BindingService {
26 * Register an {@link Rpc} implementation.
28 * @param implementation implementation object
29 * @return A {@link Registration} controlling unregistration
30 * @throws NullPointerException if {@code implementation} is {@code null}
32 @NonNull Registration registerRpcImplementation(Rpc<?, ?> implementation);
35 * Register an {@link Rpc} implementation on a set of datastore context paths.
37 * @param implementation implementation object
38 * @param paths Datastore paths to service
39 * @return A {@link Registration} controlling unregistration
40 * @throws NullPointerException if any argument is {@code null}
42 @NonNull Registration registerRpcImplementation(Rpc<?, ?> implementation, Set<DataObjectIdentifier<?>> paths);
45 * Register a set of {@link Rpc} implementations.
47 * @param implementations implementation objects
48 * @return A {@link Registration} controlling unregistration
49 * @throws NullPointerException if {@code implementations} is, or contains, {@code null}
50 * @throws IllegalArgumentException if there are implementations contains {@link Rpc#implementedInterface()}
53 default @NonNull Registration registerRpcImplementations(final Rpc<?, ?>... implementations) {
54 return registerRpcImplementations(List.of(implementations));
58 * Register a set of {@link Rpc} implementations.
60 * @param implementations implementation objects
61 * @return A {@link Registration} controlling unregistration
62 * @throws NullPointerException if {@code implementations} is, or contains, {@code null}
63 * @throws IllegalArgumentException if there are implementations contains {@link Rpc#implementedInterface()}
66 default @NonNull Registration registerRpcImplementations(final Collection<Rpc<?, ?>> implementations) {
67 return registerRpcImplementations(indexImplementations(implementations));
71 * Register a set of {@link Rpc} implementations on a set of datastore context paths. Note that this method does not
72 * support registering multiple implementations of the same {@link Rpc} and hence we require specifying them through
73 * a {@link ClassToInstanceMap}.
75 * @param implementations implementation objects
76 * @return A {@link Registration} controlling unregistration
77 * @throws NullPointerException if any argument is, or contains, {@code null}
78 * @throws IllegalArgumentException if there are implementations contains {@link Rpc#implementedInterface()}
81 default @NonNull Registration registerRpcImplementations(final Collection<Rpc<?, ?>> implementations,
82 final Set<DataObjectIdentifier<?>> paths) {
83 return registerRpcImplementations(indexImplementations(implementations), paths);
87 * Register a set of {@link Rpc} implementations. Note that this method does not support registering multiple
88 * implementations of the same {@link Rpc} and hence we require specifying them through a
89 * {@link ClassToInstanceMap}.
91 * @param implementations implementation objects
92 * @return A {@link Registration} controlling unregistration
93 * @throws NullPointerException if {@code implementations} is {@code null}
94 * @deprecated Use {@link #registerRpcImplementations(Collection)} or {@link #registerRpcImplementations(Rpc...)}
97 @Deprecated(since = "13.0.1")
98 @NonNull Registration registerRpcImplementations(ClassToInstanceMap<Rpc<?, ?>> implementations);
101 * Register a set of {@link Rpc} implementations on a set of datastore context paths. Note that this method does not
102 * support registering multiple implementations of the same {@link Rpc} and hence we require specifying them through
103 * a {@link ClassToInstanceMap}.
105 * @param implementations implementation objects
106 * @return A {@link Registration} controlling unregistration
107 * @throws NullPointerException if any argument is {@code null}
108 * @deprecated Use {@link #registerRpcImplementations(Collection, Set)} instead
110 @Deprecated(since = "13.0.1")
111 @NonNull Registration registerRpcImplementations(ClassToInstanceMap<Rpc<?, ?>> implementations,
112 Set<DataObjectIdentifier<?>> paths);
114 @SuppressWarnings("unchecked")
115 private static @NonNull ImmutableClassToInstanceMap<Rpc<?, ?>> indexImplementations(
116 final Collection<Rpc<?, ?>> impls) {
117 final var builder = ImmutableClassToInstanceMap.<Rpc<?, ?>>builder();
118 for (var impl : impls) {
119 builder.put((Class<Rpc<?, ?>>) impl.implementedInterface(), impl);
121 return builder.build();