ObservationManager obsMgr = getSession().getWorkspace().getObservationManager();
obsMgr.addEventListener(new EventListener() {
@Override
public void onEvent(EventIterator events) {
while (events.hasNext()) {
Event event = events.nextEvent();
try {
switch (event.getType()) {
case Event.NODE_ADDED:
if (!addNodes.remove(event.getPath())) {
failedEvents.add(event);
}
break;
case Event.NODE_REMOVED:
if (!removeNodes.remove(event.getPath())) {
failedEvents.add(event);
}
break;
case Event.PROPERTY_ADDED:
if (!addProperties.remove(event.getPath())) {
failedEvents.add(event);
}
break;
case Event.PROPERTY_CHANGED:
if (!setProperties.remove(event.getPath())) {
failedEvents.add(event);
}
break;
case Event.PROPERTY_REMOVED:
if (!removeProperties.remove(event.getPath())) {
failedEvents.add(event);
}
break;
default:
failedEvents.add(event);