71b6593bb74734cd7d352c9161f02e137e080ce1
[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 com.google.common.base.Preconditions;
11 import org.opendaylight.controller.sal.binding.api.NotificationListener;
12 import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
13 import org.opendaylight.yangtools.yang.binding.Notification;
14
15 /**
16  * Abstract implementation of {@link NotificationListenerRegistration}.
17  *
18  * @param <T> Notification type
19  */
20 @Deprecated
21 abstract class AbstractNotificationListenerRegistration<T extends Notification>
22         extends AbstractListenerRegistration<NotificationListener<T>> implements NotificationListenerRegistration<T> {
23     private final Class<? extends Notification> type;
24
25     protected AbstractNotificationListenerRegistration(final Class<? extends Notification> type,
26             final NotificationListener<T> listener) {
27         super(listener);
28         this.type = Preconditions.checkNotNull(type);
29     }
30
31     @Override
32     public Class<? extends Notification> getType() {
33         return type;
34     }
35
36     @Override
37     @SuppressWarnings("unchecked")
38     public void notify(final Notification notification) {
39         if (!isClosed()) {
40             getInstance().onNotification((T)notification);
41         }
42     }
43 }