Fix Netty replication components
[mdsal.git] / replicate / mdsal-replicate-netty / src / main / java / org / opendaylight / mdsal / replicate / netty / NettyReplicationSource.java
index f94a4717c6a49a297ea3416e8fb3bbb416a8ad52..dc17e792462fec00c48d83546fe09ba57b7f0224 100644 (file)
@@ -14,10 +14,10 @@ import java.time.Duration;
 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
-import org.opendaylight.yangtools.concepts.AbstractRegistration;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
 import org.osgi.service.component.annotations.Reference;
 import org.osgi.service.metatype.annotations.AttributeDefinition;
 import org.osgi.service.metatype.annotations.Designate;
@@ -54,15 +54,10 @@ public final class NettyReplicationSource {
     @Reference
     private ClusterSingletonServiceProvider singletonService;
 
-    private static final class Disabled extends AbstractRegistration {
-        @Override
-        protected void removeRegistration() {
-            // no-op
-        }
-    }
-
-    private NettyReplicationSource() {
+    private Registration reg;
 
+    public NettyReplicationSource() {
+        // Visible for DI
     }
 
     @Activate
@@ -73,6 +68,12 @@ public final class NettyReplicationSource {
                 keepaliveInterval, config.maxMissedKeepalives());
     }
 
+    @Deactivate
+    void deactivate() {
+        reg.close();
+        reg = null;
+    }
+
     static Registration createSource(final BootstrapSupport bootstrap, final DOMDataBroker broker,
                                     final ClusterSingletonServiceProvider singleton, final boolean enabled,
                                     final int listenPort, final Duration keepaliveInterval,
@@ -82,6 +83,6 @@ public final class NettyReplicationSource {
         verify(dtcs != null, "Missing DOMDataTreeChangeService in broker %s", broker);
         checkArgument(maxMissedKeepalives > 0, "max-missed-keepalives %s must be greater than 0", maxMissedKeepalives);
         return enabled ? singleton.registerClusterSingletonService(new SourceSingletonService(bootstrap,
-                dtcs, listenPort, keepaliveInterval, maxMissedKeepalives)) : new Disabled();
+                dtcs, listenPort, keepaliveInterval, maxMissedKeepalives)) : new NoOpRegistration();
     }
 }