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