Change RpcImplementation contract to asynchronous
[controller.git] / opendaylight / md-sal / sal-dom-api / src / main / java / org / opendaylight / controller / sal / core / api / RpcImplementation.java
1 /*
2  * Copyright (c) 2013 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.core.api;
9
10 import java.util.Set;
11
12 import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession;
13 import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.common.RpcResult;
16 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
17
18 import com.google.common.util.concurrent.ListenableFuture;
19
20 /**
21  * {@link Provider}'s implementation of an RPC.
22  *
23  * In order to expose an RPC to other components, the provider MUST register
24  * a concrete implementation of this interface.
25  *
26  * The registration could be done by :
27  * <ul>
28  * <li>returning an instance of implementation in the return value of
29  * {@link Provider#getProviderFunctionality()}
30  * <li>passing an instance of implementation and {@link QName} of rpc as
31  * arguments to the
32  * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)}
33  * </ul>
34  *
35  * The simplified process of the invocation of rpc is following:
36  *
37  * <ol>
38  * <li> {@link Consumer} invokes
39  * {@link ConsumerSession#rpc(QName, CompositeNode)}
40  * <li> {@link Broker} finds registered {@link RpcImplementation}s
41  * <li> {@link Broker} invokes
42  * {@link RpcImplementation#invokeRpc(QName, CompositeNode)}
43  * <li> {@link RpcImplementation} processes the data and returns a
44  * {@link RpcResult}
45  * <li> {@link Broker} returns the {@link RpcResult} to {@link Consumer}
46  * </ol>
47  */
48 public interface RpcImplementation extends Provider.ProviderFunctionality {
49
50     /**
51      * A set of rpc types supported by implementation.
52      *
53      * The set of rpc {@link QName}s which are supported by this implementation.
54      * This set is used, when {@link Provider} is registered to the SAL, to
55      * register and expose the implementation of the returned rpcs.
56      *
57      * @return Set of QNames identifying supported RPCs
58      */
59     Set<QName> getSupportedRpcs();
60
61     /**
62      * Invokes a implementation of specified RPC asynchronously.
63      *
64      * @param rpc
65      *            RPC to be invoked
66      * @param input
67      *            Input data for the RPC.
68      *
69      * @throws IllegalArgumentException
70      *             <ul>
71      *             <li>If rpc is null.
72      *             <li>If input is not <code>null</code> and
73      *             <code>false == rpc.equals(input.getNodeType)</code>
74      *             </ul>
75      * @return Future promising an RpcResult containing the output of
76      *         the RPC if was executed successfully, the list of errors
77      *         otherwise.
78      */
79     ListenableFuture<RpcResult<CompositeNode>> invokeRpc(QName rpc, CompositeNode input);
80 }