LinkDiscovery: only reschedule if not requested to stop
Change-Id: If2ac04fbc81afec95137fbdbe22afa0c7f826e4a
Showing
1 changed file
with
7 additions
and
3 deletions
... | @@ -82,7 +82,7 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -82,7 +82,7 @@ public class LinkDiscovery implements TimerTask { |
82 | private final PacketService pktService; | 82 | private final PacketService pktService; |
83 | private final MastershipService mastershipService; | 83 | private final MastershipService mastershipService; |
84 | private Timeout timeout; | 84 | private Timeout timeout; |
85 | - private boolean isStopped; | 85 | + private volatile boolean isStopped; |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * Instantiates discovery manager for the given physical switch. Creates a | 88 | * Instantiates discovery manager for the given physical switch. Creates a |
... | @@ -243,8 +243,10 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -243,8 +243,10 @@ public class LinkDiscovery implements TimerTask { |
243 | public void run(final Timeout t) { | 243 | public void run(final Timeout t) { |
244 | boolean isMaster = mastershipService.getLocalRole(device.id()) == MASTER; | 244 | boolean isMaster = mastershipService.getLocalRole(device.id()) == MASTER; |
245 | if (!isMaster) { | 245 | if (!isMaster) { |
246 | + if (!isStopped()) { | ||
246 | // reschedule timer | 247 | // reschedule timer |
247 | timeout = Timer.getTimer().newTimeout(this, this.probeRate, MILLISECONDS); | 248 | timeout = Timer.getTimer().newTimeout(this, this.probeRate, MILLISECONDS); |
249 | + } | ||
248 | return; | 250 | return; |
249 | } | 251 | } |
250 | 252 | ||
... | @@ -280,16 +282,18 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -280,16 +282,18 @@ public class LinkDiscovery implements TimerTask { |
280 | } | 282 | } |
281 | } | 283 | } |
282 | 284 | ||
285 | + if (!isStopped()) { | ||
283 | // reschedule timer | 286 | // reschedule timer |
284 | timeout = Timer.getTimer().newTimeout(this, this.probeRate, MILLISECONDS); | 287 | timeout = Timer.getTimer().newTimeout(this, this.probeRate, MILLISECONDS); |
285 | } | 288 | } |
289 | + } | ||
286 | 290 | ||
287 | - public void stop() { | 291 | + public synchronized void stop() { |
288 | timeout.cancel(); | 292 | timeout.cancel(); |
289 | isStopped = true; | 293 | isStopped = true; |
290 | } | 294 | } |
291 | 295 | ||
292 | - public void start() { | 296 | + public synchronized void start() { |
293 | if (isStopped) { | 297 | if (isStopped) { |
294 | timeout = Timer.getTimer().newTimeout(this, 0, MILLISECONDS); | 298 | timeout = Timer.getTimer().newTimeout(this, 0, MILLISECONDS); |
295 | isStopped = false; | 299 | isStopped = false; | ... | ... |
-
Please register or login to post a comment