Fix warnings in topology-lldp-discovery
[openflowplugin.git] / applications / topology-lldp-discovery / src / main / java / org / opendaylight / openflowplugin / applications / topology / lldp / LLDPLinkAger.java
index c6a38365cefbd9c5d3b796e3fc5a0726b0d33d23..c4404d9d97c654259edc226ec67328a8e783b377 100644 (file)
@@ -8,19 +8,17 @@
 package org.opendaylight.openflowplugin.applications.topology.lldp;
 
 import com.google.common.annotations.VisibleForTesting;
-import java.util.Collection;
 import java.util.Date;
-import java.util.Map;
+import java.util.List;
 import java.util.Map.Entry;
 import java.util.Timer;
 import java.util.TimerTask;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
-import org.apache.aries.blueprint.annotation.service.Reference;
 import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.mdsal.binding.api.ClusteredDataTreeChangeListener;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.DataObjectModification;
 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
@@ -43,25 +41,26 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Singleton
-public class LLDPLinkAger implements ConfigurationListener, ClusteredDataTreeChangeListener<Link>, AutoCloseable {
+public final class LLDPLinkAger implements ConfigurationListener, DataTreeChangeListener<Link>, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(LLDPLinkAger.class);
     static final String TOPOLOGY_ID = "flow:1";
     static final InstanceIdentifier<Link> II_TO_LINK = InstanceIdentifier.create(NetworkTopology.class)
             .child(Topology.class, new TopologyKey(new TopologyId(TOPOLOGY_ID))).child(Link.class);
 
     private final long linkExpirationTime;
-    private final Map<LinkDiscovered, Date> linkToDate;
-    private final Timer timer;
+    // FIXME: use Instant instead of Date
+    private final ConcurrentMap<LinkDiscovered, Date> linkToDate = new ConcurrentHashMap<>();
+    private final Timer timer = new Timer();
     private final NotificationPublishService notificationService;
     private final AutoCloseable configurationServiceRegistration;
     private final EntityOwnershipService eos;
-    private ListenerRegistration<DataTreeChangeListener> listenerRegistration;
+    private Registration listenerRegistration;
 
     /**
      * default ctor - start timer.
@@ -69,20 +68,18 @@ public class LLDPLinkAger implements ConfigurationListener, ClusteredDataTreeCha
     @Inject
     @SuppressWarnings("checkstyle:IllegalCatch")
     public LLDPLinkAger(final TopologyLldpDiscoveryConfig topologyLldpDiscoveryConfig,
-                        @Reference final NotificationPublishService notificationService,
-                        @Reference final ConfigurationService configurationService,
-                        @Reference final EntityOwnershipService entityOwnershipService,
-                        @Reference final DataBroker dataBroker) {
-        this.linkExpirationTime = topologyLldpDiscoveryConfig.getTopologyLldpExpirationInterval().getValue().toJava();
+                        final NotificationPublishService notificationService,
+                        final ConfigurationService configurationService,
+                        final EntityOwnershipService entityOwnershipService,
+                        final DataBroker dataBroker) {
+        linkExpirationTime = topologyLldpDiscoveryConfig.getTopologyLldpExpirationInterval().getValue().toJava();
         this.notificationService = notificationService;
-        this.configurationServiceRegistration = configurationService.registerListener(this);
-        this.eos = entityOwnershipService;
-        linkToDate = new ConcurrentHashMap<>();
-        timer = new Timer();
-        final DataTreeIdentifier dtiToNodeConnector = DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
+        configurationServiceRegistration = configurationService.registerListener(this);
+        eos = entityOwnershipService;
+        final DataTreeIdentifier<Link> dtiToNodeConnector = DataTreeIdentifier.of(LogicalDatastoreType.OPERATIONAL,
                 II_TO_LINK);
         try {
-            listenerRegistration = dataBroker.registerDataTreeChangeListener(dtiToNodeConnector, LLDPLinkAger.this);
+            listenerRegistration = dataBroker.registerTreeChangeListener(dtiToNodeConnector, this);
         } catch (Exception e) {
             LOG.error("DataTreeChangeListeners registration failed:", e);
             throw new IllegalStateException("LLDPLinkAger startup failed!", e);
@@ -91,7 +88,7 @@ public class LLDPLinkAger implements ConfigurationListener, ClusteredDataTreeCha
             topologyLldpDiscoveryConfig.getTopologyLldpInterval().getValue().toJava());
     }
 
-    public void put(LinkDiscovered link) {
+    public void put(final LinkDiscovered link) {
         Date expires = new Date();
         expires.setTime(expires.getTime() + linkExpirationTime);
         linkToDate.put(link, expires);
@@ -110,9 +107,9 @@ public class LLDPLinkAger implements ConfigurationListener, ClusteredDataTreeCha
     }
 
     @Override
-    public void onDataTreeChanged(@NonNull Collection<DataTreeModification<Link>> changes) {
-        for (DataTreeModification modification : changes) {
-            switch (modification.getRootNode().getModificationType()) {
+    public void onDataTreeChanged(final List<DataTreeModification<Link>> changes) {
+        for (DataTreeModification<Link> modification : changes) {
+            switch (modification.getRootNode().modificationType()) {
                 case WRITE:
                     break;
                 case SUBTREE_MODIFIED:
@@ -122,7 +119,7 @@ public class LLDPLinkAger implements ConfigurationListener, ClusteredDataTreeCha
                     processLinkDeleted(modification.getRootNode());
                     break;
                 default:
-                    LOG.error("Unhandled modification type: {}", modification.getRootNode().getModificationType());
+                    LOG.error("Unhandled modification type: {}", modification.getRootNode().modificationType());
             }
         }
     }
@@ -154,14 +151,14 @@ public class LLDPLinkAger implements ConfigurationListener, ClusteredDataTreeCha
         return linkToDate.containsKey(linkDiscovered);
     }
 
-    private void processLinkDeleted(DataObjectModification rootNode) {
-        Link link = (Link) rootNode.getDataBefore();
+    private void processLinkDeleted(final DataObjectModification<Link> rootNode) {
+        Link link = rootNode.dataBefore();
         LOG.trace("Removing link {} from linkToDate cache", link);
         LinkDiscovered linkDiscovered = LLDPDiscoveryUtils.toLLDPLinkDiscovered(link);
         linkToDate.remove(linkDiscovered);
     }
 
-    private class LLDPAgingTask extends TimerTask {
+    private final class LLDPAgingTask extends TimerTask {
         @Override
         public void run() {
             for (Entry<LinkDiscovered, Date> entry : linkToDate.entrySet()) {