2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.core.api;
10 import java.util.concurrent.Future;
12 import org.opendaylight.controller.sal.core.api.data.DataBrokerService;
13 import org.opendaylight.controller.sal.core.api.data.DataProviderService;
14 import org.opendaylight.controller.sal.core.api.notify.NotificationProviderService;
15 import org.opendaylight.controller.sal.core.api.notify.NotificationService;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.common.RpcResult;
18 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
22 * Core component of the SAL layer responsible for wiring the SAL consumers.
24 * The responsibility of the broker is to maintain registration of SAL
25 * functionality {@link Consumer}s and {@link Provider}s, store provider and
26 * consumer specific context and functionality registration via
27 * {@link ConsumerSession} and provide access to infrastructure services, which
28 * removes direct dependencies between providers and consumers.
31 * <h3>Infrastructure services</h3> Some examples of infrastructure services:
34 * <li>RPC Invocation - see {@link ConsumerSession#rpc(QName, CompositeNode)},
35 * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)} and
36 * {@link RpcImplementation}
37 * <li>Notification Service - see {@link NotificationService} and
38 * {@link NotificationProviderService}
39 * <li>Functionality and Data model
40 * <li>Data Store access and modification - see {@link DataBrokerService} and
41 * {@link DataProviderService}
44 * The services are exposed via session.
46 * <h3>Session-based access</h3>
48 * The providers and consumers needs to register in order to use the
49 * binding-independent SAL layer and to expose functionality via SAL layer.
51 * For more information about session-based access see {@link ConsumerSession}
52 * and {@link ProviderSession}
57 public interface Broker {
60 * Registers the {@link Consumer}, which will use the SAL layer.
63 * During the registration, the broker obtains the initial functionality
64 * from consumer, using the {@link Consumer#getConsumerFunctionality()}, and
65 * register that functionality into system and concrete infrastructure
69 * Note that consumer could register additional functionality at later point
70 * by using service and functionality specific APIs.
73 * The consumer is required to use returned session for all communication
74 * with broker or one of the broker services. The session is announced to
75 * the consumer by invoking
76 * {@link Consumer#onSessionInitiated(ConsumerSession)}.
79 * Consumer to be registered.
80 * @return a session specific to consumer registration
81 * @throws IllegalArgumentException
82 * If the consumer is <code>null</code>.
83 * @throws IllegalStateException
84 * If the consumer is already registered.
86 ConsumerSession registerConsumer(Consumer cons);
89 * Registers the {@link Provider}, which will use the SAL layer.
92 * During the registration, the broker obtains the initial functionality
93 * from consumer, using the {@link Provider#getProviderFunctionality()}, and
94 * register that functionality into system and concrete infrastructure
98 * Note that consumer could register additional functionality at later point
99 * by using service and functionality specific APIs (e.g.
100 * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)}
103 * The consumer is <b>required to use</b> returned session for all
104 * communication with broker or one of the broker services. The session is
105 * announced to the consumer by invoking
106 * {@link Provider#onSessionInitiated(ProviderSession)}.
110 * Provider to be registered.
111 * @return a session unique to the provider registration.
112 * @throws IllegalArgumentException
113 * If the provider is <code>null</code>.
114 * @throws IllegalStateException
115 * If the consumer is already registered.
117 ProviderSession registerProvider(Provider prov);
120 * {@link Consumer} specific access to the SAL functionality.
123 * ConsumerSession is {@link Consumer}-specific access to the SAL
124 * functionality and infrastructure services.
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
135 public interface ConsumerSession {
138 * Sends an RPC to other components registered to the broker.
140 * @see RpcImplementation
144 * Input data to the RPC
145 * @return Result of the RPC call
147 Future<RpcResult<CompositeNode>> rpc(QName rpc, CompositeNode input);
152 * Returns a session specific instance (implementation) of requested
157 * @return Session specific implementation of service
159 <T extends BrokerService> T getService(Class<T> service);
162 * Closes a session between consumer and broker.
165 * The close operation unregisters a consumer and remove all registered
166 * functionality of the consumer from the system.
173 * {@link Provider} specific access to the SAL functionality.
176 * ProviderSession is {@link Provider}-specific access to the SAL
177 * functionality and infrastructure services, which also allows for exposing
178 * the provider's functionality to the other {@link Consumer}s.
181 * The session serves to store SAL context (e.g. registration of
182 * functionality) for the providers and exposes access to the SAL
183 * infrastructure services, dynamic functionality registration and any other
184 * functionality provided by other {@link Provider}s.
187 public interface ProviderSession extends ConsumerSession {
189 * Registers an implementation of the rpc.
192 * The registered rpc functionality will be available to all other
193 * consumers and providers registered to the broker, which are aware of
194 * the {@link QName} assigned to the rpc.
197 * There is no assumption that rpc type is in the set returned by
198 * invoking {@link RpcImplementation#getSupportedRpcs()}. This allows
199 * for dynamic rpc implementations.
203 * @param implementation
204 * Provider's Implementation of the RPC functionality
205 * @throws IllegalArgumentException
206 * If the name of RPC is invalid
208 void addRpcImplementation(QName rpcType,
209 RpcImplementation implementation)
210 throws IllegalArgumentException;
213 * Unregisters an Rpc implementation
217 * @param implementation
218 * Registered Implementation of the Rpc functionality
219 * @throws IllegalArgumentException
221 void removeRpcImplementation(QName rpcType,
222 RpcImplementation implementation)
223 throws IllegalArgumentException;
226 * Closes a session between provider and SAL.
229 * The close operation unregisters a provider and remove all registered
230 * functionality of the provider from the system.