如何在 AEM 中使用 EventListener 处理节点移动事件?出现重复调用

How to process node move event with EventListener in AEM? Duplicate calls occurs

我有实现 javax.jcr.observation.EventListener 的服务。此服务正在侦听以下事件类型:

当我移动节点时 myCustomCodeToExecute() 方法被触发了两次。

有没有办法在有人移动节点时只触发一次我的代码?

    executor.submit(() -> {
        List<Event> eventsList = IteratorUtils.toList(eventIterator);
        for (final Event event : eventsList) {
            try {
                myCustomCodeToExecute()
            } catch (Exception e) {
                LOGGER.error("Can't send event", e);
            }
        }
    });

REMOVE 事件按预期工作

我找到了解决方案:

@Override
public void onEvent(EventIterator eventIterator) {
    executor.submit(() -> {
        List<Event> eventsList = IteratorUtils.toList(eventIterator);
        for (final Event event : eventsList) {
            try {
                if (eventType == Event.NODE_REMOVED) {
                    if (eventsList.stream().noneMatch(e -> Event.NODE_MOVED == e.getType())) {
                         //remove event
                    }
                         //move event will be processed in next iteration
                         continue;
                    }
                }
            } catch (Exception e) {
                LOGGER.error("Can't send event", e);
            }
        }
    });
}