Prune long-deprecated APIs
[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 org.opendaylight.controller.sal.binding.api.NotificationListener;
11 import org.opendaylight.controller.sal.binding.api.NotificationService;
12 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
13 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
14 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
15 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
16 import org.opendaylight.yangtools.concepts.ListenerRegistration;
17 import org.opendaylight.yangtools.concepts.Registration;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 import org.opendaylight.yangtools.yang.binding.Notification;
21 import org.opendaylight.yangtools.yang.binding.RpcService;
22
23 import com.google.common.base.Preconditions;
24
25 public abstract class AbstractBindingSalConsumerInstance<D extends DataBrokerService, N extends NotificationService, R extends RpcConsumerRegistry> //
26         implements //
27         RpcConsumerRegistry, //
28         NotificationService, //
29         DataBrokerService {
30
31     private final R rpcRegistry;
32     private final N notificationBroker;
33     private final D dataBroker;
34
35     protected final R getRpcRegistry() {
36         return rpcRegistry;
37     }
38
39     protected final N getNotificationBroker() {
40         return notificationBroker;
41     }
42
43     protected final D getDataBroker() {
44         return dataBroker;
45     }
46
47     protected final R getRpcRegistryChecked() {
48         Preconditions.checkState(rpcRegistry != null,"Rpc Registry is not available.");
49         return rpcRegistry;
50     }
51
52     protected final N getNotificationBrokerChecked() {
53         Preconditions.checkState(notificationBroker != null,"Notification Broker is not available.");
54         return notificationBroker;
55     }
56
57     protected final D getDataBrokerChecked() {
58         Preconditions.checkState(dataBroker != null, "Data Broker is not available");
59         return dataBroker;
60     }
61
62
63     protected AbstractBindingSalConsumerInstance(R rpcRegistry, N notificationBroker, D dataBroker) {
64         this.rpcRegistry = rpcRegistry;
65         this.notificationBroker = notificationBroker;
66         this.dataBroker = dataBroker;
67     }
68
69     @Override
70     public <T extends RpcService> T getRpcService(Class<T> module) {
71         return getRpcRegistryChecked().getRpcService(module);
72     }
73
74     @Override
75     @Deprecated
76     public <T extends Notification> void addNotificationListener(Class<T> notificationType,
77             NotificationListener<T> listener) {
78         getNotificationBrokerChecked().addNotificationListener(notificationType, listener);
79     }
80
81     @Override
82     @Deprecated
83     public void addNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
84         getNotificationBrokerChecked().addNotificationListener(listener);
85     }
86
87     @Override
88     @Deprecated
89     public void removeNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
90         getNotificationBrokerChecked().removeNotificationListener(listener);
91     }
92
93     @Override
94     @Deprecated
95     public <T extends Notification> void removeNotificationListener(Class<T> notificationType,
96             NotificationListener<T> listener) {
97         getNotificationBrokerChecked().removeNotificationListener(notificationType, listener);
98     }
99
100     @Override
101     public <T extends Notification> Registration<NotificationListener<T>> registerNotificationListener(
102             Class<T> notificationType, NotificationListener<T> listener) {
103         return getNotificationBrokerChecked().registerNotificationListener(notificationType, listener);
104     }
105
106     @Override
107     public Registration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(
108             org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
109         return getNotificationBrokerChecked().registerNotificationListener(listener);
110     }
111
112     @Override
113     public DataModificationTransaction beginTransaction() {
114         return getDataBrokerChecked().beginTransaction();
115     }
116
117     @Override
118     @Deprecated
119     public DataObject readConfigurationData(InstanceIdentifier<? extends DataObject> path) {
120         return getDataBrokerChecked().readConfigurationData(path);
121     }
122
123     @Override
124     public DataObject readOperationalData(InstanceIdentifier<? extends DataObject> path) {
125         return getDataBrokerChecked().readOperationalData(path);
126     }
127
128     @Override
129     @Deprecated
130     public ListenerRegistration<DataChangeListener> registerDataChangeListener(
131             InstanceIdentifier<? extends DataObject> path, DataChangeListener listener) {
132         return getDataBrokerChecked().registerDataChangeListener(path, listener);
133     }
134 }