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