Fix checkstyle violations in sal-binding-util and sal-schema-service
[controller.git] / opendaylight / md-sal / sal-binding-util / src / main / java / org / opendaylight / controller / md / sal / binding / util / AbstractBindingSalConsumerInstance.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.md.sal.binding.util;
9
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;
17
18 public abstract class AbstractBindingSalConsumerInstance<N extends NotificationService, R extends RpcConsumerRegistry>
19         implements RpcConsumerRegistry, NotificationService {
20
21     private final R rpcRegistry;
22     private final N notificationBroker;
23
24     protected final R getRpcRegistry() {
25         return rpcRegistry;
26     }
27
28     protected final N getNotificationBroker() {
29         return notificationBroker;
30     }
31
32     protected final R getRpcRegistryChecked() {
33         Preconditions.checkState(rpcRegistry != null,"Rpc Registry is not available.");
34         return rpcRegistry;
35     }
36
37     protected final N getNotificationBrokerChecked() {
38         Preconditions.checkState(notificationBroker != null,"Notification Broker is not available.");
39         return notificationBroker;
40     }
41
42     protected AbstractBindingSalConsumerInstance(R rpcRegistry, N notificationBroker) {
43         this.rpcRegistry = rpcRegistry;
44         this.notificationBroker = notificationBroker;
45     }
46
47     @Override
48     public <T extends RpcService> T getRpcService(Class<T> module) {
49         return getRpcRegistryChecked().getRpcService(module);
50     }
51
52     @Override
53     public <T extends Notification> ListenerRegistration<NotificationListener<T>> registerNotificationListener(
54             Class<T> notificationType, NotificationListener<T> listener) {
55         return getNotificationBrokerChecked().registerNotificationListener(notificationType, listener);
56     }
57
58     @Override
59     public ListenerRegistration<org.opendaylight.yangtools.yang.binding.NotificationListener>
60             registerNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
61         return getNotificationBrokerChecked().registerNotificationListener(listener);
62     }
63 }