4 Replies Latest reply on Jan 11, 2010 3:00 AM by galder.zamarreno

    CacheListener is (unduly) notified of rollbacked operations

      I need to be notified of NodeModifiedEvents.
      When i update my node I do receive a notification which is fine.

      But when the modification is rollbacked, i still receive the notification even though the event describes a rolled back operation!

      Sounds like a bug to me since you should only be notified of things that really changed the system state, not things that were cancelled or rolled back.
      I'm using Core 3.2.

        • 1. Re: CacheListener is (unduly) notified of rollbacked operati
          galder.zamarreno

          Modifications are only rolledback when there're transactions and for such notifications, there's @TransactionCompleted and its TransactionCompletedEvent that contains:

          /**
           * @return if <tt>true</tt>, the transaction completed by committing successfully. If <tt>false</tt>, the transaction
           * completed with a rollback.
           */
           boolean isSuccessful();


          • 2. Re: CacheListener is (unduly) notified of rollbacked operati

            Do you mean something like i should accumulate events, clear the accumulating list on TransactionCompletedEvent, and re-fire the accumulated events on TransactionCompletedEvent if isSuccessful is true?

            I have seen this workaround mentionned in the PojoCacheListener javadoc, but i don't understand why JBPC doesn't already do this by himself.
            I can't think of a use case where you would need to be notified of rolled back events.

            • 3. Re: CacheListener is (unduly) notified of rollbacked operati

              The CacheListener is a local observer: it sees changes to the local copy of the cache.
              If a transaction is started on the "master" node (master for a given interaction, otherwise nodes need not be symmetric), and it is rolled back, changes are not replicated to the slave nodes.
              Thus on slave nodes, the CacheListener is not notified of any change on rollback.
              So the only problem is that the master node's CacheListener IS notified even in case of rollback.

              So you don't need the workaround if, on the master node, you don't need the notification.

              • 4. Re: CacheListener is (unduly) notified of rollbacked operati
                galder.zamarreno
                I'm not sure what your problem is with the master node. If you implement @TransactionRegistered you can know when a transaction started and any @NodeModified events you receive between when @TransactionRegistered was called and when @TransactionCompleted is received, you know these are not final unless you receive TransactionCompletedEvent.isSuccessful=true, otherwise you should be able to discard them.