Take advantage of default methods in DOMRpcProviderService
[controller.git] / opendaylight / md-sal / sal-dom-api / src / main / java / org / opendaylight / controller / md / sal / dom / api / DOMRpcProviderService.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.md.sal.dom.api;
9
10 import com.google.common.collect.ImmutableSet;
11 import java.util.Set;
12 import javax.annotation.Nonnull;
13
14 /**
15  * A {@link DOMService} which allows registration of RPC implementations with a conceptual router. The client
16  * counterpart of this service is {@link DOMRpcService}.
17  *
18  * <p>
19  * This interface supports both RFC6020 RPCs and RFC7950 actions (formerly known as 'Routed RPCs'. Invocation for
20  * RFC6020 RPCs is always based on an empty context reference. Invocation of actions requires a non-empty context
21  * reference and is matched against registered implementations as follows:
22  * <ul>
23  *     <li>First, attempt to look up the implementation based on exact match. If a match is found the invocation is
24  *         on that implementation, returning its result.</li>
25  *     <li>Second, attempt to look up the implementation which registered for empty context reference. If a such an
26  *         implementation exists, invoke that implementation, returning its result</li>
27  *     <li>Throw {@link DOMRpcImplementationNotAvailableException}
28  * </ul>
29  *
30  * <p>
31  * All implementations are required to perform these steps as specified above.
32  */
33 public interface DOMRpcProviderService extends DOMService {
34     /**
35      * Register an {@link DOMRpcImplementation} object with this service.
36      *
37      * @param implementation RPC implementation, must not be null
38      * @param rpcs Array of supported RPC identifiers. Must not be null, empty, or contain a null element.
39      *             Each identifier is added exactly once, no matter how many times it occurs.
40      * @return A {@link DOMRpcImplementationRegistration} object, guaranteed to be non-null.
41      * @throws NullPointerException if implementation or types is null
42      * @throws IllegalArgumentException if types is empty or contains a null element.
43      */
44     default @Nonnull <T extends DOMRpcImplementation> DOMRpcImplementationRegistration<T> registerRpcImplementation(
45             @Nonnull final T implementation, @Nonnull final DOMRpcIdentifier... rpcs) {
46         return registerRpcImplementation(implementation, ImmutableSet.copyOf(rpcs));
47     }
48
49     /**
50      * Register an {@link DOMRpcImplementation} object with this service.
51      *
52      * @param implementation RPC implementation, must not be null
53      * @param rpcs Set of supported RPC identifiers. Must not be null, empty, or contain a null element.
54      * @return A {@link DOMRpcImplementationRegistration} object, guaranteed to be non-null.
55      * @throws NullPointerException if implementation or types is null
56      * @throws IllegalArgumentException if types is empty or contains a null element.
57      */
58     @Nonnull <T extends DOMRpcImplementation> DOMRpcImplementationRegistration<T> registerRpcImplementation(
59             @Nonnull T implementation, @Nonnull Set<DOMRpcIdentifier> rpcs);
60 }