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 java.util.concurrent.Future;
12 import org.opendaylight.controller.sal.binding.api.NotificationListener;
13 import org.opendaylight.controller.sal.binding.api.NotificationService;
14 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
15 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
16 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
17 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
18 import org.opendaylight.controller.sal.common.DataStoreIdentifier;
19 import org.opendaylight.yangtools.concepts.ListenerRegistration;
20 import org.opendaylight.yangtools.concepts.Registration;
21 import org.opendaylight.yangtools.yang.binding.DataObject;
22 import org.opendaylight.yangtools.yang.binding.DataRoot;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.opendaylight.yangtools.yang.binding.Notification;
25 import org.opendaylight.yangtools.yang.binding.RpcService;
26 import org.opendaylight.yangtools.yang.common.RpcResult;
28 import com.google.common.base.Preconditions;
30 public abstract class AbstractBindingSalConsumerInstance<D extends DataBrokerService, N extends NotificationService, R extends RpcConsumerRegistry> //
32 RpcConsumerRegistry, //
33 NotificationService, //
36 private final R rpcRegistry;
37 private final N notificationBroker;
38 private final D dataBroker;
40 protected final R getRpcRegistry() {
44 protected final N getNotificationBroker() {
45 return notificationBroker;
48 protected final D getDataBroker() {
52 protected final R getRpcRegistryChecked() {
53 Preconditions.checkState(rpcRegistry != null,"Rpc Registry is not available.");
57 protected final N getNotificationBrokerChecked() {
58 Preconditions.checkState(notificationBroker != null,"Notification Broker is not available.");
59 return notificationBroker;
62 protected final D getDataBrokerChecked() {
63 Preconditions.checkState(dataBroker != null, "Data Broker is not available");
68 protected AbstractBindingSalConsumerInstance(R rpcRegistry, N notificationBroker, D dataBroker) {
69 this.rpcRegistry = rpcRegistry;
70 this.notificationBroker = notificationBroker;
71 this.dataBroker = dataBroker;
75 public <T extends RpcService> T getRpcService(Class<T> module) {
76 return getRpcRegistryChecked().getRpcService(module);
81 public <T extends Notification> void addNotificationListener(Class<T> notificationType,
82 NotificationListener<T> listener) {
83 getNotificationBrokerChecked().addNotificationListener(notificationType, listener);
88 public void addNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
89 getNotificationBrokerChecked().addNotificationListener(listener);
94 public void removeNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
95 getNotificationBrokerChecked().removeNotificationListener(listener);
100 public <T extends Notification> void removeNotificationListener(Class<T> notificationType,
101 NotificationListener<T> listener) {
102 getNotificationBrokerChecked().removeNotificationListener(notificationType, listener);
106 public <T extends Notification> Registration<NotificationListener<T>> registerNotificationListener(
107 Class<T> notificationType, NotificationListener<T> listener) {
108 return getNotificationBrokerChecked().registerNotificationListener(notificationType, listener);
112 public Registration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(
113 org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
114 return getNotificationBrokerChecked().registerNotificationListener(listener);
119 public <T extends DataRoot> T getData(DataStoreIdentifier store, Class<T> rootType) {
120 return getDataBrokerChecked().getData(store, rootType);
125 public <T extends DataRoot> T getData(DataStoreIdentifier store, T filter) {
126 return getDataBrokerChecked().getData(store, filter);
131 public <T extends DataRoot> T getCandidateData(DataStoreIdentifier store, Class<T> rootType) {
132 return getDataBrokerChecked().getCandidateData(store, rootType);
137 public <T extends DataRoot> T getCandidateData(DataStoreIdentifier store, T filter) {
138 return getDataBrokerChecked().getCandidateData(store, filter);
143 public RpcResult<DataRoot> editCandidateData(DataStoreIdentifier store, DataRoot changeSet) {
144 return getDataBrokerChecked().editCandidateData(store, changeSet);
149 public Future<RpcResult<Void>> commit(DataStoreIdentifier store) {
150 return getDataBrokerChecked().commit(store);
155 public DataObject getData(InstanceIdentifier<? extends DataObject> data) {
156 return getDataBrokerChecked().getData(data);
161 public DataObject getConfigurationData(InstanceIdentifier<?> data) {
162 return getDataBrokerChecked().getConfigurationData(data);
166 public DataModificationTransaction beginTransaction() {
167 return getDataBrokerChecked().beginTransaction();
172 public void registerChangeListener(InstanceIdentifier<? extends DataObject> path, DataChangeListener changeListener) {
173 getDataBrokerChecked().registerChangeListener(path, changeListener);
178 public void unregisterChangeListener(InstanceIdentifier<? extends DataObject> path,
179 DataChangeListener changeListener) {
180 getDataBrokerChecked().unregisterChangeListener(path, changeListener);
185 public DataObject readConfigurationData(InstanceIdentifier<? extends DataObject> path) {
186 return getDataBrokerChecked().readConfigurationData(path);
190 public DataObject readOperationalData(InstanceIdentifier<? extends DataObject> path) {
191 return getDataBrokerChecked().readOperationalData(path);
196 public ListenerRegistration<DataChangeListener> registerDataChangeListener(
197 InstanceIdentifier<? extends DataObject> path, DataChangeListener listener) {
198 return getDataBrokerChecked().registerDataChangeListener(path, listener);