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

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.