Merge "Fix bug #2569 XSQL delay controller load when in cluster env"
[controller.git] / opendaylight / md-sal / sal-binding-api / src / main / java / org / opendaylight / controller / sal / binding / api / BindingAwareProvider.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.sal.binding.api.BindingAwareBroker.ProviderContext;
11
12 /**
13  *
14  * A developer implemented component that gets registered with the Broker.
15  *
16  * Semantically, a provider may:
17  *
18  * <ol>
19  *   <li> Emit Notifications</li>
20  *   <li> Provide the implementation of RPCs </li>
21  *   <li> Write to the operational data tree </li>
22  * </ol>
23  *
24  * If a class is not doing at least one of those three, consider using
25  * a BindingAwareConsumer instead:
26  * @see org.opendaylight.controller.sal.binding.api.BindingAwareConsumer
27  *
28  * <p>
29  *
30  *In addition, a BindingAwareProvider can in pursuit of its goals:
31  *
32  * <ol>
33  *   <li>Subscribe for Notifications </li>
34  *   <li>Invoke RPCs</li>
35  *   <li>Read from either the operational or config data tree</li>
36  *   <li>Write to the config data tree</li>
37  * </ol>
38  * (All of the above are things a Consumer can also do).
39  *
40  *<p>
41  *
42  * Examples:
43  *
44  *<p>
45  *
46  * To get a NotificationService:
47  *
48  * {code
49  * public void onSessionInitiated(ProviderContext session) {
50  *      NotificationProviderService notificationService = session.getSALService(NotificationProviderService.class);
51  * }
52  * For more information on sending notifications via the NotificationProviderService
53  * @see org.opendaylight.controller.sal.binding.api.NotificationProviderService
54  *
55  * To register an RPC implementation:
56  *
57  * {code
58  * public void onSessionInitiated(ProviderContext session) {
59  *    RpcRegistration<MyService> registration = session.addRpcImplementation(MyService.class, myImplementationInstance);
60  * }
61  *
62  * <p>
63  *
64  * Where MyService.class is a Service interface generated from a yang model with RPCs modeled in it and myImplementationInstance
65  * is an instance of a class that implements MyService.
66  *
67  * To register a Routed RPC Implementation:
68  * {code
69  * public void onSessionInitiated(ProviderContext session) {
70  *   RoutedRpcRegistration<SalFlowService> flowRegistration = session.addRoutedRpcImplementation(SalFlowService.class, salFlowServiceImplementationInstance);
71      flowRegistration.registerPath(NodeContext.class, nodeInstanceId);
72  * }
73  * }
74  *
75  * Where SalFlowService.class is a Service interface generated from a yang model with RPCs modeled in it and salFlowServiceImplementationInstance is an instance
76  * of a class that implements SalFlowService.
77  * <p>
78  * The line:
79  * {code
80  * flowRegistration.registerPath(NodeContext.class, nodeInstanceId);
81  * }
82  * Is indicating that the RPC implementation is registered to handle RPC invocations that have their NodeContext pointing to the node with instance id nodeInstanceId.
83  * This bears a bit of further explanation.  RoutedRPCs can be 'routed' to an implementation based upon 'context'.  'context' is a pointer (instanceId) to some place
84  * in the data tree.  In this example, the 'context' is a pointer to a Node.  In this way, a provider can register its ability to provide a service for a particular
85  * Node, but not *all* Nodes.  The Broker routes the RPC by 'context' to the correct implementation, without the caller having to do extra work.  Because of this when
86  * a RoutedRPC is registered, it needs to also be able to indicate for which 'contexts' it is providing an implementation.
87  *
88  * An example of a Routed RPC would be an updateFlow(node, flow) that would be routed based on node to the provider which had registered to provide
89  * it *for that node*.
90  *
91  *<p>
92  *
93  * To get a DataBroker to allow access to the data tree:
94  *
95  * {code
96  * public void onSessionInitiated(final ProviderContext session) {
97  *      DataBroker databroker = session.getSALService(BindingDataBroker.class);
98  * }
99  * }
100  * @see org.opendaylight.controller.md.sal.common.api.data.BindingDataBroker
101  * for more info on using the DataBroker.
102  *
103  */
104 public interface BindingAwareProvider {
105
106     /**
107      * Callback signaling initialization of the consumer session to the SAL.
108      *
109      * The consumer MUST use the session for all communication with SAL or
110      * retrieving SAL infrastructure services.
111      *
112      * This method is invoked by
113      * {@link BindingAwareBroker#registerProvider(BindingAwareProvider)}
114      *
115      * @param session Unique session between consumer and SAL.
116      */
117     void onSessionInitiated(ProviderContext session);
118 }