MRI version bumpup for Aluminium
[netvirt.git] / natservice / impl / src / main / java / org / opendaylight / netvirt / natservice / internal / NatInterfaceStateChangeListener.java
index 48ee9e173cae5067458d89abe7cdaea166ae8785..733e253bda82d526fd88f1b12ea626465d00a025 100644 (file)
@@ -7,33 +7,30 @@
  */
 package org.opendaylight.netvirt.natservice.internal;
 
-import static org.opendaylight.netvirt.natservice.internal.NatUtil.requireNonNullElse;
-
-import com.google.common.base.Optional;
-import java.math.BigInteger;
-
-import java.util.Collections;
-import javax.annotation.PostConstruct;
+import java.util.Optional;
+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.datastoreutils.SingleTransactionDataBroker;
-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.vpn._interface.VpnInstanceNames;
+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.AbstractAsyncDataTreeChangeListener;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev170119.L2vlan;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.router.interfaces.RouterInterface;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry;
+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.vpn._interface.VpnInstanceNames;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint64;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Singleton
 public class NatInterfaceStateChangeListener
-    extends AsyncDataTreeChangeListenerBase<Interface, NatInterfaceStateChangeListener> {
+    extends AbstractAsyncDataTreeChangeListener<Interface> {
 
     private static final Logger LOG = LoggerFactory.getLogger(NatInterfaceStateChangeListener.class);
     private final DataBroker dataBroker;
@@ -42,46 +39,42 @@ public class NatInterfaceStateChangeListener
     @Inject
     public NatInterfaceStateChangeListener(final DataBroker dataBroker,
                                            final NatSouthboundEventHandlers southboundEventHandlers) {
-        super(Interface.class, NatInterfaceStateChangeListener.class);
+        super(dataBroker, LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(InterfacesState.class)
+                .child(Interface.class),
+                Executors.newListeningSingleThreadExecutor("NatInterfaceStateChangeListener", LOG));
         this.dataBroker = dataBroker;
         this.southboundEventHandlers = southboundEventHandlers;
     }
 
-    @Override
-    @PostConstruct
     public void init() {
         LOG.info("{} init", getClass().getSimpleName());
-        registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
-    }
-
-    @Override
-    protected InstanceIdentifier<Interface> getWildCardPath() {
-        return InstanceIdentifier.create(InterfacesState.class).child(Interface.class);
     }
 
     @Override
-    protected NatInterfaceStateChangeListener getDataTreeChangeListener() {
-        return NatInterfaceStateChangeListener.this;
+    @PreDestroy
+    public void close() {
+        super.close();
+        Executors.shutdownAndAwaitTermination(getExecutorService());
     }
 
     @Override
     // TODO Clean up the exception handling
     @SuppressWarnings("checkstyle:IllegalCatch")
-    protected void add(InstanceIdentifier<Interface> identifier, Interface intrf) {
+    public void add(InstanceIdentifier<Interface> identifier, Interface intrf) {
         LOG.trace("add : Interface {} up event received", intrf);
         if (!L2vlan.class.equals(intrf.getType())) {
             LOG.debug("add : Interface {} is not Vlan Interface.Ignoring", intrf.getName());
             return;
         }
         String interfaceName = intrf.getName();
-        BigInteger intfDpnId;
+        Uint64 intfDpnId;
         try {
             intfDpnId = NatUtil.getDpIdFromInterface(intrf);
         } catch (Exception e) {
             LOG.error("add : Exception occured while retriving dpnid for interface {}", intrf.getName(), e);
             return;
         }
-        if (BigInteger.ZERO.equals(intfDpnId)) {
+        if (Uint64.ZERO.equals(intfDpnId)) {
             LOG.warn("add : Could not retrieve dp id for interface {} ", interfaceName);
             return;
         }
@@ -99,14 +92,14 @@ public class NatInterfaceStateChangeListener
     @Override
     // TODO Clean up the exception handling
     @SuppressWarnings("checkstyle:IllegalCatch")
-    protected void remove(InstanceIdentifier<Interface> identifier, Interface intrf) {
+    public void remove(InstanceIdentifier<Interface> identifier, Interface intrf) {
         LOG.trace("remove : Interface {} removed event received", intrf);
         if (!L2vlan.class.equals(intrf.getType())) {
             LOG.debug("remove : Interface {} is not Vlan Interface.Ignoring", intrf.getName());
             return;
         }
         String interfaceName = intrf.getName();
-        BigInteger intfDpnId = BigInteger.ZERO;
+        Uint64 intfDpnId = Uint64.ZERO;
         try {
             intfDpnId = NatUtil.getDpIdFromInterface(intrf);
         } catch (Exception e) {
@@ -119,8 +112,7 @@ public class NatInterfaceStateChangeListener
                 LOG.warn("remove : Interface {} is not a VPN Interface, ignoring.", interfaceName);
                 return;
             }
-            for (VpnInstanceNames vpnInterfaceVpnInstance : requireNonNullElse(
-                    cfgVpnInterface.get().getVpnInstanceNames(), Collections.<VpnInstanceNames>emptyList())) {
+            for (VpnInstanceNames vpnInterfaceVpnInstance : cfgVpnInterface.get().nonnullVpnInstanceNames().values()) {
                 String vpnName  = vpnInterfaceVpnInstance.getVpnName();
                 InstanceIdentifier<VpnInterfaceOpDataEntry> idOper = NatUtil
                       .getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
@@ -133,7 +125,7 @@ public class NatInterfaceStateChangeListener
                 }
             }
         }
-        if (BigInteger.ZERO.equals(intfDpnId)) {
+        if (Uint64.ZERO.equals(intfDpnId)) {
             LOG.warn("remove : Could not retrieve dpnid for interface {} ", interfaceName);
             return;
         }
@@ -148,13 +140,13 @@ public class NatInterfaceStateChangeListener
     @Override
     // TODO Clean up the exception handling
     @SuppressWarnings("checkstyle:IllegalCatch")
-    protected void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
+    public void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
         LOG.trace("update : Operation Interface update event - Old: {}, New: {}", original, update);
         if (!L2vlan.class.equals(update.getType())) {
             LOG.debug("update : Interface {} is not Vlan Interface.Ignoring", update.getName());
             return;
         }
-        BigInteger intfDpnId = BigInteger.ZERO;
+        Uint64 intfDpnId = Uint64.ZERO;
         String interfaceName = update.getName();
         try {
             intfDpnId = NatUtil.getDpIdFromInterface(update);
@@ -168,8 +160,7 @@ public class NatInterfaceStateChangeListener
                 LOG.warn("update : Interface {} is not a VPN Interface, ignoring.", interfaceName);
                 return;
             }
-            for (VpnInstanceNames vpnInterfaceVpnInstance : requireNonNullElse(
-                    cfgVpnInterface.get().getVpnInstanceNames(), Collections.<VpnInstanceNames>emptyList())) {
+            for (VpnInstanceNames vpnInterfaceVpnInstance : cfgVpnInterface.get().nonnullVpnInstanceNames().values()) {
                 String vpnName  = vpnInterfaceVpnInstance.getVpnName();
                 InstanceIdentifier<VpnInterfaceOpDataEntry> idOper = NatUtil
                       .getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
@@ -182,7 +173,7 @@ public class NatInterfaceStateChangeListener
                 }
             }
         }
-        if (BigInteger.ZERO.equals(intfDpnId)) {
+        if (Uint64.ZERO.equals(intfDpnId)) {
             LOG.warn("remove : Could not retrieve dpnid for interface {} ", interfaceName);
             return;
         }