Deprecate old MD-SAL APIs for removal
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / compat / AbstractNotificationListenerRegistration.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.compat;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.opendaylight.controller.sal.binding.api.NotificationListener;
13 import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
14 import org.opendaylight.yangtools.yang.binding.Notification;
15
16 /**
17  * Abstract implementation of {@link NotificationListenerRegistration}.
18  *
19  * @param <T> Notification type
20  */
21 @Deprecated(forRemoval = true)
22 abstract class AbstractNotificationListenerRegistration<T extends Notification>
23         extends AbstractListenerRegistration<NotificationListener<T>> implements NotificationListenerRegistration<T> {
24     private final Class<? extends Notification> type;
25
26     protected AbstractNotificationListenerRegistration(final Class<? extends Notification> type,
27             final NotificationListener<T> listener) {
28         super(listener);
29         this.type = requireNonNull(type);
30     }
31
32     @Override
33     public Class<? extends Notification> getType() {
34         return type;
35     }
36
37     @Override
38     @SuppressWarnings("unchecked")
39     public void notify(final Notification notification) {
40         if (!isClosed()) {
41             getInstance().onNotification((T)notification);
42         }
43     }
44 }