Merge "BUG-832 Refactor netconf connector"
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / sal / binding / impl / GeneratedListenerRegistration.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.spi.NotificationInvokerFactory.NotificationInvoker;
11 import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
12 import org.opendaylight.yangtools.concepts.ListenerRegistration;
13 import org.opendaylight.yangtools.yang.binding.NotificationListener;
14
15 import com.google.common.base.Preconditions;
16
17 class GeneratedListenerRegistration extends AbstractObjectRegistration<NotificationListener> implements ListenerRegistration<NotificationListener> {
18     private NotificationBrokerImpl notificationBroker;
19     private final NotificationInvoker invoker;
20
21     public GeneratedListenerRegistration(final NotificationListener instance, final NotificationInvoker invoker, final NotificationBrokerImpl broker) {
22         super(instance);
23         this.invoker = Preconditions.checkNotNull(invoker);
24         this.notificationBroker = Preconditions.checkNotNull(broker);
25     }
26
27     public NotificationInvoker getInvoker() {
28         // There is a race with NotificationBrokerImpl:
29         // the invoker can be closed here
30         return invoker;
31     }
32
33     @Override
34     protected void removeRegistration() {
35         notificationBroker.unregisterListener(this);
36         notificationBroker = null;
37         invoker.close();
38     }
39 }