fix for host remove event when an instance comes back online
Change-Id: Ie9099eabcda7f7e0435a09eeca17e2f8954e051d
Showing
1 changed file
with
20 additions
and
12 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) { | 298 | + Host prevHost = prevHosts.put(host.id(), host); |
297 | - Host prevHost = prevHosts.put(host.id(), host); | 299 | + switch (event.type()) { |
298 | - if (prevHost == null) { | 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; |
301 | - notifyDelegate(new HostEvent(HOST_MOVED, host, prevHost)); | 303 | + case UPDATE: |
302 | - } else if (!Objects.equals(prevHost, host)) { | 304 | + if (!Objects.equals(prevHost.location(), host.location())) { |
303 | - notifyDelegate(new HostEvent(HOST_UPDATED, host, prevHost)); | 305 | + notifyDelegate(new HostEvent(HOST_MOVED, host, prevHost)); |
304 | - } | 306 | + } else if (!Objects.equals(prevHost, host)) { |
305 | - } else if (event.type() == MapEvent.Type.REMOVE) { | 307 | + notifyDelegate(new HostEvent(HOST_UPDATED, host, prevHost)); |
306 | - if (prevHosts.remove(host.id()) != null) { | 308 | + } |
307 | - notifyDelegate(new HostEvent(HOST_REMOVED, host)); | 309 | + break; |
308 | - } | 310 | + case REMOVE: |
311 | + if (prevHosts.remove(host.id()) != null) { | ||
312 | + notifyDelegate(new HostEvent(HOST_REMOVED, host)); | ||
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