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;
11 import java.util.zip.Checksum;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
15 import org.opendaylight.controller.sal.binding.api.NotificationListener;
16 import org.opendaylight.controller.sal.binding.api.NotificationService;
17 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
18 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
19 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
20 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
21 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
22 import org.opendaylight.controller.sal.binding.api.mount.MountInstance;
23 import org.opendaylight.controller.sal.common.DataStoreIdentifier;
24 import org.opendaylight.yangtools.concepts.Identifiable;
25 import org.opendaylight.yangtools.concepts.ListenerRegistration;
26 import org.opendaylight.yangtools.concepts.Registration;
27 import org.opendaylight.yangtools.yang.binding.DataObject;
28 import org.opendaylight.yangtools.yang.binding.DataRoot;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.opendaylight.yangtools.yang.binding.Notification;
31 import org.opendaylight.yangtools.yang.binding.RpcService;
32 import org.opendaylight.yangtools.yang.common.RpcResult;
34 import com.google.common.base.Preconditions;
36 public abstract class AbstractBindingSalConsumerInstance<D extends DataBrokerService, N extends NotificationService, R extends RpcConsumerRegistry> //
38 RpcConsumerRegistry, //
39 NotificationService, //
42 private final R rpcRegistry;
43 private final N notificationBroker;
44 private final D dataBroker;
46 protected final R getRpcRegistry() {
50 protected final N getNotificationBroker() {
51 return notificationBroker;
54 protected final D getDataBroker() {
58 protected final R getRpcRegistryChecked() {
59 Preconditions.checkState(rpcRegistry != null,"Rpc Registry is not available.");
63 protected final N getNotificationBrokerChecked() {
64 Preconditions.checkState(notificationBroker != null,"Notification Broker is not available.");
65 return notificationBroker;
68 protected final D getDataBrokerChecked() {
69 Preconditions.checkState(dataBroker != null, "Data Broker is not available");
74 protected AbstractBindingSalConsumerInstance(R rpcRegistry, N notificationBroker, D dataBroker) {
75 this.rpcRegistry = rpcRegistry;
76 this.notificationBroker = notificationBroker;
77 this.dataBroker = dataBroker;
80 public <T extends RpcService> T getRpcService(Class<T> module) {
81 return getRpcRegistryChecked().getRpcService(module);
85 public <T extends Notification> void addNotificationListener(Class<T> notificationType,
86 NotificationListener<T> listener) {
87 getNotificationBrokerChecked().addNotificationListener(notificationType, listener);
91 public void addNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
92 getNotificationBrokerChecked().addNotificationListener(listener);
96 public void removeNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
97 getNotificationBrokerChecked().removeNotificationListener(listener);
101 public <T extends Notification> void removeNotificationListener(Class<T> notificationType,
102 NotificationListener<T> listener) {
103 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);
111 public Registration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(
112 org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
113 return getNotificationBrokerChecked().registerNotificationListener(listener);
117 public <T extends DataRoot> T getData(DataStoreIdentifier store, Class<T> rootType) {
118 return getDataBrokerChecked().getData(store, rootType);
122 public <T extends DataRoot> T getData(DataStoreIdentifier store, T filter) {
123 return getDataBrokerChecked().getData(store, filter);
127 public <T extends DataRoot> T getCandidateData(DataStoreIdentifier store, Class<T> rootType) {
128 return getDataBrokerChecked().getCandidateData(store, rootType);
132 public <T extends DataRoot> T getCandidateData(DataStoreIdentifier store, T filter) {
133 return getDataBrokerChecked().getCandidateData(store, filter);
137 public RpcResult<DataRoot> editCandidateData(DataStoreIdentifier store, DataRoot changeSet) {
138 return getDataBrokerChecked().editCandidateData(store, changeSet);
142 public Future<RpcResult<Void>> commit(DataStoreIdentifier store) {
143 return getDataBrokerChecked().commit(store);
147 public DataObject getData(InstanceIdentifier<? extends DataObject> data) {
148 return getDataBrokerChecked().getData(data);
152 public DataObject getConfigurationData(InstanceIdentifier<?> data) {
153 return getDataBrokerChecked().getConfigurationData(data);
156 public DataModificationTransaction beginTransaction() {
157 return getDataBrokerChecked().beginTransaction();
161 public void registerChangeListener(InstanceIdentifier<? extends DataObject> path, DataChangeListener changeListener) {
162 getDataBrokerChecked().registerChangeListener(path, changeListener);
166 public void unregisterChangeListener(InstanceIdentifier<? extends DataObject> path,
167 DataChangeListener changeListener) {
168 getDataBrokerChecked().unregisterChangeListener(path, changeListener);
172 public DataObject readConfigurationData(InstanceIdentifier<? extends DataObject> path) {
173 return getDataBrokerChecked().readConfigurationData(path);
176 public DataObject readOperationalData(InstanceIdentifier<? extends DataObject> path) {
177 return getDataBrokerChecked().readOperationalData(path);
181 public ListenerRegistration<DataChangeListener> registerDataChangeListener(
182 InstanceIdentifier<? extends DataObject> path, DataChangeListener listener) {
183 return getDataBrokerChecked().registerDataChangeListener(path, listener);