Merge "BUG-832 Refactor netconf connector"
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / sal / binding / impl / GenericNotificationRegistration.java
1 /**
2  * Copyright (c) 2013 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.AbstractObjectRegistration;
12 import org.opendaylight.yangtools.concepts.ListenerRegistration;
13 import org.opendaylight.yangtools.yang.binding.Notification;
14
15 import com.google.common.base.Preconditions;
16
17 class GenericNotificationRegistration<T extends Notification> extends AbstractObjectRegistration<NotificationListener<T>> implements ListenerRegistration<NotificationListener<T>> {
18     private final Class<T> type;
19     private NotificationBrokerImpl notificationBroker;
20
21     public GenericNotificationRegistration(final Class<T> type, final NotificationListener<T> instance, final NotificationBrokerImpl broker) {
22         super(instance);
23         this.type = Preconditions.checkNotNull(type);
24         this.notificationBroker = Preconditions.checkNotNull(broker);
25     }
26
27     public Class<T> getType() {
28         return type;
29     }
30
31     @Override
32     protected void removeRegistration() {
33         notificationBroker.unregisterListener(this);
34         notificationBroker = null;
35     }
36 }