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;
18 public abstract class AbstractBindingSalConsumerInstance<N extends NotificationService, R extends RpcConsumerRegistry>
19 implements RpcConsumerRegistry, NotificationService {
21 private final R rpcRegistry;
22 private final N notificationBroker;
24 protected final R getRpcRegistry() {
28 protected final N getNotificationBroker() {
29 return notificationBroker;
32 protected final R getRpcRegistryChecked() {
33 Preconditions.checkState(rpcRegistry != null,"Rpc Registry is not available.");
37 protected final N getNotificationBrokerChecked() {
38 Preconditions.checkState(notificationBroker != null,"Notification Broker is not available.");
39 return notificationBroker;
42 protected AbstractBindingSalConsumerInstance(R rpcRegistry, N notificationBroker) {
43 this.rpcRegistry = rpcRegistry;
44 this.notificationBroker = notificationBroker;
48 public <T extends RpcService> T getRpcService(Class<T> module) {
49 return getRpcRegistryChecked().getRpcService(module);
53 public <T extends Notification> ListenerRegistration<NotificationListener<T>> registerNotificationListener(
54 Class<T> notificationType, NotificationListener<T> listener) {
55 return getNotificationBrokerChecked().registerNotificationListener(notificationType, listener);
59 public ListenerRegistration<org.opendaylight.yangtools.yang.binding.NotificationListener>
60 registerNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
61 return getNotificationBrokerChecked().registerNotificationListener(listener);