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 com.google.common.base.Preconditions;
11 import org.opendaylight.controller.sal.binding.api.NotificationListener;
12 import org.opendaylight.controller.sal.binding.api.NotificationService;
13 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
14 import org.opendaylight.yangtools.concepts.ListenerRegistration;
15 import org.opendaylight.yangtools.yang.binding.Notification;
16 import org.opendaylight.yangtools.yang.binding.RpcService;
19 public abstract class AbstractBindingSalConsumerInstance<N extends NotificationService, R extends RpcConsumerRegistry>
20 implements RpcConsumerRegistry, NotificationService {
22 private final R rpcRegistry;
23 private final N notificationBroker;
25 protected final R getRpcRegistry() {
29 protected final N getNotificationBroker() {
30 return notificationBroker;
33 protected final R getRpcRegistryChecked() {
34 Preconditions.checkState(rpcRegistry != null,"Rpc Registry is not available.");
38 protected final N getNotificationBrokerChecked() {
39 Preconditions.checkState(notificationBroker != null,"Notification Broker is not available.");
40 return notificationBroker;
43 protected AbstractBindingSalConsumerInstance(R rpcRegistry, N notificationBroker) {
44 this.rpcRegistry = rpcRegistry;
45 this.notificationBroker = notificationBroker;
49 public <T extends RpcService> T getRpcService(Class<T> module) {
50 return getRpcRegistryChecked().getRpcService(module);
54 public <T extends Notification> ListenerRegistration<NotificationListener<T>> registerNotificationListener(
55 Class<T> notificationType, NotificationListener<T> listener) {
56 return getNotificationBrokerChecked().registerNotificationListener(notificationType, listener);
60 public ListenerRegistration<org.opendaylight.yangtools.yang.binding.NotificationListener>
61 registerNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
62 return getNotificationBrokerChecked().registerNotificationListener(listener);