1 package org.opendaylight.controller.md.sal.binding.util;
3 import java.util.concurrent.Future;
4 import java.util.zip.Checksum;
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;
27 import com.google.common.base.Preconditions;
29 public abstract class AbstractBindingSalConsumerInstance<D extends DataBrokerService, N extends NotificationService, R extends RpcConsumerRegistry> //
31 RpcConsumerRegistry, //
32 NotificationService, //
35 private final R rpcRegistry;
36 private final N notificationBroker;
37 private final D dataBroker;
39 protected final R getRpcRegistry() {
43 protected final N getNotificationBroker() {
44 return notificationBroker;
47 protected final D getDataBroker() {
51 protected final R getRpcRegistryChecked() {
52 Preconditions.checkState(rpcRegistry != null,"Rpc Registry is not available.");
56 protected final N getNotificationBrokerChecked() {
57 Preconditions.checkState(notificationBroker != null,"Notification Broker is not available.");
58 return notificationBroker;
61 protected final D getDataBrokerChecked() {
62 Preconditions.checkState(dataBroker != null, "Data Broker is not available");
67 protected AbstractBindingSalConsumerInstance(R rpcRegistry, N notificationBroker, D dataBroker) {
68 this.rpcRegistry = rpcRegistry;
69 this.notificationBroker = notificationBroker;
70 this.dataBroker = dataBroker;
73 public <T extends RpcService> T getRpcService(Class<T> module) {
74 return getRpcRegistryChecked().getRpcService(module);
78 public <T extends Notification> void addNotificationListener(Class<T> notificationType,
79 NotificationListener<T> listener) {
80 getNotificationBrokerChecked().addNotificationListener(notificationType, listener);
84 public void addNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
85 getNotificationBrokerChecked().addNotificationListener(listener);
89 public void removeNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
90 getNotificationBrokerChecked().removeNotificationListener(listener);
94 public <T extends Notification> void removeNotificationListener(Class<T> notificationType,
95 NotificationListener<T> listener) {
96 getNotificationBrokerChecked().removeNotificationListener(notificationType, listener);
99 public <T extends Notification> Registration<NotificationListener<T>> registerNotificationListener(
100 Class<T> notificationType, NotificationListener<T> listener) {
101 return getNotificationBrokerChecked().registerNotificationListener(notificationType, listener);
104 public Registration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(
105 org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
106 return getNotificationBrokerChecked().registerNotificationListener(listener);
110 public <T extends DataRoot> T getData(DataStoreIdentifier store, Class<T> rootType) {
111 return getDataBrokerChecked().getData(store, rootType);
115 public <T extends DataRoot> T getData(DataStoreIdentifier store, T filter) {
116 return getDataBrokerChecked().getData(store, filter);
120 public <T extends DataRoot> T getCandidateData(DataStoreIdentifier store, Class<T> rootType) {
121 return getDataBrokerChecked().getCandidateData(store, rootType);
125 public <T extends DataRoot> T getCandidateData(DataStoreIdentifier store, T filter) {
126 return getDataBrokerChecked().getCandidateData(store, filter);
130 public RpcResult<DataRoot> editCandidateData(DataStoreIdentifier store, DataRoot changeSet) {
131 return getDataBrokerChecked().editCandidateData(store, changeSet);
135 public Future<RpcResult<Void>> commit(DataStoreIdentifier store) {
136 return getDataBrokerChecked().commit(store);
140 public DataObject getData(InstanceIdentifier<? extends DataObject> data) {
141 return getDataBrokerChecked().getData(data);
145 public DataObject getConfigurationData(InstanceIdentifier<?> data) {
146 return getDataBrokerChecked().getConfigurationData(data);
149 public DataModificationTransaction beginTransaction() {
150 return getDataBrokerChecked().beginTransaction();
154 public void registerChangeListener(InstanceIdentifier<? extends DataObject> path, DataChangeListener changeListener) {
155 getDataBrokerChecked().registerChangeListener(path, changeListener);
159 public void unregisterChangeListener(InstanceIdentifier<? extends DataObject> path,
160 DataChangeListener changeListener) {
161 getDataBrokerChecked().unregisterChangeListener(path, changeListener);
165 public DataObject readConfigurationData(InstanceIdentifier<? extends DataObject> path) {
166 return getDataBrokerChecked().readConfigurationData(path);
169 public DataObject readOperationalData(InstanceIdentifier<? extends DataObject> path) {
170 return getDataBrokerChecked().readOperationalData(path);
174 public ListenerRegistration<DataChangeListener> registerDataChangeListener(
175 InstanceIdentifier<? extends DataObject> path, DataChangeListener listener) {
176 return getDataBrokerChecked().registerDataChangeListener(path, listener);