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