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.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.opendaylight.yangtools.yang.binding.Notification;
20 import org.opendaylight.yangtools.yang.binding.RpcService;
22 import com.google.common.base.Preconditions;
24 public abstract class AbstractBindingSalConsumerInstance<D extends DataBrokerService, N extends NotificationService, R extends RpcConsumerRegistry> //
26 RpcConsumerRegistry, //
27 NotificationService, //
30 private final R rpcRegistry;
31 private final N notificationBroker;
32 private final D dataBroker;
34 protected final R getRpcRegistry() {
38 protected final N getNotificationBroker() {
39 return notificationBroker;
42 protected final D getDataBroker() {
46 protected final R getRpcRegistryChecked() {
47 Preconditions.checkState(rpcRegistry != null,"Rpc Registry is not available.");
51 protected final N getNotificationBrokerChecked() {
52 Preconditions.checkState(notificationBroker != null,"Notification Broker is not available.");
53 return notificationBroker;
56 protected final D getDataBrokerChecked() {
57 Preconditions.checkState(dataBroker != null, "Data Broker is not available");
62 protected AbstractBindingSalConsumerInstance(R rpcRegistry, N notificationBroker, D dataBroker) {
63 this.rpcRegistry = rpcRegistry;
64 this.notificationBroker = notificationBroker;
65 this.dataBroker = dataBroker;
69 public <T extends RpcService> T getRpcService(Class<T> module) {
70 return getRpcRegistryChecked().getRpcService(module);
74 public <T extends Notification> ListenerRegistration<NotificationListener<T>> registerNotificationListener(
75 Class<T> notificationType, NotificationListener<T> listener) {
76 return getNotificationBrokerChecked().registerNotificationListener(notificationType, listener);
80 public ListenerRegistration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(
81 org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
82 return getNotificationBrokerChecked().registerNotificationListener(listener);
86 public DataModificationTransaction beginTransaction() {
87 return getDataBrokerChecked().beginTransaction();
92 public DataObject readConfigurationData(InstanceIdentifier<? extends DataObject> path) {
93 return getDataBrokerChecked().readConfigurationData(path);
97 public DataObject readOperationalData(InstanceIdentifier<? extends DataObject> path) {
98 return getDataBrokerChecked().readOperationalData(path);
103 public ListenerRegistration<DataChangeListener> registerDataChangeListener(
104 InstanceIdentifier<? extends DataObject> path, DataChangeListener listener) {
105 return getDataBrokerChecked().registerDataChangeListener(path, listener);