Migrate HashedWheelTimer to netty 4
- moved potentially time consuming task to
shared ScheduledThreadPoolExecutor
Change-Id: I8e77041e0f84bd2bdfd6ae6704f4e39b81c721dd
diff --git a/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java b/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java
index e365236..2150bf1 100644
--- a/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java
+++ b/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java
@@ -15,8 +15,6 @@
*/
package org.onosproject.net.host.impl;
-import org.jboss.netty.util.Timeout;
-import org.jboss.netty.util.TimerTask;
import org.onlab.packet.ARP;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IPv6;
@@ -26,7 +24,7 @@
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onlab.packet.ndp.NeighborSolicitation;
-import org.onlab.util.Timer;
+import org.onlab.util.SharedScheduledExecutors;
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Host;
@@ -46,6 +44,7 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
/**
@@ -56,7 +55,7 @@
* probe for hosts that have not yet been detected (specified by IP address).
* </p>
*/
-public class HostMonitor implements TimerTask {
+public class HostMonitor implements Runnable {
private Logger log = LoggerFactory.getLogger(getClass());
@@ -73,7 +72,7 @@
private static final byte[] ZERO_MAC_ADDRESS = MacAddress.ZERO.toBytes();
private long probeRate = DEFAULT_PROBE_RATE;
- private Timeout timeout;
+ private ScheduledFuture<?> timeout;
/**
* Creates a new host monitor.
@@ -124,7 +123,7 @@
void start() {
synchronized (this) {
if (timeout == null) {
- timeout = Timer.getTimer().newTimeout(this, 0, TimeUnit.MILLISECONDS);
+ timeout = SharedScheduledExecutors.newTimeout(this, 0, TimeUnit.MILLISECONDS);
}
}
}
@@ -134,7 +133,7 @@
*/
void shutdown() {
synchronized (this) {
- timeout.cancel();
+ timeout.cancel(true);
timeout = null;
}
}
@@ -157,11 +156,11 @@
}
@Override
- public void run(Timeout timeout) throws Exception {
+ public void run() {
monitoredAddresses.forEach(this::probe);
synchronized (this) {
- this.timeout = Timer.getTimer().newTimeout(this, probeRate, TimeUnit.MILLISECONDS);
+ this.timeout = SharedScheduledExecutors.newTimeout(this, probeRate, TimeUnit.MILLISECONDS);
}
}