Brian O'Connor

ONOS-2979 ObjectiveTracker improvements

- Removing unused intent map
- Passing copy of intents to recompile to prevent ConcurrentModificationException
- Dropping Host Updated events (only act on ADDED, MOVED, and REMOVED)

Change-Id: I86520c45f51e74c21cc47aab94a746c0b4135f93
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
16 package org.onosproject.net.intent.impl; 16 package org.onosproject.net.intent.impl;
17 17
18 import com.google.common.collect.HashMultimap; 18 import com.google.common.collect.HashMultimap;
19 +import com.google.common.collect.ImmutableSet;
19 import com.google.common.collect.Lists; 20 import com.google.common.collect.Lists;
20 -import com.google.common.collect.Maps;
21 import com.google.common.collect.SetMultimap; 21 import com.google.common.collect.SetMultimap;
22 import org.apache.felix.scr.annotations.Activate; 22 import org.apache.felix.scr.annotations.Activate;
23 import org.apache.felix.scr.annotations.Component; 23 import org.apache.felix.scr.annotations.Component;
...@@ -61,7 +61,6 @@ import java.util.Collections; ...@@ -61,7 +61,6 @@ import java.util.Collections;
61 import java.util.HashSet; 61 import java.util.HashSet;
62 import java.util.List; 62 import java.util.List;
63 import java.util.Set; 63 import java.util.Set;
64 -import java.util.concurrent.ConcurrentMap;
65 import java.util.concurrent.ExecutorService; 64 import java.util.concurrent.ExecutorService;
66 import java.util.concurrent.Executors; 65 import java.util.concurrent.Executors;
67 import java.util.concurrent.ScheduledExecutorService; 66 import java.util.concurrent.ScheduledExecutorService;
...@@ -91,8 +90,6 @@ public class ObjectiveTracker implements ObjectiveTrackerService { ...@@ -91,8 +90,6 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
91 90
92 private final Logger log = getLogger(getClass()); 91 private final Logger log = getLogger(getClass());
93 92
94 - private final ConcurrentMap<Key, Intent> intents = Maps.newConcurrentMap();
95 -
96 private final SetMultimap<LinkKey, Key> intentsByLink = 93 private final SetMultimap<LinkKey, Key> intentsByLink =
97 //TODO this could be slow as a point of synchronization 94 //TODO this could be slow as a point of synchronization
98 synchronizedSetMultimap(HashMultimap.<LinkKey, Key>create()); 95 synchronizedSetMultimap(HashMultimap.<LinkKey, Key>create());
...@@ -378,7 +375,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService { ...@@ -378,7 +375,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
378 } 375 }
379 376
380 // TODO should we recompile on available==true? 377 // TODO should we recompile on available==true?
381 - delegate.triggerCompile(intentsByDevice.get(id), available); 378 + delegate.triggerCompile(ImmutableSet.copyOf(intentsByDevice.get(id)), available);
382 } 379 }
383 } 380 }
384 381
...@@ -415,7 +412,17 @@ public class ObjectiveTracker implements ObjectiveTrackerService { ...@@ -415,7 +412,17 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
415 @Override 412 @Override
416 public void event(HostEvent event) { 413 public void event(HostEvent event) {
417 HostId id = event.subject().id(); 414 HostId id = event.subject().id();
415 + switch (event.type()) {
416 + case HOST_ADDED:
417 + case HOST_MOVED:
418 + case HOST_REMOVED:
418 executorService.execute(new DeviceAvailabilityHandler(id, false)); 419 executorService.execute(new DeviceAvailabilityHandler(id, false));
420 + break;
421 + case HOST_UPDATED:
422 + default:
423 + // DO NOTHING
424 + break;
425 + }
419 } 426 }
420 } 427 }
421 428
......