Devices dashlet show port total numbers, modal shows collapsible list
[controller.git] / opendaylight / sal / yang-prototype / sal / sal-core-api / src / main / java / org / opendaylight / controller / sal / core / api / Broker.java
1 /*\r
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 package org.opendaylight.controller.sal.core.api;\r
9 \r
10 import java.util.concurrent.Future;\r
11 \r
12 import org.opendaylight.controller.sal.core.api.data.DataBrokerService;\r
13 import org.opendaylight.controller.sal.core.api.data.DataProviderService;\r
14 import org.opendaylight.controller.sal.core.api.notify.NotificationProviderService;\r
15 import org.opendaylight.controller.sal.core.api.notify.NotificationService;\r
16 import org.opendaylight.controller.yang.common.QName;\r
17 import org.opendaylight.controller.yang.common.RpcResult;\r
18 import org.opendaylight.controller.yang.data.api.CompositeNode;\r
19 \r
20 \r
21 /**\r
22  * Core component of the SAL layer responsible for wiring the SAL consumers.\r
23  * \r
24  * The responsibility of the broker is to maintain registration of SAL\r
25  * functionality {@link Consumer}s and {@link Provider}s, store provider and\r
26  * consumer specific context and functionality registration via\r
27  * {@link ConsumerSession} and provide access to infrastructure services, which\r
28  * removes direct dependencies between providers and consumers.\r
29  * \r
30  * \r
31  * <h3>Infrastructure services</h3> Some examples of infrastructure services:\r
32  * \r
33  * <ul>\r
34  * <li>RPC Invocation - see {@link ConsumerSession#rpc(QName, CompositeNode)},\r
35  * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)} and\r
36  * {@link RpcImplementation}\r
37  * <li>Notification Service - see {@link NotificationService} and\r
38  * {@link NotificationProviderService}\r
39  * <li>Functionality and Data model\r
40  * <li>Data Store access and modification - see {@link DataBrokerService} and\r
41  * {@link DataProviderService}\r
42  * </ul>\r
43  * \r
44  * The services are exposed via session.\r
45  * \r
46  * <h3>Session-based access</h3>\r
47  * \r
48  * The providers and consumers needs to register in order to use the\r
49  * binding-independent SAL layer and to expose functionality via SAL layer.\r
50  * \r
51  * For more information about session-based access see {@link ConsumerSession}\r
52  * and {@link ProviderSession}\r
53  * \r
54  * \r
55  * \r
56  */\r
57 public interface Broker {\r
58 \r
59     /**\r
60      * Registers the {@link Consumer}, which will use the SAL layer.\r
61      * \r
62      * <p>\r
63      * During the registration, the broker obtains the initial functionality\r
64      * from consumer, using the {@link Consumer#getConsumerFunctionality()}, and\r
65      * register that functionality into system and concrete infrastructure\r
66      * services.\r
67      * \r
68      * <p>\r
69      * Note that consumer could register additional functionality at later point\r
70      * by using service and functionality specific APIs.\r
71      * \r
72      * <p>\r
73      * The consumer is required to use returned session for all communication\r
74      * with broker or one of the broker services. The session is announced to\r
75      * the consumer by invoking\r
76      * {@link Consumer#onSessionInitiated(ConsumerSession)}.\r
77      * \r
78      * @param cons\r
79      *            Consumer to be registered.\r
80      * @return a session specific to consumer registration\r
81      * @throws IllegalArgumentException\r
82      *             If the consumer is <code>null</code>.\r
83      * @throws IllegalStateException\r
84      *             If the consumer is already registered.\r
85      */\r
86     ConsumerSession registerConsumer(Consumer cons);\r
87 \r
88     /**\r
89      * Registers the {@link Provider}, which will use the SAL layer.\r
90      * \r
91      * <p>\r
92      * During the registration, the broker obtains the initial functionality\r
93      * from consumer, using the {@link Provider#getProviderFunctionality()}, and\r
94      * register that functionality into system and concrete infrastructure\r
95      * services.\r
96      * \r
97      * <p>\r
98      * Note that consumer could register additional functionality at later point\r
99      * by using service and functionality specific APIs (e.g.\r
100      * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)}\r
101      * \r
102      * <p>\r
103      * The consumer is <b>required to use</b> returned session for all\r
104      * communication with broker or one of the broker services. The session is\r
105      * announced to the consumer by invoking\r
106      * {@link Provider#onSessionInitiated(ProviderSession)}.\r
107      * \r
108      * \r
109      * @param prov\r
110      *            Provider to be registered.\r
111      * @return a session unique to the provider registration.\r
112      * @throws IllegalArgumentException\r
113      *             If the provider is <code>null</code>.\r
114      * @throws IllegalStateException\r
115      *             If the consumer is already registered.\r
116      */\r
117     ProviderSession registerProvider(Provider prov);\r
118 \r
119     /**\r
120      * {@link Consumer} specific access to the SAL functionality.\r
121      * \r
122      * <p>\r
123      * ConsumerSession is {@link Consumer}-specific access to the SAL\r
124      * functionality and infrastructure services.\r
125      * \r
126      * <p>\r
127      * The session serves to store SAL context (e.g. registration of\r
128      * functionality) for the consumer and provides access to the SAL\r
129      * infrastructure services and other functionality provided by\r
130      * {@link Provider}s.\r
131      * \r
132 \r
133      * \r
134      */\r
135     public interface ConsumerSession {\r
136 \r
137         /**\r
138          * Sends an RPC to other components registered to the broker.\r
139          * \r
140          * @see RpcImplementation\r
141          * @param rpc\r
142          *            Name of RPC\r
143          * @param input\r
144          *            Input data to the RPC\r
145          * @return Result of the RPC call\r
146          */\r
147         Future<RpcResult<CompositeNode>> rpc(QName rpc, CompositeNode input);\r
148 \r
149         boolean isClosed();\r
150 \r
151         /**\r
152          * Returns a session specific instance (implementation) of requested\r
153          * service\r
154          * \r
155          * @param service\r
156          *            Broker service\r
157          * @return Session specific implementation of service\r
158          */\r
159         <T extends BrokerService> T getService(Class<T> service);\r
160 \r
161         /**\r
162          * Closes a session between consumer and broker.\r
163          * \r
164          * <p>\r
165          * The close operation unregisters a consumer and remove all registered\r
166          * functionality of the consumer from the system.\r
167          * \r
168          */\r
169         void close();\r
170     }\r
171 \r
172     /**\r
173      * {@link Provider} specific access to the SAL functionality.\r
174      * \r
175      * <p>\r
176      * ProviderSession is {@link Provider}-specific access to the SAL\r
177      * functionality and infrastructure services, which also allows for exposing\r
178      * the provider's functionality to the other {@link Consumer}s.\r
179      * \r
180      * <p>\r
181      * The session serves to store SAL context (e.g. registration of\r
182      * functionality) for the providers and exposes access to the SAL\r
183      * infrastructure services, dynamic functionality registration and any other\r
184      * functionality provided by other {@link Provider}s.\r
185      * \r
186      */\r
187     public interface ProviderSession extends ConsumerSession {\r
188         /**\r
189          * Registers an implementation of the rpc.\r
190          * \r
191          * <p>\r
192          * The registered rpc functionality will be available to all other\r
193          * consumers and providers registered to the broker, which are aware of\r
194          * the {@link QName} assigned to the rpc.\r
195          * \r
196          * <p>\r
197          * There is no assumption that rpc type is in the set returned by\r
198          * invoking {@link RpcImplementation#getSupportedRpcs()}. This allows\r
199          * for dynamic rpc implementations.\r
200          * \r
201          * @param rpcType\r
202          *            Name of Rpc\r
203          * @param implementation\r
204          *            Provider's Implementation of the RPC functionality\r
205          * @throws IllegalArgumentException\r
206          *             If the name of RPC is invalid\r
207          */\r
208         void addRpcImplementation(QName rpcType,\r
209                 RpcImplementation implementation)\r
210                 throws IllegalArgumentException;\r
211 \r
212         /**\r
213          * Unregisters an Rpc implementation\r
214          * \r
215          * @param rpcType\r
216          *            Name of Rpc\r
217          * @param implementation\r
218          *            Registered Implementation of the Rpc functionality\r
219          * @throws IllegalArgumentException\r
220          */\r
221         void removeRpcImplementation(QName rpcType,\r
222                 RpcImplementation implementation)\r
223                 throws IllegalArgumentException;\r
224 \r
225         /**\r
226          * Closes a session between provider and SAL.\r
227          * \r
228          * <p>\r
229          * The close operation unregisters a provider and remove all registered\r
230          * functionality of the provider from the system.\r
231          */\r
232         @Override\r
233         public void close();\r
234 \r
235         @Override\r
236         boolean isClosed();\r
237     }\r
238 }\r