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