Merge "Adding some more traces for better debuggability"
[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     public <T extends Notification> Registration<NotificationListener<T>> registerNotificationListener(
76             Class<T> notificationType, NotificationListener<T> listener) {
77         return getNotificationBrokerChecked().registerNotificationListener(notificationType, listener);
78     }
79
80     @Override
81     public Registration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(
82             org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
83         return getNotificationBrokerChecked().registerNotificationListener(listener);
84     }
85
86     @Override
87     public DataModificationTransaction beginTransaction() {
88         return getDataBrokerChecked().beginTransaction();
89     }
90
91     @Override
92     @Deprecated
93     public DataObject readConfigurationData(InstanceIdentifier<? extends DataObject> path) {
94         return getDataBrokerChecked().readConfigurationData(path);
95     }
96
97     @Override
98     public DataObject readOperationalData(InstanceIdentifier<? extends DataObject> path) {
99         return getDataBrokerChecked().readOperationalData(path);
100     }
101
102     @Override
103     @Deprecated
104     public ListenerRegistration<DataChangeListener> registerDataChangeListener(
105             InstanceIdentifier<? extends DataObject> path, DataChangeListener listener) {
106         return getDataBrokerChecked().registerDataChangeListener(path, listener);
107     }
108 }