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