NETVIRT-1630 migrate to md-sal APIs
[netvirt.git] / qosservice / impl / src / main / java / org / opendaylight / netvirt / qosservice / QosAlertConfigListener.java
index efaed3fd6e51dd73f80b1984517345e2e51064e8..bd45784052f9bd64d85988afe61959f7914caa09 100644 (file)
@@ -8,12 +8,13 @@
 
 package org.opendaylight.netvirt.qosservice;
 
-import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
+import org.opendaylight.infrautils.utils.concurrent.Executors;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.serviceutils.tools.listener.AbstractClusteredAsyncDataTreeChangeListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.qosalert.config.rev170301.QosalertConfig;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
@@ -21,8 +22,7 @@ import org.slf4j.LoggerFactory;
 
 
 @Singleton
-public class QosAlertConfigListener  extends
-        AsyncClusteredDataTreeChangeListenerBase<QosalertConfig, QosAlertConfigListener> {
+public class QosAlertConfigListener  extends AbstractClusteredAsyncDataTreeChangeListener<QosalertConfig> {
 
     private static final Logger LOG = LoggerFactory.getLogger(QosAlertConfigListener.class);
     private final DataBroker dataBroker;
@@ -30,45 +30,40 @@ public class QosAlertConfigListener  extends
 
     @Inject
     public QosAlertConfigListener(final DataBroker dataBroker, final QosAlertManager qosAlertManager) {
-        super(QosalertConfig.class, QosAlertConfigListener.class);
+        super(dataBroker, LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(QosalertConfig.class),
+                Executors.newListeningSingleThreadExecutor("QosAlertConfigListener", LOG));
         this.dataBroker = dataBroker;
         this.qosAlertManager = qosAlertManager;
-        LOG.debug("{} created",  getClass().getSimpleName());
+        LOG.trace("{} created",  getClass().getSimpleName());
     }
 
-    @PostConstruct
     public void init() {
-        registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
-        LOG.debug("{} init and registerListener done", getClass().getSimpleName());
+        LOG.trace("{} init and registerListener done", getClass().getSimpleName());
     }
 
     @Override
-    protected InstanceIdentifier<QosalertConfig> getWildCardPath() {
-        return InstanceIdentifier.create(QosalertConfig.class);
+    @PreDestroy
+    public void close() {
+        super.close();
+        Executors.shutdownAndAwaitTermination(getExecutorService());
     }
 
     @Override
-    protected void remove(InstanceIdentifier<QosalertConfig> identifier, QosalertConfig del) {
+    public void remove(InstanceIdentifier<QosalertConfig> identifier, QosalertConfig del) {
         LOG.debug("QosalertConfig removed: {}", del);
         qosAlertManager.restoreDefaultConfig();
     }
 
     @Override
-    protected void update(InstanceIdentifier<QosalertConfig> identifier, QosalertConfig original,
+    public void update(InstanceIdentifier<QosalertConfig> identifier, QosalertConfig original,
                                                                                 QosalertConfig update) {
         LOG.debug("QosalertConfig changed to {}", update);
         qosAlertManager.setQosalertConfig(update);
     }
 
     @Override
-    protected void add(InstanceIdentifier<QosalertConfig> identifier, QosalertConfig add) {
+    public void add(InstanceIdentifier<QosalertConfig> identifier, QosalertConfig add) {
         LOG.debug("QosalertConfig added {}", add);
         qosAlertManager.setQosalertConfig(add);
     }
-
-    @Override
-    protected QosAlertConfigListener getDataTreeChangeListener() {
-        return this;
-    }
-
 }