2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.binding.api;
10 import org.opendaylight.yangtools.yang.binding.RpcService;
13 * Provides access to registered Remote Procedure Call (RPC) service implementations. The RPCs are
14 * defined in YANG models.
16 * RPC implementations are registered using the {@link RpcProviderRegistry}.
19 public interface RpcConsumerRegistry extends BindingAwareService {
21 * Returns an implementation of a requested RPC service.
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.
29 * The following describes the behavior of the proxy when invoking RPC methods:
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.
39 * The returned proxy is automatically updated with the most recent
40 * registered implementation.
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.
52 * final Future<RpcResult<SomeRpcOutput>> future = someRpcService.someRpc( ... );
53 * Futures.addCallback(JdkFutureAdapters.listenInThreadPool(future), new FutureCallback<RpcResult<SomeRpcOutput>>() {
55 * public void onSuccess(RpcResult<SomeRpcOutput> result) {
56 * // process result ...
59 * public void onFailure(Throwable t) {
64 * @param serviceInterface the interface of the RPC Service. Typically this is an interface generated
66 * @return the proxy for the requested RPC service. This method never returns null.
68 <T extends RpcService> T getRpcService(Class<T> serviceInterface);