Merge "Fix for Bug 3"
[controller.git] / opendaylight / md-sal / sal-binding-util / src / main / java / org / opendaylight / controller / md / sal / binding / util / AbstractBindingSalConsumerInstance.java
1 package org.opendaylight.controller.md.sal.binding.util;
2
3 import java.util.concurrent.Future;
4 import java.util.zip.Checksum;
5
6 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
7 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
8 import org.opendaylight.controller.sal.binding.api.NotificationListener;
9 import org.opendaylight.controller.sal.binding.api.NotificationService;
10 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
11 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
12 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
13 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
14 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
15 import org.opendaylight.controller.sal.binding.api.mount.MountInstance;
16 import org.opendaylight.controller.sal.common.DataStoreIdentifier;
17 import org.opendaylight.yangtools.concepts.Identifiable;
18 import org.opendaylight.yangtools.concepts.ListenerRegistration;
19 import org.opendaylight.yangtools.concepts.Registration;
20 import org.opendaylight.yangtools.yang.binding.DataObject;
21 import org.opendaylight.yangtools.yang.binding.DataRoot;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.opendaylight.yangtools.yang.binding.Notification;
24 import org.opendaylight.yangtools.yang.binding.RpcService;
25 import org.opendaylight.yangtools.yang.common.RpcResult;
26
27 import com.google.common.base.Preconditions;
28
29 public abstract class AbstractBindingSalConsumerInstance<D extends DataBrokerService, N extends NotificationService, R extends RpcConsumerRegistry> //
30         implements //
31         RpcConsumerRegistry, //
32         NotificationService, //
33         DataBrokerService {
34
35     private final R rpcRegistry;
36     private final N notificationBroker;
37     private final D dataBroker;
38
39     protected final R getRpcRegistry() {
40         return rpcRegistry;
41     }
42
43     protected final N getNotificationBroker() {
44         return notificationBroker;
45     }
46
47     protected final D getDataBroker() {
48         return dataBroker;
49     }
50     
51     protected final R getRpcRegistryChecked() {
52         Preconditions.checkState(rpcRegistry != null,"Rpc Registry is not available.");
53         return rpcRegistry;
54     }
55
56     protected final N getNotificationBrokerChecked() {
57         Preconditions.checkState(notificationBroker != null,"Notification Broker is not available.");
58         return notificationBroker;
59     }
60
61     protected final D getDataBrokerChecked() {
62         Preconditions.checkState(dataBroker != null, "Data Broker is not available");
63         return dataBroker;
64     }
65     
66
67     protected AbstractBindingSalConsumerInstance(R rpcRegistry, N notificationBroker, D dataBroker) {
68         this.rpcRegistry = rpcRegistry;
69         this.notificationBroker = notificationBroker;
70         this.dataBroker = dataBroker;
71     }
72
73     public <T extends RpcService> T getRpcService(Class<T> module) {
74         return getRpcRegistryChecked().getRpcService(module);
75     }
76
77     @Deprecated
78     public <T extends Notification> void addNotificationListener(Class<T> notificationType,
79             NotificationListener<T> listener) {
80         getNotificationBrokerChecked().addNotificationListener(notificationType, listener);
81     }
82
83     @Deprecated
84     public void addNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
85         getNotificationBrokerChecked().addNotificationListener(listener);
86     }
87
88     @Deprecated
89     public void removeNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
90         getNotificationBrokerChecked().removeNotificationListener(listener);
91     }
92
93     @Deprecated
94     public <T extends Notification> void removeNotificationListener(Class<T> notificationType,
95             NotificationListener<T> listener) {
96         getNotificationBrokerChecked().removeNotificationListener(notificationType, listener);
97     }
98
99     public <T extends Notification> Registration<NotificationListener<T>> registerNotificationListener(
100             Class<T> notificationType, NotificationListener<T> listener) {
101         return getNotificationBrokerChecked().registerNotificationListener(notificationType, listener);
102     }
103
104     public Registration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(
105             org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
106         return getNotificationBrokerChecked().registerNotificationListener(listener);
107     }
108
109     @Deprecated
110     public <T extends DataRoot> T getData(DataStoreIdentifier store, Class<T> rootType) {
111         return getDataBrokerChecked().getData(store, rootType);
112     }
113
114     @Deprecated
115     public <T extends DataRoot> T getData(DataStoreIdentifier store, T filter) {
116         return getDataBrokerChecked().getData(store, filter);
117     }
118
119     @Deprecated
120     public <T extends DataRoot> T getCandidateData(DataStoreIdentifier store, Class<T> rootType) {
121         return getDataBrokerChecked().getCandidateData(store, rootType);
122     }
123
124     @Deprecated
125     public <T extends DataRoot> T getCandidateData(DataStoreIdentifier store, T filter) {
126         return getDataBrokerChecked().getCandidateData(store, filter);
127     }
128
129     @Deprecated
130     public RpcResult<DataRoot> editCandidateData(DataStoreIdentifier store, DataRoot changeSet) {
131         return getDataBrokerChecked().editCandidateData(store, changeSet);
132     }
133
134     @Deprecated
135     public Future<RpcResult<Void>> commit(DataStoreIdentifier store) {
136         return getDataBrokerChecked().commit(store);
137     }
138
139     @Deprecated
140     public DataObject getData(InstanceIdentifier<? extends DataObject> data) {
141         return getDataBrokerChecked().getData(data);
142     }
143
144     @Deprecated
145     public DataObject getConfigurationData(InstanceIdentifier<?> data) {
146         return getDataBrokerChecked().getConfigurationData(data);
147     }
148
149     public DataModificationTransaction beginTransaction() {
150         return getDataBrokerChecked().beginTransaction();
151     }
152
153     @Deprecated
154     public void registerChangeListener(InstanceIdentifier<? extends DataObject> path, DataChangeListener changeListener) {
155         getDataBrokerChecked().registerChangeListener(path, changeListener);
156     }
157
158     @Deprecated
159     public void unregisterChangeListener(InstanceIdentifier<? extends DataObject> path,
160             DataChangeListener changeListener) {
161         getDataBrokerChecked().unregisterChangeListener(path, changeListener);
162     }
163
164     @Deprecated
165     public DataObject readConfigurationData(InstanceIdentifier<? extends DataObject> path) {
166         return getDataBrokerChecked().readConfigurationData(path);
167     }
168
169     public DataObject readOperationalData(InstanceIdentifier<? extends DataObject> path) {
170         return getDataBrokerChecked().readOperationalData(path);
171     }
172
173     @Deprecated
174     public ListenerRegistration<DataChangeListener> registerDataChangeListener(
175             InstanceIdentifier<? extends DataObject> path, DataChangeListener listener) {
176         return getDataBrokerChecked().registerDataChangeListener(path, listener);
177     }
178 }