Migrate ListenableFutures.addErrorLogging() users
[netvirt.git] / vpnmanager / impl / src / main / java / org / opendaylight / netvirt / vpnmanager / VpnElanInterfaceChangeListener.java
index 4aece250b4fd7e17df4655c55a657fa7a2d093d0..82fadd7bc5bac7f3933d9bf613380b85f3f73eec 100644 (file)
@@ -8,36 +8,36 @@
 
 package org.opendaylight.netvirt.vpnmanager;
 
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
 import java.util.ArrayList;
 import java.util.List;
-
-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.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
-import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
+import org.opendaylight.infrautils.utils.concurrent.Executors;
+import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.netvirt.elanmanager.api.IElanService;
 import org.opendaylight.netvirt.vpnmanager.api.VpnHelper;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames.AssociatedSubnetType;
+import org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInterfaces;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames.AssociatedSubnetType;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Singleton
-public class VpnElanInterfaceChangeListener
-    extends AsyncDataTreeChangeListenerBase<ElanInterface, VpnElanInterfaceChangeListener> {
+public class VpnElanInterfaceChangeListener extends AbstractAsyncDataTreeChangeListener<ElanInterface> {
     private static final Logger LOG = LoggerFactory.getLogger(VpnElanInterfaceChangeListener.class);
 
     private final DataBroker broker;
@@ -48,26 +48,30 @@ public class VpnElanInterfaceChangeListener
     @Inject
     public VpnElanInterfaceChangeListener(final DataBroker broker, final IElanService elanService,
                                           final VpnUtil vpnUtil) {
-        super(ElanInterface.class, VpnElanInterfaceChangeListener.class);
+        super(broker, LogicalDatastoreType.CONFIGURATION,
+                InstanceIdentifier.create(ElanInterfaces.class).child(ElanInterface.class),
+                Executors.newListeningSingleThreadExecutor("VpnElanInterfaceChangeListener", LOG));
         this.broker = broker;
         this.txRunner = new ManagedNewTransactionRunnerImpl(broker);
         this.elanService = elanService;
         this.vpnUtil = vpnUtil;
+        start();
     }
 
-    @PostConstruct
     public void start() {
         LOG.info("{} start", getClass().getSimpleName());
-        registerListener(LogicalDatastoreType.CONFIGURATION, broker);
     }
 
     @Override
-    protected InstanceIdentifier<ElanInterface> getWildCardPath() {
-        return InstanceIdentifier.create(ElanInterfaces.class).child(ElanInterface.class);
+    @PreDestroy
+    public void close() {
+        super.close();
+        Executors.shutdownAndAwaitTermination(getExecutorService());
     }
 
+
     @Override
-    protected void remove(InstanceIdentifier<ElanInterface> key, ElanInterface elanInterface) {
+    public void remove(InstanceIdentifier<ElanInterface> key, ElanInterface elanInterface) {
         String interfaceName = elanInterface.getName();
         if (!elanService.isExternalInterface(interfaceName)) {
             LOG.debug("remove: Interface {} is not external. Ignoring interface removal", interfaceName);
@@ -80,20 +84,19 @@ public class VpnElanInterfaceChangeListener
         }
 
         InstanceIdentifier<VpnInterface> vpnInterfaceIdentifier = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
-        ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
-            tx.delete(LogicalDatastoreType.CONFIGURATION, vpnInterfaceIdentifier)), LOG,
-                "Error removing VPN interface {}", vpnInterfaceIdentifier);
+        LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx ->
+            tx.delete(vpnInterfaceIdentifier)), LOG, "Error removing VPN interface {}", vpnInterfaceIdentifier);
         LOG.info("remove: Removed VPN interface {}", interfaceName);
     }
 
     @Override
-    protected void update(InstanceIdentifier<ElanInterface> key, ElanInterface origElanInterface,
+    public void update(InstanceIdentifier<ElanInterface> key, ElanInterface origElanInterface,
         ElanInterface updatedElanInterface) {
 
     }
 
     @Override
-    protected void add(InstanceIdentifier<ElanInterface> key, ElanInterface elanInterface) {
+    public void add(InstanceIdentifier<ElanInterface> key, ElanInterface elanInterface) {
         String interfaceName = elanInterface.getName();
         if (!elanService.isExternalInterface(interfaceName)) {
             LOG.debug("add: Interface {} is not external. Ignoring", interfaceName);
@@ -121,7 +124,6 @@ public class VpnElanInterfaceChangeListener
         listVpn.add(vpnInstance);
         VpnInterface vpnInterface = new VpnInterfaceBuilder().withKey(new VpnInterfaceKey(interfaceName))
             .setVpnInstanceNames(listVpn)
-            .setScheduledForRemove(Boolean.FALSE)
             .build();
         InstanceIdentifier<VpnInterface> vpnInterfaceIdentifier = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
         vpnUtil.syncWrite(LogicalDatastoreType.CONFIGURATION, vpnInterfaceIdentifier, vpnInterface);
@@ -129,8 +131,4 @@ public class VpnElanInterfaceChangeListener
                 elanInterface.getElanInstanceName());
     }
 
-    @Override
-    protected VpnElanInterfaceChangeListener getDataTreeChangeListener() {
-        return this;
-    }
 }