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