Jonathan Hart

Cleaned up HostMonitor and support HostProvider invalidation

...@@ -4,9 +4,9 @@ import java.nio.ByteBuffer; ...@@ -4,9 +4,9 @@ import java.nio.ByteBuffer;
4 import java.util.ArrayList; 4 import java.util.ArrayList;
5 import java.util.HashSet; 5 import java.util.HashSet;
6 import java.util.List; 6 import java.util.List;
7 -import java.util.Map;
8 import java.util.Set; 7 import java.util.Set;
9 import java.util.concurrent.ConcurrentHashMap; 8 import java.util.concurrent.ConcurrentHashMap;
9 +import java.util.concurrent.ConcurrentMap;
10 import java.util.concurrent.TimeUnit; 10 import java.util.concurrent.TimeUnit;
11 11
12 import org.jboss.netty.util.Timeout; 12 import org.jboss.netty.util.Timeout;
...@@ -59,15 +59,14 @@ public class HostMonitor implements TimerTask { ...@@ -59,15 +59,14 @@ public class HostMonitor implements TimerTask {
59 59
60 private final Set<IpAddress> monitoredAddresses; 60 private final Set<IpAddress> monitoredAddresses;
61 61
62 - private final Map<ProviderId, HostProvider> hostProviders; 62 + private final ConcurrentMap<ProviderId, HostProvider> hostProviders;
63 63
64 - private final long probeRate; 64 + private static final long DEFAULT_PROBE_RATE = 30000; // milliseconds
65 + private long probeRate = DEFAULT_PROBE_RATE;
65 66
66 private final Timeout timeout; 67 private final Timeout timeout;
67 68
68 - public HostMonitor( 69 + public HostMonitor(DeviceService deviceService, PacketService packetService,
69 - DeviceService deviceService,
70 - PacketService packetService,
71 HostManager hostService) { 70 HostManager hostService) {
72 71
73 this.deviceService = deviceService; 72 this.deviceService = deviceService;
...@@ -77,15 +76,7 @@ public class HostMonitor implements TimerTask { ...@@ -77,15 +76,7 @@ public class HostMonitor implements TimerTask {
77 monitoredAddresses = new HashSet<>(); 76 monitoredAddresses = new HashSet<>();
78 hostProviders = new ConcurrentHashMap<>(); 77 hostProviders = new ConcurrentHashMap<>();
79 78
80 - probeRate = 30000; // milliseconds
81 -
82 timeout = Timer.getTimer().newTimeout(this, 0, TimeUnit.MILLISECONDS); 79 timeout = Timer.getTimer().newTimeout(this, 0, TimeUnit.MILLISECONDS);
83 -
84 - addDefaultAddresses();
85 - }
86 -
87 - private void addDefaultAddresses() {
88 - //monitoredAddresses.add(IpAddress.valueOf("10.0.0.1"));
89 } 80 }
90 81
91 void addMonitoringFor(IpAddress ip) { 82 void addMonitoringFor(IpAddress ip) {
...@@ -104,10 +95,6 @@ public class HostMonitor implements TimerTask { ...@@ -104,10 +95,6 @@ public class HostMonitor implements TimerTask {
104 hostProviders.put(provider.id(), provider); 95 hostProviders.put(provider.id(), provider);
105 } 96 }
106 97
107 - void unregisterHostProvider(HostProvider provider) {
108 - // TODO find out how to call this
109 - }
110 -
111 @Override 98 @Override
112 public void run(Timeout timeout) throws Exception { 99 public void run(Timeout timeout) throws Exception {
113 for (IpAddress ip : monitoredAddresses) { 100 for (IpAddress ip : monitoredAddresses) {
...@@ -121,7 +108,9 @@ public class HostMonitor implements TimerTask { ...@@ -121,7 +108,9 @@ public class HostMonitor implements TimerTask {
121 } else { 108 } else {
122 for (Host host : hosts) { 109 for (Host host : hosts) {
123 HostProvider provider = hostProviders.get(host.providerId()); 110 HostProvider provider = hostProviders.get(host.providerId());
124 - if (provider != null) { 111 + if (provider == null) {
112 + hostProviders.remove(host.providerId(), null);
113 + } else {
125 provider.triggerProbe(host); 114 provider.triggerProbe(host);
126 } 115 }
127 } 116 }
......