2 Replies Latest reply on Nov 30, 2011 12:32 PM by Jonathan Fields

    Observation: PROPERTY_ADDED fired, but new Property not found

    Jonathan Fields Novice

      I'm using Modeshape 2.6.0.Final and JBoss AS 6 kit.


      An MDB driven from a JMS queue adds a property to a node, then does session.save() and session.logout(). The new property is successfully added to the node.


      A JCR EventListener was previously  registered to listen for PROPERTY_ADDED. The  property added by the MDB causes the listener to be invoked with an Event.PROPERTY_ADDED Event. However, session.getProperty(event.getPath()) in the EventListener fails with javax.jcr.PathNotFoundException.


      I'm guessing this is a race condition between the MDB thread and the EventListener thread, in that the event is delivered before the session.save() is complete.


      I can probably solve the problem by looping in EventListener on session.getProperty() until the new property "appears".


      What's the intended behavior? If this is a bug, let me know and I'll submit a JIRA.




        • 1. Re: Observation: PROPERTY_ADDED fired, but new Property not found
          Randall Hauch Master

          The events are not be fired before the changes are actually persisted to the connector, so what's actually happening is that the session likely doesn't "see" the property because it's already read the node without the new property. This is a side-effect of the "copy-on-read" behavior of ModeShape.


          In what session are you trying to get the property? You should *not* be doing this work on the session that the listener was registered with; instead, you should be creating a new session. If you're reusing a session that existed prior to the property being added, you'll have to refresh the node (or the entire session) to see the changes on that property.


          BTW, this behavior will be different in 3.0: we're actually changing the session's behavior to so that it sees its changes applied on top of the existing persisted state. This is almost "copy-on-write", except that a session never "copies" anything but merely holds onto the transient changes made with the session.

          • 2. Re: Observation: PROPERTY_ADDED fired, but new Property not found
            Jonathan Fields Novice

            I was trying to get the property in the (long running) EventListener Session, so that is the problem.


            Basically, the EventListener receives the Events, and puts messages onto a JMS queue based only upon the information in the Event itself.


            However, in this particular case, it was attempting to get the property, because it's value determines what goes into the JMS message.  Everywhere else, I was only accessing the Event, and not doing anything with the Session.


            I'll change that so the EventListener  forwards the Events to another Session to actually handle them.