Changed the AsyncDataChangeListenerBase to 32/47132/9
authorSatish Dutt <satishd@altencalsoftlabs.com>
Wed, 19 Oct 2016 14:56:51 +0000 (20:26 +0530)
committerSam Hague <shague@redhat.com>
Sun, 23 Oct 2016 17:33:56 +0000 (13:33 -0400)
AsyncDataTreeChangeListenerBase in the NAT reated files

Addressed the review comments

Change-Id: I9fa06d9d230839ab8b812470469e14f247b7d8f5
Signed-off-by: Satish Dutt <satishd@altencalsoftlabs.com>
Author: Sam Hague <shague@redhat.com>
Signed-off-by: Sam Hague <shague@redhat.com>
vpnservice/natservice/natservice-impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ExternalNetworkListener.java
vpnservice/natservice/natservice-impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ExternalNetworksChangeListener.java
vpnservice/natservice/natservice-impl/src/main/java/org/opendaylight/netvirt/natservice/internal/FloatingIPListener.java
vpnservice/natservice/natservice-impl/src/main/java/org/opendaylight/netvirt/natservice/internal/InterfaceStateEventListener.java
vpnservice/natservice/natservice-impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatNodeEventListener.java
vpnservice/natservice/natservice-impl/src/main/java/org/opendaylight/netvirt/natservice/internal/RouterDpnChangeListener.java
vpnservice/natservice/natservice-impl/src/main/java/org/opendaylight/netvirt/natservice/internal/RouterPortsListener.java

index 965c791e635f9f947c252b38b2eaa3465737be43..d92e79973b677a1f790276fed5cc286e159e9df9 100644 (file)
@@ -17,7 +17,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.genius.mdsalutil.AbstractDataChangeListener;
+import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.genius.mdsalutil.FlowEntity;
 import org.opendaylight.genius.mdsalutil.InstructionInfo;
 import org.opendaylight.genius.mdsalutil.InstructionType;
@@ -37,53 +37,49 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class ExternalNetworkListener extends AbstractDataChangeListener<Networks> implements AutoCloseable {
+public class ExternalNetworkListener extends AsyncDataTreeChangeListenerBase<Networks, ExternalNetworkListener> implements AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(ExternalNetworkListener.class);
-    private ListenerRegistration<DataChangeListener> listenerRegistration;
     private final DataBroker dataBroker;
     private final IMdsalApiManager mdsalManager;
 
     public ExternalNetworkListener (final DataBroker dataBroker, final IMdsalApiManager mdsalManager) {
-        super(Networks.class);
+        super(Networks.class, ExternalNetworkListener.class);
         this.dataBroker = dataBroker;
         this.mdsalManager = mdsalManager;
     }
 
+    @Override
     public void init() {
         LOG.info("{} init", getClass().getSimpleName());
-        listenerRegistration = dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
-                getWildCardPath(), this, AsyncDataBroker.DataChangeScope.SUBTREE);
+        registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
     }
 
-    private InstanceIdentifier<Networks> getWildCardPath() {
-        return InstanceIdentifier.create(ExternalNetworks.class).child(Networks.class);
+    @Override
+    protected ExternalNetworkListener getDataTreeChangeListener() {
+        return ExternalNetworkListener.this;
     }
 
     @Override
-    public void close() throws Exception {
-        if (listenerRegistration != null) {
-            listenerRegistration.close();
-            listenerRegistration = null;
-        }
-        LOG.info("{} close", getClass().getSimpleName());
+    protected InstanceIdentifier<Networks> getWildCardPath() {
+        return InstanceIdentifier.create(ExternalNetworks.class).child(Networks.class);
     }
 
     @Override
     protected void add(final InstanceIdentifier<Networks> identifier,
                        final Networks nw) {
-        LOG.trace("External Network add mapping method - key: " + identifier + ", value=" + nw );
+        LOG.trace("NAT Service : External Network add mapping method - key: " + identifier + ", value=" + nw );
         processExternalNwAdd(identifier, nw);
     }
 
     @Override
     protected void remove(InstanceIdentifier<Networks> identifier, Networks nw) {
-        LOG.trace("External Network remove mapping method - key: " + identifier + ", value=" + nw );
+        LOG.trace("NAT Service : External Network remove mapping method - key: " + identifier + ", value=" + nw );
         processExternalNwDel(identifier, nw);
     }
 
     @Override
     protected void update(InstanceIdentifier<Networks> identifier, Networks original, Networks update) {
-        LOG.trace("External Network update mapping method - key: " + identifier + ", original=" + original + ", update=" + update );
+        LOG.trace("NAT Service : External Network update mapping method - key: " + identifier + ", original=" + original + ", update=" + update );
         //check if a new router has been added or an already existing router has been deleted from the external nw to router association
         List<Uuid> oldRtrs = original.getRouterIds();
         List<Uuid> newRtrs = update.getRouterIds();
@@ -111,7 +107,7 @@ public class ExternalNetworkListener extends AbstractDataChangeListener<Networks
 
     private void processExternalNwAdd(final InstanceIdentifier<Networks> identifier,
                                       final Networks network) {
-        LOG.trace("Add event - key: {}, value: {}", identifier, network);
+        LOG.trace("NAT Service : Add event - key: {}, value: {}", identifier, network);
         List<Uuid> routerList = network.getRouterIds();
 
         if(routerList == null) {
@@ -127,7 +123,7 @@ public class ExternalNetworkListener extends AbstractDataChangeListener<Networks
 
     private void processExternalNwDel(final InstanceIdentifier<Networks> identifier,
                                       final Networks network) {
-        LOG.trace("Add event - key: {}, value: {}", identifier, network);
+        LOG.trace("NAT Service : Add event - key: {}, value: {}", identifier, network);
         List<Uuid> routerList = network.getRouterIds();
 
         for(Uuid router: routerList) {
@@ -164,7 +160,7 @@ public class ExternalNetworkListener extends AbstractDataChangeListener<Networks
             defaultIP = InetAddress.getByName("0.0.0.0");
 
         } catch (UnknownHostException e) {
-            LOG.error("UnknowHostException in buildDefNATFlowEntity. Failed  to build FIB Table Flow for Default Route to NAT table ");
+            LOG.error("NAT Service : UnknowHostException in buildDefNATFlowEntity. Failed  to build FIB Table Flow for Default Route to NAT table ");
             return null;
         }
 
@@ -197,7 +193,7 @@ public class ExternalNetworkListener extends AbstractDataChangeListener<Networks
     private void installDefNATRouteInDPN(BigInteger dpnId, long vpnId) {
         FlowEntity flowEntity = buildDefNATFlowEntity(dpnId, vpnId);
         if(flowEntity == null) {
-            LOG.error("Flow entity received is NULL. Cannot proceed with installation of Default NAT flow");
+            LOG.error("NAT Service : Flow entity received is NULL. Cannot proceed with installation of Default NAT flow");
             return;
         }
         mdsalManager.installFlow(flowEntity);
@@ -206,7 +202,7 @@ public class ExternalNetworkListener extends AbstractDataChangeListener<Networks
     private void removeDefNATRouteInDPN(BigInteger dpnId, long vpnId) {
         FlowEntity flowEntity = buildDefNATFlowEntity(dpnId, vpnId);
         if(flowEntity == null) {
-            LOG.error("Flow entity received is NULL. Cannot proceed with installation of Default NAT flow");
+            LOG.error("NAT Service : Flow entity received is NULL. Cannot proceed with installation of Default NAT flow");
             return;
         }
         mdsalManager.removeFlow(flowEntity);
index b57caf5e37ed238ae44878019b7e4a5e7319feba..773ea5a36d594643f2dfabd2219ccddbab7284ba 100644 (file)
@@ -82,6 +82,7 @@ public class ExternalNetworksChangeListener
         this.fibService =fibService;
     }
 
+    @Override
     public void init() {
         LOG.info("{} init", getClass().getSimpleName());
         registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
@@ -241,10 +242,7 @@ public class ExternalNetworksChangeListener
     private void disassociateExternalNetworkFromVPN(Networks network, String vpnName) {
         List<Uuid> routerIds = network.getRouterIds();
 
-        //long vpnId = NatUtil.getVpnId(dataBroker, vpnName);
         for(Uuid routerId : routerIds) {
-            //long router = NatUtil.getVpnId(dataBroker, routerId.getValue());
-
             InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerId.getValue());
             Optional<RouterPorts> optRouterPorts = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
             if(!optRouterPorts.isPresent()) {
index 1f84ea29ccbfc6aa29132808100c3edb14d245d0..7cb73ac2af03bdfe6df3a6f4768b814276b8b403 100644 (file)
@@ -14,7 +14,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.genius.mdsalutil.AbstractDataChangeListener;
+import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.genius.mdsalutil.ActionInfo;
 import org.opendaylight.genius.mdsalutil.ActionType;
 import org.opendaylight.genius.mdsalutil.FlowEntity;
@@ -49,7 +49,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpc
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
-
 import com.google.common.base.Optional;
 
 import java.math.BigInteger;
@@ -58,9 +57,8 @@ import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.List;
 
-public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> implements AutoCloseable{
+public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<IpMapping, FloatingIPListener> implements AutoCloseable{
     private static final Logger LOG = LoggerFactory.getLogger(FloatingIPListener.class);
-    private ListenerRegistration<DataChangeListener> listenerRegistration;
     private final DataBroker dataBroker;
     private final IMdsalApiManager mdsalManager;
     private final OdlInterfaceRpcService interfaceManager;
@@ -72,12 +70,11 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
                               final OdlInterfaceRpcService interfaceManager,
                               final IdManagerService idManager,
                               final BundleContext bundleContext) {
-        super(IpMapping.class);
+        super(IpMapping.class, FloatingIPListener.class);
         this.dataBroker = dataBroker;
         this.mdsalManager = mdsalManager;
         this.interfaceManager = interfaceManager;
         this.idManager = idManager;
-
         GlobalEventExecutor.INSTANCE.execute(new Runnable() {
             @Override
             public void run() {
@@ -91,34 +88,28 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
 
     public void init() {
         LOG.info("{} init", getClass().getSimpleName());
-        listenerRegistration = dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
-                getWildCardPath(), this, AsyncDataBroker.DataChangeScope.SUBTREE);
+        registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
     }
 
-    private InstanceIdentifier<IpMapping> getWildCardPath() {
-        return InstanceIdentifier.create(FloatingIpInfo.class).child(RouterPorts.class).child(Ports.class)
-                .child(IpMapping.class);
+    @Override
+    protected InstanceIdentifier<IpMapping> getWildCardPath() {
+        return InstanceIdentifier.create(FloatingIpInfo.class).child(RouterPorts.class).child(Ports.class).child(IpMapping.class);
     }
 
     @Override
-    public void close() throws Exception {
-        if (listenerRegistration != null) {
-            listenerRegistration.close();
-            listenerRegistration = null;
-        }
-        LOG.info("{} close", getClass().getSimpleName());
+    protected FloatingIPListener getDataTreeChangeListener() {
+        return FloatingIPListener.this;
     }
-
     @Override
     protected void add(final InstanceIdentifier<IpMapping> identifier,
                        final IpMapping mapping) {
-        LOG.trace("FloatingIPListener add ip mapping method - key: " + identifier + ", value=" + mapping );
+        LOG.trace("NAT Service : FloatingIPListener add ip mapping method - key: " + identifier + ", value=" + mapping );
         processFloatingIPAdd(identifier, mapping);
     }
 
     @Override
     protected void remove(InstanceIdentifier<IpMapping> identifier, IpMapping mapping) {
-        LOG.trace("FloatingIPListener remove ip mapping method - key: " + identifier + ", value=" + mapping );
+        LOG.trace("NAT Service : FloatingIPListener remove ip mapping method - key: " + identifier + ", value=" + mapping );
         processFloatingIPDel(identifier, mapping);
     }
 
@@ -128,10 +119,10 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
     }
 
     private FlowEntity buildPreDNATFlowEntity(BigInteger dpId, String internalIp, String externalIp, long routerId, long vpnId, long associatedVpn) {
-        LOG.info("Bulding DNAT Flow entity for ip {} ", externalIp);
+        LOG.info("NAT Service : Bulding DNAT Flow entity for ip {} ", externalIp);
 
         long segmentId = (associatedVpn == NatConstants.INVALID_ID) ? routerId : associatedVpn;
-        LOG.debug("Segment id {} in build preDNAT Flow", segmentId);
+        LOG.debug("NAT Service : Segment id {} in build preDNAT Flow", segmentId);
 
         List<MatchInfo> matches = new ArrayList<>();
         matches.add(new MatchInfo(MatchFieldType.eth_type,
@@ -163,10 +154,10 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
 
     private FlowEntity buildDNATFlowEntity(BigInteger dpId, String internalIp, String externalIp, long routerId, long associatedVpn) {
 
-        LOG.info("Bulding DNAT Flow entity for ip {} ", externalIp);
+        LOG.info("NAT Service : Bulding DNAT Flow entity for ip {} ", externalIp);
 
         long segmentId = (associatedVpn == NatConstants.INVALID_ID) ? routerId : associatedVpn;
-        LOG.debug("Segment id {} in build DNAT", segmentId);
+        LOG.debug("NAT Service : Segment id {} in build DNAT", segmentId);
 
         List<MatchInfo> matches = new ArrayList<>();
         matches.add(new MatchInfo(MatchFieldType.metadata, new BigInteger[] {
@@ -201,11 +192,11 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
 
     private FlowEntity buildPreSNATFlowEntity(BigInteger dpId, String internalIp, String externalIp, long vpnId, long routerId, long associatedVpn) {
 
-        LOG.info("Building PSNAT Flow entity for ip {} ", internalIp);
+        LOG.info("NAT Service : Building PSNAT Flow entity for ip {} ", internalIp);
 
         long segmentId = (associatedVpn == NatConstants.INVALID_ID) ? routerId : associatedVpn;
 
-        LOG.debug("Segment id {} in build preSNAT flow", segmentId);
+        LOG.debug("NAT Service : Segment id {} in build preSNAT flow", segmentId);
 
         List<MatchInfo> matches = new ArrayList<>();
         matches.add(new MatchInfo(MatchFieldType.eth_type,
@@ -326,7 +317,7 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
     private Uuid getExtNetworkId(final InstanceIdentifier<RouterPorts> pIdentifier, LogicalDatastoreType dataStoreType) {
         Optional<RouterPorts> rtrPort = NatUtil.read(dataBroker, dataStoreType, pIdentifier);
         if(!rtrPort.isPresent()) {
-            LOG.error("Unable to read router port entry for {}", pIdentifier);
+            LOG.error("NAT Service : Unable to read router port entry for {}", pIdentifier);
             return null;
         }
 
@@ -338,7 +329,7 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
         InstanceIdentifier<Networks> nwId = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNwId)).build();
         Optional<Networks> nw = NatUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, nwId);
         if(!nw.isPresent()) {
-            LOG.error("Unable to read external network for {}", extNwId);
+            LOG.error("NAT Service : Unable to read external network for {}", extNwId);
             return NatConstants.INVALID_ID;
         }
 
@@ -353,7 +344,7 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
 
     private void processFloatingIPAdd(final InstanceIdentifier<IpMapping> identifier,
                                       final IpMapping mapping) {
-        LOG.trace("Add event - key: {}, value: {}", identifier, mapping);
+        LOG.trace("NAT Service : Add event - key: {}, value: {}", identifier, mapping);
 
         final String routerId = identifier.firstKeyOf(RouterPorts.class).getRouterId();
         final PortsKey pKey = identifier.firstKeyOf(Ports.class);
@@ -365,7 +356,7 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
 
     private void processFloatingIPDel(final InstanceIdentifier<IpMapping> identifier,
                                       final IpMapping mapping) {
-        LOG.trace("Del event - key: {}, value: {}", identifier, mapping);
+        LOG.trace("NAT Service : Del event - key: {}, value: {}", identifier, mapping);
 
         final String routerId = identifier.firstKeyOf(RouterPorts.class).getRouterId();
         final PortsKey pKey = identifier.firstKeyOf(Ports.class);
@@ -380,7 +371,7 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
         try {
             ipAddress = InetAddress.getByName(ipAddr);
         } catch (UnknownHostException e) {
-            LOG.error("UnknowHostException for ip {}", ipAddr);
+            LOG.error("NAT Service : UnknowHostException for ip {}", ipAddr);
         }
         return ipAddress;
     }
@@ -393,7 +384,7 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
     void createNATFlowEntries(String interfaceName, final IpMapping mapping,
                               final InstanceIdentifier<RouterPorts> pIdentifier, final String routerName) {
         if(!validateIpMapping(mapping)) {
-            LOG.warn("Not a valid ip addresses in the mapping {}", mapping);
+            LOG.warn("NAT Service : Not a valid ip addresses in the mapping {}", mapping);
             return;
         }
 
@@ -401,14 +392,14 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
         BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, interfaceName);
 
         if(dpnId.equals(BigInteger.ZERO)) {
-             LOG.error("No DPN for interface {}. NAT flow entries for ip mapping {} will not be installed",
+             LOG.error("NAT Service : No DPN for interface {}. NAT flow entries for ip mapping {} will not be installed",
                      interfaceName, mapping);
              return;
         }
 
         long routerId = NatUtil.getVpnId(dataBroker, routerName);
         if(routerId == NatConstants.INVALID_ID) {
-            LOG.warn("Could not retrieve router id for {} to create NAT Flow entries", routerName);
+            LOG.warn("NAT Service : Could not retrieve router id for {} to create NAT Flow entries", routerName);
             return;
         }
         //Check if the router to vpn association is present
@@ -416,23 +407,23 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
         Uuid associatedVpn = NatUtil.getVpnForRouter(dataBroker, routerName);
         long associatedVpnId = NatConstants.INVALID_ID;
         if(associatedVpn == null) {
-            LOG.debug("Router {} is not assicated with any BGP VPN instance", routerName);
+            LOG.debug("NAT Service : Router {} is not assicated with any BGP VPN instance", routerName);
         } else {
-            LOG.debug("Router {} is associated with VPN Instance with Id {}", routerName, associatedVpn);
+            LOG.debug("NAT Service : Router {} is associated with VPN Instance with Id {}", routerName, associatedVpn);
             associatedVpnId = NatUtil.getVpnId(dataBroker, associatedVpn.getValue());
-            LOG.debug("vpninstance Id is {} for VPN {}", associatedVpnId, associatedVpn);
+            LOG.debug("NAT Service : vpninstance Id is {} for VPN {}", associatedVpnId, associatedVpn);
             //routerId = associatedVpnId;
         }
 
         Uuid extNwId = getExtNetworkId(pIdentifier, LogicalDatastoreType.CONFIGURATION);
         if(extNwId == null) {
-            LOG.error("External network associated with interface {} could not be retrieved", interfaceName);
-            LOG.error("NAT flow entries will not be installed {}", mapping);
+            LOG.error("NAT Service : External network associated with interface {} could not be retrieved", interfaceName);
+            LOG.error("NAT Service : NAT flow entries will not be installed {}", mapping);
             return;
         }
         long vpnId = getVpnId(extNwId);
         if(vpnId < 0) {
-            LOG.error("No VPN associated with Ext nw {}. Unable to create SNAT table entry for fixed ip {}",
+            LOG.error("NAT Service : No VPN associated with Ext nw {}. Unable to create SNAT table entry for fixed ip {}",
                     extNwId, mapping.getInternalIp());
             return;
         }
@@ -450,21 +441,21 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
     void createNATFlowEntries(BigInteger dpnId,  String interfaceName, String routerName, Uuid externalNetworkId, String internalIp, String externalIp) {
         long routerId = NatUtil.getVpnId(dataBroker, routerName);
         if(routerId == NatConstants.INVALID_ID) {
-            LOG.warn("Could not retrieve router id for {} to create NAT Flow entries", routerName);
+            LOG.warn("NAT Service : Could not retrieve router id for {} to create NAT Flow entries", routerName);
             return;
         }
         //Check if the router to vpn association is present
         long associatedVpnId = NatUtil.getAssociatedVpn(dataBroker, routerName);
         if(associatedVpnId == NatConstants.INVALID_ID) {
-            LOG.debug("Router {} is not assicated with any BGP VPN instance", routerName);
+            LOG.debug("NAT Service : Router {} is not assicated with any BGP VPN instance", routerName);
         } else {
-            LOG.debug("Router {} is associated with VPN Instance with Id {}", routerName, associatedVpnId);
+            LOG.debug("NAT Service : Router {} is associated with VPN Instance with Id {}", routerName, associatedVpnId);
             //routerId = associatedVpnId;
         }
 
         long vpnId = getVpnId(externalNetworkId);
         if(vpnId < 0) {
-            LOG.error("Unable to create SNAT table entry for fixed ip {}", internalIp);
+            LOG.error("NAT Service : Unable to create SNAT table entry for fixed ip {}", internalIp);
             return;
         }
         //Create the DNAT and SNAT table entries
@@ -477,17 +468,17 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
 
     void createNATOnlyFlowEntries(BigInteger dpnId,  String interfaceName, String routerName, String associatedVPN, Uuid externalNetworkId, String internalIp, String externalIp) {
         //String segmentId = associatedVPN == null ? routerName : associatedVPN;
-        LOG.debug("Retrieving vpn id for VPN {} to proceed with create NAT Flows", routerName);
+        LOG.debug("NAT Service : Retrieving vpn id for VPN {} to proceed with create NAT Flows", routerName);
         long routerId = NatUtil.getVpnId(dataBroker, routerName);
         if(routerId == NatConstants.INVALID_ID) {
             LOG.warn("Could not retrieve vpn id for {} to create NAT Flow entries", routerName);
             return;
         }
         long associatedVpnId = NatUtil.getVpnId(dataBroker, associatedVPN);
-        LOG.debug("Associated VPN Id {} for router {}", associatedVpnId, routerName);
+        LOG.debug("NAT Service : Associated VPN Id {} for router {}", associatedVpnId, routerName);
         long vpnId = getVpnId(externalNetworkId);
         if(vpnId < 0) {
-            LOG.error("Unable to create SNAT table entry for fixed ip {}", internalIp);
+            LOG.error("NAT Service : Unable to create SNAT table entry for fixed ip {}", internalIp);
             return;
         }
         //Create the DNAT and SNAT table entries
@@ -513,13 +504,13 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
         //Get the DPN on which this interface resides
         BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, interfaceName);
         if(dpnId.equals(BigInteger.ZERO)) {
-            LOG.info("Abort processing Floating ip configuration. No DPN for port : {}", interfaceName);
+            LOG.info("NAT Service : Abort processing Floating ip configuration. No DPN for port : {}", interfaceName);
             return;
         }
 
         long routerId = NatUtil.getVpnId(dataBroker, routerName);
         if(routerId == NatConstants.INVALID_ID) {
-            LOG.warn("Could not retrieve router id for {} to remove NAT Flow entries", routerName);
+            LOG.warn("NAT Service : Could not retrieve router id for {} to remove NAT Flow entries", routerName);
             return;
         }
         //if(routerId == NatConstants.INVALID_ID) {
@@ -527,9 +518,9 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
         Uuid associatedVPN = NatUtil.getVpnForRouter(dataBroker, routerName);
         long associatedVpnId = NatConstants.INVALID_ID;
         if(associatedVPN == null) {
-            LOG.warn("Could not retrieve router id for {} to remove NAT Flow entries", routerName);
+            LOG.warn("NAT Service : Could not retrieve router id for {} to remove NAT Flow entries", routerName);
         } else {
-            LOG.debug("Retrieving vpn id for VPN {} to proceed with remove NAT Flows", associatedVPN.getValue());
+            LOG.debug("NAT Service : Retrieving vpn id for VPN {} to proceed with remove NAT Flows", associatedVPN.getValue());
             associatedVpnId = NatUtil.getVpnId(dataBroker, associatedVPN.getValue());
         }
 
@@ -538,12 +529,12 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
 
         Uuid extNwId = getExtNetworkId(pIdentifier, LogicalDatastoreType.OPERATIONAL);
         if(extNwId == null) {
-            LOG.error("External network associated with interface {} could not be retrieved", interfaceName);
+            LOG.error("NAT Service : External network associated with interface {} could not be retrieved", interfaceName);
             return;
         }
         long vpnId = getVpnId(extNwId);
         if(vpnId < 0) {
-            LOG.error("No VPN associated with ext nw {}. Unable to delete SNAT table entry for fixed ip {}",
+            LOG.error("NAT Service : No VPN associated with ext nw {}. Unable to delete SNAT table entry for fixed ip {}",
                     extNwId, mapping.getInternalIp());
             return;
         }
@@ -551,7 +542,7 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
 
         long label = getOperationalIpMapping(routerName, interfaceName, mapping.getInternalIp());
         if(label < 0) {
-            LOG.error("Could not retrieve label for prefix {} in router {}", mapping.getInternalIp(), routerId);
+            LOG.error("NAT Service : Could not retrieve label for prefix {} in router {}", mapping.getInternalIp(), routerId);
             return;
         }
         //Uuid extNwId = getExtNetworkId(pIdentifier);
@@ -568,13 +559,13 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
     void removeNATFlowEntries(BigInteger dpnId, String interfaceName, String vpnName, String routerName, Uuid externalNetworkId, String internalIp, String externalIp) {
         long routerId = NatUtil.getVpnId(dataBroker, routerName);
         if(routerId == NatConstants.INVALID_ID) {
-            LOG.warn("Could not retrieve router id for {} to remove NAT Flow entries", routerName);
+            LOG.warn("NAT Service : Could not retrieve router id for {} to remove NAT Flow entries", routerName);
             return;
         }
 
         long vpnId = NatUtil.getVpnId(dataBroker, vpnName);
         if(vpnId == NatConstants.INVALID_ID) {
-            LOG.warn("VPN Id not found for {} to remove NAT flow entries {}", vpnName, internalIp);
+            LOG.warn("NAT Service : VPN Id not found for {} to remove NAT flow entries {}", vpnName, internalIp);
         }
 
         //Delete the DNAT and SNAT table entries
@@ -584,7 +575,7 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
 
         long label = getOperationalIpMapping(routerName, interfaceName, internalIp);
         if(label < 0) {
-            LOG.error("Could not retrieve label for prefix {} in router {}", internalIp, routerId);
+            LOG.error("NAT Service : Could not retrieve label for prefix {} in router {}", internalIp, routerId);
             return;
         }
         //floatingIPHandler.onRemoveFloatingIp(dpnId, routerName, externalNetworkId, externalIp, internalIp, (int)label);
@@ -595,10 +586,10 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
     void removeNATOnlyFlowEntries(BigInteger dpnId, String interfaceName, String routerName, String associatedVPN,
                                                                           String internalIp, String externalIp) {
         String segmentId = associatedVPN == null ? routerName : associatedVPN;
-        LOG.debug("Retrieving vpn id for VPN {} to proceed with remove NAT Flows", segmentId);
+        LOG.debug("NAT Service : Retrieving vpn id for VPN {} to proceed with remove NAT Flows", segmentId);
         long routerId = NatUtil.getVpnId(dataBroker, segmentId);
         if(routerId == NatConstants.INVALID_ID) {
-            LOG.warn("Could not retrieve vpn id for {} to remove NAT Flow entries", segmentId);
+            LOG.warn("NAT Service : Could not retrieve vpn id for {} to remove NAT Flow entries", segmentId);
             return;
         }
         //Delete the DNAT and SNAT table entries
@@ -618,16 +609,16 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
 
     void updateOperationalDS(String routerId, String interfaceName, long label, String internalIp, String externalIp) {
 
-        LOG.info("Updating operational DS for floating ip config : {} with label {}", internalIp, label);
+        LOG.info("NAT Service : Updating operational DS for floating ip config : {} with label {}", internalIp, label);
         InstanceIdentifier<Ports> portsId = NatUtil.getPortsIdentifier(routerId, interfaceName);
         Optional<Ports> optPorts = NatUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, portsId);
         IpMapping ipMapping = new IpMappingBuilder().setKey(new IpMappingKey(internalIp)).setInternalIp(internalIp)
                 .setExternalIp(externalIp).setLabel(label).build();
         if(optPorts.isPresent()) {
-            LOG.debug("Ports {} entry already present. Updating ipmapping for internal ip {}", interfaceName, internalIp);
+            LOG.debug("NAT Service : Ports {} entry already present. Updating ipmapping for internal ip {}", interfaceName, internalIp);
             MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, portsId.child(IpMapping.class, new IpMappingKey(internalIp)), ipMapping);
         } else {
-            LOG.debug("Adding Ports entry {} along with ipmapping {}", interfaceName, internalIp);
+            LOG.debug("NAT Service : Adding Ports entry {} along with ipmapping {}", interfaceName, internalIp);
             List<IpMapping> ipMappings = new ArrayList<>();
             ipMappings.add(ipMapping);
             Ports ports = new PortsBuilder().setKey(new PortsKey(interfaceName)).setPortName(interfaceName).setIpMapping(ipMappings).build();
@@ -643,7 +634,7 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
 
     private FlowEntity buildPreDNATDeleteFlowEntity(BigInteger dpId, String internalIp, String externalIp, long routerId) {
 
-        LOG.info("Bulding Delete DNAT Flow entity for ip {} ", externalIp);
+        LOG.info("NAT Service : Bulding Delete DNAT Flow entity for ip {} ", externalIp);
 
         String flowRef = NatUtil.getFlowRef(dpId, NwConstants.PDNAT_TABLE, routerId, externalIp);
 
@@ -658,7 +649,7 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
 
     private FlowEntity buildDNATDeleteFlowEntity(BigInteger dpId, String internalIp, String externalIp, long routerId) {
 
-        LOG.info("Bulding Delete DNAT Flow entity for ip {} ", externalIp);
+        LOG.info("NAT Service : Bulding Delete DNAT Flow entity for ip {} ", externalIp);
 
         String flowRef = NatUtil.getFlowRef(dpId, NwConstants.DNAT_TABLE, routerId, externalIp);
 
@@ -672,7 +663,7 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
 
     private FlowEntity buildPreSNATDeleteFlowEntity(BigInteger dpId, String internalIp, long routerId, String externalIp) {
 
-        LOG.info("Building Delete PSNAT Flow entity for ip {} ", internalIp);
+        LOG.info("NAT Service : Building Delete PSNAT Flow entity for ip {} ", internalIp);
 
         String flowRef = NatUtil.getFlowRef(dpId, NwConstants.PSNAT_TABLE, routerId, internalIp);
 
@@ -685,7 +676,7 @@ public class FloatingIPListener extends AbstractDataChangeListener<IpMapping> im
 
     private FlowEntity buildSNATDeleteFlowEntity(BigInteger dpId, String internalIp, long routerId, String externalIp) {
 
-        LOG.info("Building Delete SNAT Flow entity for ip {} ", internalIp);
+        LOG.info("NAT Service : Building Delete SNAT Flow entity for ip {} ", internalIp);
 
         String flowRef = NatUtil.getFlowRef(dpId, NwConstants.SNAT_TABLE, routerId, internalIp);
 
index 35826fab0008103160cc98fd99feabca643a8252..32280987c7002b1dcbe2212a578ed50a591480b0 100644 (file)
@@ -12,7 +12,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.genius.mdsalutil.AbstractDataChangeListener;
+import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.genius.mdsalutil.BucketInfo;
 import org.opendaylight.genius.mdsalutil.FlowEntity;
 import org.opendaylight.genius.mdsalutil.NwConstants;
@@ -42,7 +42,6 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
 import com.google.common.base.Optional;
 
 import java.math.BigInteger;
@@ -51,7 +50,7 @@ import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 
-public class InterfaceStateEventListener extends AbstractDataChangeListener<Interface> implements AutoCloseable {
+public class InterfaceStateEventListener extends AsyncDataTreeChangeListenerBase<Interface, InterfaceStateEventListener> implements AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(InterfaceStateEventListener.class);
     private ListenerRegistration<DataChangeListener> listenerRegistration;
     private final DataBroker dataBroker;
@@ -66,7 +65,7 @@ public class InterfaceStateEventListener extends AbstractDataChangeListener<Inte
                                        final NaptManager naptManager,
                                        final NeutronvpnService neutronvpnService,
                                        final NaptSwitchHA naptSwitchHA){
-        super(Interface.class);
+        super(Interface.class, InterfaceStateEventListener.class);
         this.dataBroker = dataBroker;
         this.mdsalManager = mdsalManager;
         this.floatingIPListener = floatingIPListener;
@@ -77,21 +76,17 @@ public class InterfaceStateEventListener extends AbstractDataChangeListener<Inte
 
     public void init() {
         LOG.info("{} init", getClass().getSimpleName());
-        listenerRegistration = dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
-                getWildCardPath(), this, AsyncDataBroker.DataChangeScope.SUBTREE);
+        registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
     }
 
-    private InstanceIdentifier<Interface> getWildCardPath() {
+    @Override
+    protected InstanceIdentifier<Interface> getWildCardPath() {
         return InstanceIdentifier.create(InterfacesState.class).child(Interface.class);
     }
 
     @Override
-    public void close() throws Exception {
-        if (listenerRegistration != null) {
-            listenerRegistration.close();
-            listenerRegistration = null;
-        }
-        LOG.info("{} close", getClass().getSimpleName());
+    protected InterfaceStateEventListener getDataTreeChangeListener() {
+        return InterfaceStateEventListener.this;
     }
 
     @Override
@@ -241,7 +236,7 @@ public class InterfaceStateEventListener extends AbstractDataChangeListener<Inte
                         IpPortExternal ipPortExternal = NatUtil.getExternalIpPortMap(dataBroker, routerId,
                                 internalIp, String.valueOf(portnum), proto);
                         if (ipPortExternal == null) {
-                            LOG.error("Mapping for internalIp {} with port {} is not found in router with Id {}",internalIp,portnum,routerId);
+                            LOG.error("NAT Service : Mapping for internalIp {} with port {} is not found in router with Id {}",internalIp,portnum,routerId);
                             return;
                         }
                         String externalIpAddress = ipPortExternal.getIpAddress();
@@ -310,7 +305,7 @@ public class InterfaceStateEventListener extends AbstractDataChangeListener<Inte
                                     interfaceName, routerName);
                         }
                     } else {
-                        LOG.debug("Router is not associated to vpnname {} for interface {}",vpnName,interfaceName);
+                        LOG.debug("NAT Service : Router is not associated to vpnname {} for interface {}",vpnName,interfaceName);
                     }
                 } else {
                     LOG.debug("NAT Service : vpnName not found for vpnInterface {} of port {}",vpnInterface,interfaceName);
@@ -351,11 +346,11 @@ public class InterfaceStateEventListener extends AbstractDataChangeListener<Inte
     }
 
     private void processInterfaceAdded(String portName, String rtrId) {
-        LOG.trace("Processing Interface Add Event for interface {}", portName);
+        LOG.trace("NAT Service : Processing Interface Add Event for interface {}", portName);
         String routerId = getRouterIdForPort(dataBroker, portName);
         List<IpMapping> ipMappingList = getIpMappingForPortName(portName, routerId);
         if (ipMappingList == null || ipMappingList.isEmpty()) {
-            LOG.trace("Ip Mapping list is empty/null for portname {}", portName);
+            LOG.trace("NAT Service : Ip Mapping list is empty/null for portname {}", portName);
             return;
         }
         InstanceIdentifier<RouterPorts> pIdentifier = NatUtil.buildRouterPortsIdentifier(routerId);
@@ -369,7 +364,7 @@ public class InterfaceStateEventListener extends AbstractDataChangeListener<Inte
         String routerId = getRouterIdForPort(dataBroker, portName);
         List<IpMapping> ipMappingList = getIpMappingForPortName(portName, routerId);
         if (ipMappingList == null || ipMappingList.isEmpty()) {
-            LOG.trace("Ip Mapping list is empty/null for portName {}", portName);
+            LOG.trace("NAT Service : Ip Mapping list is empty/null for portName {}", portName);
             return;
         }
         InstanceIdentifier<RouterPorts> pIdentifier = NatUtil.buildRouterPortsIdentifier(routerId);
@@ -390,7 +385,7 @@ public class InterfaceStateEventListener extends AbstractDataChangeListener<Inte
     }
 
     private List<String> getFixedIpsForPort (String interfname) {
-        LOG.debug("getFixedIpsForPort method is called for interface {}",interfname);
+        LOG.debug("NAT Service : getFixedIpsForPort method is called for interface {}",interfname);
         try {
             Future<RpcResult<GetFixedIPsForNeutronPortOutput>> result =
                     neutronVpnService.getFixedIPsForNeutronPort(new GetFixedIPsForNeutronPortInputBuilder()
index 52b2df364684a8bc4f0c4dfd4d16c0ce478d8088..6d680e8a3af5b4a09516d8ef112233af73fa889b 100644 (file)
@@ -12,7 +12,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.genius.mdsalutil.AbstractDataChangeListener;
+import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
@@ -21,46 +21,45 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class NatNodeEventListener extends AbstractDataChangeListener<Node> implements AutoCloseable {
+import java.math.BigInteger;
+
+public class NatNodeEventListener extends AsyncDataTreeChangeListenerBase<Node, NatNodeEventListener> implements
+        AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(NatNodeEventListener.class);
     private ListenerRegistration<DataChangeListener> listenerRegistration;
     private final DataBroker dataBroker;
 
     public NatNodeEventListener(final DataBroker dataBroker) {
-        super(Node.class);
+        super(Node.class, NatNodeEventListener.class);
         this.dataBroker = dataBroker;
     }
 
     public void init() {
         LOG.info("{} init", getClass().getSimpleName());
-        listenerRegistration = dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
-                getWildCardPath(), this, AsyncDataBroker.DataChangeScope.SUBTREE);
+        registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
     }
 
-    private InstanceIdentifier<Node> getWildCardPath() {
+    @Override
+    protected InstanceIdentifier<Node> getWildCardPath() {
         return InstanceIdentifier.create(Nodes.class).child(Node.class);
     }
 
     @Override
-    public void close() throws Exception {
-        if (listenerRegistration != null) {
-            listenerRegistration.close();
-            listenerRegistration = null;
-        }
-        LOG.info("{} close", getClass().getSimpleName());
+    protected NatNodeEventListener getDataTreeChangeListener() {
+        return NatNodeEventListener.this;
     }
 
     @Override
     protected void remove(InstanceIdentifier<Node> identifier, Node del) {
-        LOG.debug("NatNodeEventListener: Node removed received");
+        LOG.debug("NAT Service : NatNodeEventListener: Node removed received");
         NodeId nodeId = del.getId();
         String[] node =  nodeId.getValue().split(":");
         if(node.length < 2) {
-            LOG.warn("Unexpected nodeId {}", nodeId.getValue());
+            LOG.warn("NAT Service : Unexpected nodeId {}", nodeId.getValue());
             return;
         }
         BigInteger dpnId = new BigInteger(node[1]);
-        LOG.debug("NodeId removed is {}",dpnId);
+        LOG.debug("NAT Service : NodeId removed is {}",dpnId);
     }
 
     @Override
@@ -69,14 +68,14 @@ public class NatNodeEventListener extends AbstractDataChangeListener<Node> imple
 
     @Override
     protected void add(InstanceIdentifier<Node> identifier, Node add) {
-        LOG.debug("NatNodeEventListener: Node added received");
+        LOG.debug("NAT Service : NatNodeEventListener: Node added received");
         NodeId nodeId = add.getId();
         String[] node =  nodeId.getValue().split(":");
         if(node.length < 2) {
-            LOG.warn("Unexpected nodeId {}", nodeId.getValue());
+            LOG.warn("NAT Service : Unexpected nodeId {}", nodeId.getValue());
             return;
         }
         BigInteger dpnId = new BigInteger(node[1]);
-        LOG.debug("NodeId added is {}",dpnId);
+        LOG.debug("NAT Service : NodeId added is {}",dpnId);
     }
 }
index 43788076d029bcb835fc8fad0397b585382385b3..62ff5d1646455998af8c009142d2794253a69f19 100644 (file)
@@ -13,8 +13,8 @@ import java.util.HashMap;
 import java.util.List;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.genius.mdsalutil.AbstractDataChangeListener;
 import org.opendaylight.genius.mdsalutil.BucketInfo;
 import org.opendaylight.genius.mdsalutil.FlowEntity;
@@ -33,7 +33,8 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class RouterDpnChangeListener extends AbstractDataChangeListener<DpnVpninterfacesList> implements AutoCloseable{
+public class RouterDpnChangeListener extends AsyncDataTreeChangeListenerBase<DpnVpninterfacesList, RouterDpnChangeListener> implements
+        AutoCloseable{
     private static final Logger LOG = LoggerFactory.getLogger(RouterDpnChangeListener.class);
     private ListenerRegistration<DataChangeListener> listenerRegistration;
     private final DataBroker dataBroker;
@@ -48,7 +49,7 @@ public class RouterDpnChangeListener extends AbstractDataChangeListener<DpnVpnin
                                    final NaptSwitchHA naptSwitchHA,
                                    final IdManagerService idManager,
                                    final ExternalNetworkGroupInstaller extNetGroupInstaller) {
-        super(DpnVpninterfacesList.class);
+        super(DpnVpninterfacesList.class, RouterDpnChangeListener.class);
         this.dataBroker = dataBroker;
         this.mdsalManager = mdsalManager;
         this.snatDefaultRouteProgrammer = snatDefaultRouteProgrammer;
@@ -57,23 +58,20 @@ public class RouterDpnChangeListener extends AbstractDataChangeListener<DpnVpnin
         this.extNetGroupInstaller = extNetGroupInstaller;
     }
 
+    @Override
     public void init() {
         LOG.info("{} init", getClass().getSimpleName());
-        listenerRegistration = dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
-                getWildCardPath(), this, AsyncDataBroker.DataChangeScope.SUBTREE);
+        registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
     }
 
-    private InstanceIdentifier<DpnVpninterfacesList> getWildCardPath() {
-        return InstanceIdentifier.create(NeutronRouterDpns.class).child(RouterDpnList.class).child(DpnVpninterfacesList.class);
+    @Override
+    protected RouterDpnChangeListener getDataTreeChangeListener() {
+        return RouterDpnChangeListener.this;
     }
 
     @Override
-    public void close() throws Exception {
-        if (listenerRegistration != null) {
-            listenerRegistration.close();
-            listenerRegistration = null;
-        }
-        LOG.info("{} close", getClass().getSimpleName());
+    protected InstanceIdentifier<DpnVpninterfacesList> getWildCardPath() {
+        return InstanceIdentifier.create(NeutronRouterDpns.class).child(RouterDpnList.class).child(DpnVpninterfacesList.class);
     }
 
     @Override
index b37e9343fddc5b476743fcd57b3519aeba0ae3c4..2ddb68bb660e6807e5faa43a50f51d6a1115048a 100644 (file)
@@ -12,7 +12,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.genius.mdsalutil.AbstractDataChangeListener;
+import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
 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.natservice.rev160111.FloatingIpInfo;
@@ -27,33 +27,30 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class RouterPortsListener extends AbstractDataChangeListener<RouterPorts> implements AutoCloseable{
+public class RouterPortsListener extends AsyncDataTreeChangeListenerBase<RouterPorts, RouterPortsListener> implements AutoCloseable{
     private static final Logger LOG = LoggerFactory.getLogger(RouterPortsListener.class);
     private ListenerRegistration<DataChangeListener> listenerRegistration;
     private final DataBroker dataBroker;
 
     public RouterPortsListener (final DataBroker dataBroker) {
-        super(RouterPorts.class);
+        super(RouterPorts.class, RouterPortsListener.class);
         this.dataBroker = dataBroker;
     }
 
+    @Override
     public void init() {
         LOG.info("{} init", getClass().getSimpleName());
-        listenerRegistration = dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
-                getWildCardPath(), this, AsyncDataBroker.DataChangeScope.SUBTREE);
+        registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
     }
 
-    private InstanceIdentifier<RouterPorts> getWildCardPath() {
+    @Override
+    protected InstanceIdentifier<RouterPorts> getWildCardPath() {
         return InstanceIdentifier.create(FloatingIpInfo.class).child(RouterPorts.class);
     }
 
     @Override
-    public void close() throws Exception {
-        if (listenerRegistration != null) {
-            listenerRegistration.close();
-            listenerRegistration = null;
-        }
-        LOG.info("{} close", getClass().getSimpleName());
+    protected RouterPortsListener getDataTreeChangeListener() {
+        return RouterPortsListener.this;
     }
 
     @Override