我有实现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事件按预期运行
答案 0 :(得分:1)
我找到了解决方法:
@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);
}
}
});
}