Annotate mdsal-binding-api with @NonNull
[mdsal.git] / binding / mdsal-binding-api / src / main / java / org / opendaylight / mdsal / binding / api / RpcConsumerRegistry.java
1 /*
2  * Copyright (c) 2014 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.mdsal.binding.api;
9
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.yangtools.yang.binding.RpcService;
12
13 /**
14  * Provides access to registered Remote Procedure Call (RPC) service implementations. The RPCs are
15  * defined in YANG models.
16  *
17  * <p>
18  * RPC implementations are registered using the {@link RpcProviderService}.
19  *
20  */
21 public interface RpcConsumerRegistry extends BindingService {
22     /**
23      * Returns an implementation of a requested RPC service.
24      *
25      * <p>
26      * The returned instance is not an actual implementation of the RPC service interface, but a
27      * proxy implementation of the interface that forwards to an actual implementation, if any.
28      *
29      * <p>
30      * The following describes the behavior of the proxy when invoking RPC methods:
31      * <ul>
32      * <li>If an actual implementation is registered with the MD-SAL, all invocations are forwarded
33      * to the registered implementation.</li>
34      * <li>If no actual implementation is registered, all invocations will fail by throwing
35      * {@link IllegalStateException}.</li>
36      * <li>Prior to invoking the actual implementation, the method arguments are are validated. If
37      * any are invalid, an {@link IllegalArgumentException} is thrown.
38      * </ul>
39      *
40      * The returned proxy is automatically updated with the most recent registered implementation.
41      *
42      * <p>
43      * The generated RPC method APIs require implementors to return a
44      * {@link java.util.concurrent.Future Future} instance that wraps the
45      * {@link org.opendaylight.yangtools.yang.common.RpcResult RpcResult}. Since RPC methods may be
46      * implemented asynchronously, callers should avoid blocking on the
47      * {@link java.util.concurrent.Future Future} result. Instead, it is recommended to use
48      * {@link com.google.common.util.concurrent.JdkFutureAdapters#listenInPoolThread(java.util.concurrent.Future)}
49      * or
50      * {@link com.google.common.util.concurrent.JdkFutureAdapters#listenInPoolThread(java.util.concurrent.Future,
51      * java.util.concurrent.Executor)} to listen for Rpc Result. This will asynchronously listen for future result
52      * in executor and will not block current thread.
53      *
54      * <pre>
55      *   final Future&lt;RpcResult&lt;SomeRpcOutput&gt;&gt; future = someRpcService.someRpc( ... );
56      *   Futures.addCallback(JdkFutureAdapters.listenInThreadPool(future), new FutureCallback&lt;RpcResult&lt;
57      *   SomeRpcOutput&gt;&gt;() {
58      *
59      *       public void onSuccess(RpcResult&lt;SomeRpcOutput&gt; result) {
60      *          // process result ...
61      *       }
62      *
63      *       public void onFailure(Throwable t) {
64      *          // RPC failed
65      *       }
66      *   );
67      * </pre>
68      *
69      * @param serviceInterface the interface of the RPC Service. Typically this is an interface
70      *        generated from a YANG model.
71      * @return the proxy for the requested RPC service. This method never returns null.
72      */
73     <T extends RpcService> @NonNull T getRpcService(@NonNull Class<T> serviceInterface);
74 }