Source:
protected void subscribeToGroup() { Preconditions.checkNotNull(group, "The group cannot be null"); LOG.debug("Subscribing to group "+group+", for memberAdded, memberRemoved, serviceUp, and {}", getSensorsToTrack()); subscribe(group, DynamicGroup.MEMBER_ADDED, new SensorEventListener<Entity>() { @Override public void onEvent(SensorEvent<Entity> event) { onEntityEvent(EventType.ENTITY_ADDED, event.getValue()); } }); subscribe(group, DynamicGroup.MEMBER_REMOVED, new SensorEventListener<Entity>() { @Override public void onEvent(SensorEvent<Entity> event) { entitySensorCache.remove(event.getSource().getId()); onEntityEvent(EventType.ENTITY_REMOVED, event.getValue()); } }); for (Sensor<?> sensor : getSensorsToTrack()) { subscribeToMembers(group, sensor, new SensorEventListener<Object>() { boolean hasWarnedOfServiceUp = false; @Override public void onEvent(SensorEvent<Object> event) { boolean notifyOnDuplicates = getRequiredConfig(NOTIFY_ON_DUPLICATES); if (Startable.SERVICE_UP.equals(event.getSensor()) && notifyOnDuplicates && !hasWarnedOfServiceUp) { LOG.warn("Deprecated behaviour: not notifying of duplicate value for service-up in {}, group {}", AbstractMembershipTrackingPolicy.this, group); hasWarnedOfServiceUp = true; notifyOnDuplicates = false; } String entityId = event.getSource().getId(); Map<Sensor<Object>, Object> sensorCache = entitySensorCache.get(entityId); if (sensorCache == null) { sensorCache = MutableMap.<Sensor<Object>, Object>of(); entitySensorCache.put(entityId, sensorCache); } if (!notifyOnDuplicates && Objects.equal(event.getValue(), sensorCache.put(event.getSensor(), event.getValue()))) { return; } onEntityEvent(EventType.ENTITY_CHANGE, event.getSource()); } }); } for (Entity it : group.getMembers()) { onEntityEvent(EventType.ENTITY_ADDED, it); } }

Target:
protected void subscribeToGroup() { Preconditions.checkNotNull(group, "The group cannot be null"); LOG.debug("Subscribing to group "+group+", for memberAdded, memberRemoved, serviceUp, and {}", getSensorsToTrack()); subscribe(group, DynamicGroup.MEMBER_ADDED, new SensorEventListener<Entity>() { @Override public void onEvent(SensorEvent<Entity> event) { onEntityEvent(EventType.ENTITY_ADDED, event.getValue()); } }); subscribe(group, DynamicGroup.MEMBER_REMOVED, new SensorEventListener<Entity>() { @Override public void onEvent(SensorEvent<Entity> event) { entitySensorCache.remove(event.getSource().getId()); onEntityEvent(EventType.ENTITY_REMOVED, event.getValue()); } }); for (Sensor<?> sensor : getSensorsToTrack()) { subscribeToMembers(group, sensor, new SensorEventListener<Object>() { boolean hasWarnedOfServiceUp = false; @Override public void onEvent(SensorEvent<Object> event) { boolean notifyOnDuplicates = getRequiredConfig(NOTIFY_ON_DUPLICATES); if (Startable.SERVICE_UP.equals(event.getSensor()) && notifyOnDuplicates && !hasWarnedOfServiceUp) { LOG.warn("Deprecated behaviour: not notifying of duplicate value for service-up in {}, group {}", AbstractMembershipTrackingPolicy.this, group); hasWarnedOfServiceUp = true; notifyOnDuplicates = false; } String entityId = event.getSource().getId(); Map<Sensor<Object>, Object> newMap = MutableMap.<Sensor<Object>, Object>of(); Map<Sensor<Object>, Object> sensorCache = entitySensorCache.putIfAbsent(entityId, newMap); if (sensorCache == null) { sensorCache = newMap; } if (!notifyOnDuplicates && Objects.equal(event.getValue(), sensorCache.put(event.getSensor(), event.getValue()))) { return; } onEntityEvent(EventType.ENTITY_CHANGE, event.getSource()); } }); } for (Entity it : group.getMembers()) { onEntityEvent(EventType.ENTITY_ADDED, it); } }