Update to MD-SAL APIs
[controller.git] / opendaylight / md-sal / sal-binding-api / src / main / java / org / opendaylight / controller / sal / binding / api / BindingAwareBroker.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.binding.api;
9
10 import org.opendaylight.controller.md.sal.common.api.routing.RoutedRegistration;
11 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider.ProviderFunctionality;
12 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
13 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
14 import org.opendaylight.yangtools.concepts.Registration;
15 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17 import org.opendaylight.yangtools.yang.binding.RpcService;
18 import org.osgi.framework.BundleContext;
19
20 /**
21  * Binding-aware core of the SAL layer responsible for wiring the SAL consumers.
22  * 
23  * The responsibility of the broker is to maintain registration of SAL
24  * functionality {@link Consumer}s and {@link Provider}s, store provider and
25  * consumer specific context and functionality registration via
26  * {@link ConsumerContext} and provide access to infrastructure services, which
27  * removes direct dependencies between providers and consumers.
28  * 
29  * The Binding-aware broker is also responsible for translation from Java
30  * classes modeling the functionality and data to binding-indpenedent form which
31  * is used in SAL Core.
32  * 
33  * 
34  * <h3>Infrastructure services</h3> Some examples of infrastructure services:
35  * 
36  * <ul>
37  * <li>YANG Module service - see {@link ConsumerContext#getRpcService(Class)},
38  * {@link ProviderContext}
39  * <li>Notification Service - see {@link NotificationService} and
40  * {@link NotificationProviderService}
41  * <li>Functionality and Data model
42  * <li>Data Store access and modification - see {@link DataBrokerService} and
43  * {@link DataProviderService}
44  * </ul>
45  * 
46  * The services are exposed via session.
47  * 
48  * <h3>Session-based access</h3>
49  * 
50  * The providers and consumers needs to register in order to use the
51  * binding-independent SAL layer and to expose functionality via SAL layer.
52  * 
53  * For more information about session-based access see {@link ConsumerContext}
54  * and {@link ProviderContext}
55  * 
56  * 
57  * 
58  */
59 public interface BindingAwareBroker {
60     /**
61      * Registers the {@link BindingAwareConsumer}, which will use the SAL layer.
62      * 
63      * <p>
64      * Note that consumer could register additional functionality at later point
65      * by using service and functionality specific APIs.
66      * 
67      * <p>
68      * The consumer is required to use returned session for all communication
69      * with broker or one of the broker services. The session is announced to
70      * the consumer by invoking
71      * {@link Consumer#onSessionInitiated(ConsumerContext)}.
72      * 
73      * @param cons
74      *            Consumer to be registered.
75      * @return a session specific to consumer registration
76      * @throws IllegalArgumentException
77      *             If the consumer is <code>null</code>.
78      * @throws IllegalStateException
79      *             If the consumer is already registered.
80      */
81     ConsumerContext registerConsumer(BindingAwareConsumer consumer, BundleContext ctx);
82
83     /**
84      * Registers the {@link BindingAwareProvider}, which will use the SAL layer.
85      * 
86      * <p>
87      * During the registration, the broker obtains the initial functionality
88      * from consumer, using the
89      * {@link BindingAwareProvider#getImplementations()}, and register that
90      * functionality into system and concrete infrastructure services.
91      * 
92      * <p>
93      * Note that provider could register additional functionality at later point
94      * by using service and functionality specific APIs.
95      * 
96      * <p>
97      * The consumer is <b>required to use</b> returned session for all
98      * communication with broker or one of the broker services. The session is
99      * announced to the consumer by invoking
100      * {@link BindingAwareProvider#onSessionInitiated(ProviderContext)}.
101      * 
102      * 
103      * @param prov
104      *            Provider to be registered.
105      * @return a session unique to the provider registration.
106      * @throws IllegalArgumentException
107      *             If the provider is <code>null</code>.
108      * @throws IllegalStateException
109      *             If the consumer is already registered.
110      */
111     ProviderContext registerProvider(BindingAwareProvider provider, BundleContext ctx);
112
113     /**
114      * {@link BindingAwareConsumer} specific access to the SAL functionality.
115      * 
116      * <p>
117      * ConsumerSession is {@link BindingAwareConsumer}-specific access to the
118      * SAL functionality and infrastructure services.
119      * 
120      * <p>
121      * The session serves to store SAL context (e.g. registration of
122      * functionality) for the consumer and provides access to the SAL
123      * infrastructure services and other functionality provided by
124      * {@link Provider}s.
125      * 
126      * 
127      * 
128      */
129     public interface ConsumerContext {
130
131         /**
132          * Returns a session specific instance (implementation) of requested
133          * binding-aware infrastructural service
134          * 
135          * @param service
136          *            Broker service
137          * @return Session specific implementation of service
138          */
139         <T extends BindingAwareService> T getSALService(Class<T> service);
140
141         /**
142          * Returns a session specific instance (implementation) of requested
143          * YANG module implentation / service provided by consumer.
144          * 
145          * @param service
146          *            Broker service
147          * @return Session specific implementation of service
148          */
149         <T extends RpcService> T getRpcService(Class<T> module);
150     }
151
152     /**
153      * {@link BindingAwareProvider} specific access to the SAL functionality.
154      * 
155      * <p>
156      * ProviderSession is {@link BindingAwareProvider}-specific access to the
157      * SAL functionality and infrastructure services, which also allows for
158      * exposing the provider's functionality to the other
159      * {@link BindingAwareConsumer}s.
160      * 
161      * <p>
162      * The session serves to store SAL context (e.g. registration of
163      * functionality) for the providers and exposes access to the SAL
164      * infrastructure services, dynamic functionality registration and any other
165      * functionality provided by other {@link BindingAwareConsumer}s.
166      * 
167      */
168     public interface ProviderContext extends ConsumerContext {
169         /**
170          * Registers an global RpcService implementation.
171          * 
172          * @param type
173          * @param implementation
174          * @return
175          */
176         <T extends RpcService> RpcRegistration<T> addRpcImplementation(Class<T> type, T implementation)
177                 throws IllegalStateException;
178
179         <T extends RpcService> RpcRegistration<T> addMountRpcImplementation(Class<T> type, InstanceIdentifier<?> mount,
180                 T implementation) throws IllegalStateException;
181
182         <T extends RpcService> RoutedRpcRegistration<T> addRoutedRpcImplementation(Class<T> type, T implementation)
183                 throws IllegalStateException;
184
185         void registerFunctionality(ProviderFunctionality functionality);
186
187         void unregisterFunctionality(ProviderFunctionality functionality);
188     }
189
190     public interface RpcRegistration<T extends RpcService> extends Registration<T> {
191
192         /**
193          * 
194          * @return instance for which registration does exists.
195          */
196         @Deprecated
197         T getService();
198     }
199
200     public interface RoutedRpcRegistration<T extends RpcService> extends RpcRegistration<T>,
201             RoutedRegistration<Class<? extends BaseIdentity>, InstanceIdentifier<?>, T> {
202
203         /**
204          * Register particular instance identifier to be processed by this
205          * RpcService
206          * 
207          * Deprecated in favor of {@link RoutedRegistration#registerPath(Object, Object)}. 
208          * 
209          * @param context
210          * @param instance
211          */
212         @Deprecated
213         void registerInstance(Class<? extends BaseIdentity> context, InstanceIdentifier<?> instance);
214
215         @Deprecated
216         void unregisterInstance(Class<? extends BaseIdentity> context, InstanceIdentifier<?> instance);
217     }
218 }