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);
75 public <T extends Notification> Registration<NotificationListener<T>> registerNotificationListener(
76 Class<T> notificationType, NotificationListener<T> listener) {
77 return getNotificationBrokerChecked().registerNotificationListener(notificationType, listener);
81 public Registration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(
82 org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
83 return getNotificationBrokerChecked().registerNotificationListener(listener);
87 public DataModificationTransaction beginTransaction() {
88 return getDataBrokerChecked().beginTransaction();
93 public DataObject readConfigurationData(InstanceIdentifier<? extends DataObject> path) {
94 return getDataBrokerChecked().readConfigurationData(path);
98 public DataObject readOperationalData(InstanceIdentifier<? extends DataObject> path) {
99 return getDataBrokerChecked().readOperationalData(path);
104 public ListenerRegistration<DataChangeListener> registerDataChangeListener(
105 InstanceIdentifier<? extends DataObject> path, DataChangeListener listener) {
106 return getDataBrokerChecked().registerDataChangeListener(path, listener);