Source:
<code>public void init() { boolean disablePublish = Boolean.parseBoolean(properties.getProperty(DISABLE_PUBLISH_FILTERING_PROP, DISABLE_PUBLISH_FILTERING_ENV, "false")); boolean resetCache = Boolean.parseBoolean(properties.getProperty(RESET_PUBLISH_CACHE_PROP, RESET_PUBLISH_CACHE_ENV, "true")); if (!disablePublish) { if (resetCache) { msgLog.warnClearPublishCache(); publishCache.clear(); publishDataIdsCache.clear(); } msgLog.infoInitPublishCache(); initialCacheUpdate(); definitions.registerListener(events -> { log.debugf("Receiving %s", events); events.stream() <START> .sorted((e1, e2) -> e1.getType() == TRIGGER_REMOVE ? 1 : -1) END> .forEach(e -> { log.debugf("Received %s", e); String tenantId = e.getTargetTenantId(); String triggerId = e.getTargetId(); TriggerKey triggerKey = new TriggerKey(tenantId, triggerId); publishCache.startBatch(); publishDataIdsCache.startBatch(); if (e.getType().equals(TRIGGER_REMOVE)) { Set<String> oldDataIds = publishDataIdsCache.get(triggerKey); removePublishCache(tenantId, triggerId, oldDataIds); publishDataIdsCache.remove(triggerKey); } else if (e.getType().equals(TRIGGER_CONDITION_CHANGE)) { Set<String> oldDataIds = publishDataIdsCache.getOrDefault(triggerKey, Collections.emptySet()); Set<String> newDataIds = e.getDataIds(); if (!oldDataIds.equals(newDataIds)) { removePublishCache(tenantId, triggerId, oldDataIds); addPublishCache(tenantId, triggerId, newDataIds); publishDataIdsCache.put(triggerKey, newDataIds); } } publishDataIdsCache.endBatch(true); publishCache.endBatch(true); }); }, TRIGGER_CONDITION_CHANGE, TRIGGER_REMOVE); } else { msgLog.warnDisabledPublishCache(); } }</code><technical_language>I is fine order is preserved. if tests passing I merge it</technical_language>

Target:
public void init() { boolean disablePublish = Boolean.parseBoolean(properties.getProperty(DISABLE_PUBLISH_FILTERING_PROP, DISABLE_PUBLISH_FILTERING_ENV, "false")); boolean resetCache = Boolean.parseBoolean(properties.getProperty(RESET_PUBLISH_CACHE_PROP, RESET_PUBLISH_CACHE_ENV, "true")); if (!disablePublish) { if (resetCache) { msgLog.warnClearPublishCache(); publishCache.clear(); publishDataIdsCache.clear(); } msgLog.infoInitPublishCache(); initialCacheUpdate(); definitions.registerListener(events -> { log.debugf("Receiving %s", events); events.stream() .forEach(e -> { log.debugf("Received %s", e); String tenantId = e.getTargetTenantId(); String triggerId = e.getTargetId(); TriggerKey triggerKey = new TriggerKey(tenantId, triggerId); publishCache.startBatch(); publishDataIdsCache.startBatch(); switch (e.getType()) { case TRIGGER_CONDITION_CHANGE: { Set<String> oldDataIds = publishDataIdsCache.getOrDefault(triggerKey, Collections.emptySet()); Set<String> newDataIds = e.getDataIds(); if (!oldDataIds.equals(newDataIds)) { removePublishCache(tenantId, triggerId, oldDataIds); addPublishCache(tenantId, triggerId, newDataIds); publishDataIdsCache.put(triggerKey, newDataIds); } break; } case TRIGGER_REMOVE: { Set<String> oldDataIds = publishDataIdsCache.get(triggerKey); removePublishCache(tenantId, triggerId, oldDataIds); publishDataIdsCache.remove(triggerKey); break; } default: throw new IllegalStateException("Unexpected notification: " + e.toString()); } publishDataIdsCache.endBatch(true); publishCache.endBatch(true); }); }, TRIGGER_CONDITION_CHANGE, TRIGGER_REMOVE); } else { msgLog.warnDisabledPublishCache(); } }