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