Deprecate all MD-SAL APIs
[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 @Deprecated
19 public abstract class AbstractBindingSalConsumerInstance<N extends NotificationService, R extends RpcConsumerRegistry>
20         implements RpcConsumerRegistry, NotificationService {
21
22     private final R rpcRegistry;
23     private final N notificationBroker;
24
25     protected final R getRpcRegistry() {
26         return rpcRegistry;
27     }
28
29     protected final N getNotificationBroker() {
30         return notificationBroker;
31     }
32
33     protected final R getRpcRegistryChecked() {
34         Preconditions.checkState(rpcRegistry != null,"Rpc Registry is not available.");
35         return rpcRegistry;
36     }
37
38     protected final N getNotificationBrokerChecked() {
39         Preconditions.checkState(notificationBroker != null,"Notification Broker is not available.");
40         return notificationBroker;
41     }
42
43     protected AbstractBindingSalConsumerInstance(R rpcRegistry, N notificationBroker) {
44         this.rpcRegistry = rpcRegistry;
45         this.notificationBroker = notificationBroker;
46     }
47
48     @Override
49     public <T extends RpcService> T getRpcService(Class<T> module) {
50         return getRpcRegistryChecked().getRpcService(module);
51     }
52
53     @Override
54     public <T extends Notification> ListenerRegistration<NotificationListener<T>> registerNotificationListener(
55             Class<T> notificationType, NotificationListener<T> listener) {
56         return getNotificationBrokerChecked().registerNotificationListener(notificationType, listener);
57     }
58
59     @Override
60     public ListenerRegistration<org.opendaylight.yangtools.yang.binding.NotificationListener>
61             registerNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
62         return getNotificationBrokerChecked().registerNotificationListener(listener);
63     }
64 }