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