db20a13991f8356acf88b3212c4722356aa70fc1
[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 extends RpcConsumerRegistry {
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     }
143
144     /**
145      * {@link BindingAwareProvider} specific access to the SAL functionality.
146      * 
147      * <p>
148      * ProviderSession is {@link BindingAwareProvider}-specific access to the
149      * SAL functionality and infrastructure services, which also allows for
150      * exposing the provider's functionality to the other
151      * {@link BindingAwareConsumer}s.
152      * 
153      * <p>
154      * The session serves to store SAL context (e.g. registration of
155      * functionality) for the providers and exposes access to the SAL
156      * infrastructure services, dynamic functionality registration and any other
157      * functionality provided by other {@link BindingAwareConsumer}s.
158      * 
159      */
160     public interface ProviderContext extends ConsumerContext, RpcProviderRegistry {
161
162         @Deprecated
163         void registerFunctionality(ProviderFunctionality functionality);
164
165         @Deprecated
166         void unregisterFunctionality(ProviderFunctionality functionality);
167     }
168
169     public interface RpcRegistration<T extends RpcService> extends Registration<T> {
170
171         Class<T> getServiceType();
172     }
173
174     public interface RoutedRpcRegistration<T extends RpcService> extends RpcRegistration<T>,
175             RoutedRegistration<Class<? extends BaseIdentity>, InstanceIdentifier<?>, T> {
176
177         /**
178          * Register particular instance identifier to be processed by this
179          * RpcService
180          * 
181          * Deprecated in favor of {@link RoutedRegistration#registerPath(Object, Object)}. 
182          * 
183          * @param context
184          * @param instance
185          */
186         @Deprecated
187         void registerInstance(Class<? extends BaseIdentity> context, InstanceIdentifier<?> instance);
188
189         /**
190          * Unregister particular instance identifier to be processed by this
191          * RpcService
192          * 
193          * Deprecated in favor of {@link RoutedRegistration#unregisterPath(Object, Object)}. 
194          * 
195          * @param context
196          * @param instance
197          */
198         @Deprecated
199         void unregisterInstance(Class<? extends BaseIdentity> context, InstanceIdentifier<?> instance);
200     }
201 }