2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.md.sal.binding.util;
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;
23 import com.google.common.base.Preconditions;
25 public abstract class AbstractBindingSalConsumerInstance<D extends DataBrokerService, N extends NotificationService, R extends RpcConsumerRegistry> //
27 RpcConsumerRegistry, //
28 NotificationService, //
31 private final R rpcRegistry;
32 private final N notificationBroker;
33 private final D dataBroker;
35 protected final R getRpcRegistry() {
39 protected final N getNotificationBroker() {
40 return notificationBroker;
43 protected final D getDataBroker() {
47 protected final R getRpcRegistryChecked() {
48 Preconditions.checkState(rpcRegistry != null,"Rpc Registry is not available.");
52 protected final N getNotificationBrokerChecked() {
53 Preconditions.checkState(notificationBroker != null,"Notification Broker is not available.");
54 return notificationBroker;
57 protected final D getDataBrokerChecked() {
58 Preconditions.checkState(dataBroker != null, "Data Broker is not available");
63 protected AbstractBindingSalConsumerInstance(R rpcRegistry, N notificationBroker, D dataBroker) {
64 this.rpcRegistry = rpcRegistry;
65 this.notificationBroker = notificationBroker;
66 this.dataBroker = dataBroker;
70 public <T extends RpcService> T getRpcService(Class<T> module) {
71 return getRpcRegistryChecked().getRpcService(module);
76 public <T extends Notification> void addNotificationListener(Class<T> notificationType,
77 NotificationListener<T> listener) {
78 getNotificationBrokerChecked().addNotificationListener(notificationType, listener);
83 public void addNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
84 getNotificationBrokerChecked().addNotificationListener(listener);
89 public void removeNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
90 getNotificationBrokerChecked().removeNotificationListener(listener);
95 public <T extends Notification> void removeNotificationListener(Class<T> notificationType,
96 NotificationListener<T> listener) {
97 getNotificationBrokerChecked().removeNotificationListener(notificationType, listener);
101 public <T extends Notification> Registration<NotificationListener<T>> registerNotificationListener(
102 Class<T> notificationType, NotificationListener<T> listener) {
103 return getNotificationBrokerChecked().registerNotificationListener(notificationType, listener);
107 public Registration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(
108 org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
109 return getNotificationBrokerChecked().registerNotificationListener(listener);
113 public DataModificationTransaction beginTransaction() {
114 return getDataBrokerChecked().beginTransaction();
119 public DataObject readConfigurationData(InstanceIdentifier<? extends DataObject> path) {
120 return getDataBrokerChecked().readConfigurationData(path);
124 public DataObject readOperationalData(InstanceIdentifier<? extends DataObject> path) {
125 return getDataBrokerChecked().readOperationalData(path);
130 public ListenerRegistration<DataChangeListener> registerDataChangeListener(
131 InstanceIdentifier<? extends DataObject> path, DataChangeListener listener) {
132 return getDataBrokerChecked().registerDataChangeListener(path, listener);