fix for host remove event when an instance comes back online
Change-Id: Ie9099eabcda7f7e0435a09eeca17e2f8954e051d
Showing
1 changed file
with
12 additions
and
4 deletions
... | @@ -105,6 +105,8 @@ public class DistributedHostStore | ... | @@ -105,6 +105,8 @@ public class DistributedHostStore |
105 | 105 | ||
106 | hosts = host.asJavaMap(); | 106 | hosts = host.asJavaMap(); |
107 | 107 | ||
108 | + prevHosts.putAll(hosts); | ||
109 | + | ||
108 | host.addListener(hostLocationTracker); | 110 | host.addListener(hostLocationTracker); |
109 | 111 | ||
110 | log.info("Started"); | 112 | log.info("Started"); |
... | @@ -293,19 +295,25 @@ public class DistributedHostStore | ... | @@ -293,19 +295,25 @@ public class DistributedHostStore |
293 | @Override | 295 | @Override |
294 | public void event(MapEvent<HostId, DefaultHost> event) { | 296 | public void event(MapEvent<HostId, DefaultHost> event) { |
295 | DefaultHost host = checkNotNull(event.value().value()); | 297 | DefaultHost host = checkNotNull(event.value().value()); |
296 | - if (event.type() == MapEvent.Type.INSERT) { | ||
297 | Host prevHost = prevHosts.put(host.id(), host); | 298 | Host prevHost = prevHosts.put(host.id(), host); |
298 | - if (prevHost == null) { | 299 | + switch (event.type()) { |
300 | + case INSERT: | ||
299 | notifyDelegate(new HostEvent(HOST_ADDED, host)); | 301 | notifyDelegate(new HostEvent(HOST_ADDED, host)); |
300 | - } else if (!Objects.equals(prevHost.location(), host.location())) { | 302 | + break; |
303 | + case UPDATE: | ||
304 | + if (!Objects.equals(prevHost.location(), host.location())) { | ||
301 | notifyDelegate(new HostEvent(HOST_MOVED, host, prevHost)); | 305 | notifyDelegate(new HostEvent(HOST_MOVED, host, prevHost)); |
302 | } else if (!Objects.equals(prevHost, host)) { | 306 | } else if (!Objects.equals(prevHost, host)) { |
303 | notifyDelegate(new HostEvent(HOST_UPDATED, host, prevHost)); | 307 | notifyDelegate(new HostEvent(HOST_UPDATED, host, prevHost)); |
304 | } | 308 | } |
305 | - } else if (event.type() == MapEvent.Type.REMOVE) { | 309 | + break; |
310 | + case REMOVE: | ||
306 | if (prevHosts.remove(host.id()) != null) { | 311 | if (prevHosts.remove(host.id()) != null) { |
307 | notifyDelegate(new HostEvent(HOST_REMOVED, host)); | 312 | notifyDelegate(new HostEvent(HOST_REMOVED, host)); |
308 | } | 313 | } |
314 | + break; | ||
315 | + default: | ||
316 | + log.warn("Unknown map event type: {}", event.type()); | ||
309 | } | 317 | } |
310 | } | 318 | } |
311 | } | 319 | } | ... | ... |
-
Please register or login to post a comment