EventListener questions
eldaryus Jul 24, 2014 3:25 PMHi,
I've been trying to use EventListeners with ModeShape 3.8 and I have several questions regarding it:
1. ObservationManager.addEventListener JavaDoc says that nodeTypeName restrictions
are "ANDed" together. In other words, for a particular node to be "listened to" it must meet all the restrictions
however JCR 2.0 spec says that
Only events whose associated parent node is of one of the node types in the nodeTypeNames String array will be received.
That is, restricions are ORed. Which one is correct? It seems that ModeShape implements it as in the spec.
2. noLocal restriction doesn't seem to be working in ModeShape. I've created a dedicated session for event handling and registered the listener via eventSession.getWorkspace().getObservationManager() with noLocal = true
However, when I'm updating the repository via the other session, the event doesn't get triggered at all.
I tried to debug this a little and the session comparison in JcrObservationManager is being done using session.context().getProcessId(), however this parameter is the same for all the sessions that I create. As far as I understand, whenever a new session is created, an ExecutionContext is copied from the repository one, and it seems that the processId gets copied too, so perhaps this is the reason?
3. My listener creates additional nodes (using the eventSession), and this triggers events. Since I can't use noLocal flag, JcrObservationManager tries to see if it should notify my listeners about these nodes creation. However, at this point I'm getting the following exception:
javax.jcr.PathNotFoundException: No node exists at path '/repository/newNode' in workspace "default"
at org.modeshape.jcr.JcrSession.cachedNode(JcrSession.java:610)
at org.modeshape.jcr.JcrSession.node(JcrSession.java:640)
at org.modeshape.jcr.JcrSession.node(JcrSession.java:659)
at org.modeshape.jcr.JcrObservationManager$JcrListenerAdapter.acceptBasedOnNodeTypeName(JcrObservationManager.java:1072)
at org.modeshape.jcr.JcrObservationManager$JcrListenerAdapter.shouldReject(JcrObservationManager.java:996)
at org.modeshape.jcr.JcrObservationManager$JcrListenerAdapter.processChange(JcrObservationManager.java:852)
at org.modeshape.jcr.JcrObservationManager$JcrListenerAdapter.notify(JcrObservationManager.java:828)
at org.modeshape.jcr.bus.RepositoryChangeBus$ChangeSetDispatcher.call(RepositoryChangeBus.java:227)
at org.modeshape.jcr.bus.RepositoryChangeBus$ChangeSetDispatcher.call(RepositoryChangeBus.java:209)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Is this expected behaviour? Am I allowed to create new nodes in the Event Listeners?