I have service that implements javax.jcr.observation.EventListener. This service is listening the following event types:
When I move node myCustomCodeToExecute()
method is triggered twice.
Is there a way to trigger my code only once if someone moves node?
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 event works as expected
I found an solution:
@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);
}
}
});
}