Events processed in reverse order from how they were fired during a transaction
joshuak Oct 31, 2014 2:54 PMHello again,
During the course of a transaction, I have several different events fired representing the lifecycle of some entity or entities. As expected, the IN_PROGRESS transactional observers are immediately processed for a given event. Also as expected, the AFTER_SUCCESS, etc. observers are registered with JTA to be processed after the transaction is complete. What is not expected is the order in which the events themselves are processed after the transaction completes. Note that I am NOT referring to the processing order of observers for any specific event, as I know this ordering is not guaranteed by the spec.
The snippet below is a section of my log (anonymized with internal package names removed) that is a clear example of this issue.
2014-10-31 17:51:18,801 FINEST [DAO.fireEvent] (default task-102) Fired event EntityType1 with id 1 fired with qualifiers [@Created()]
2014-10-31 17:51:18,803 FINEST [EntityFired.inProgress] (default task-102) Observed event EntityType1 with id 1 fired with qualifiers [@javax.enterprise.inject.Any(), @Created()]
2014-10-31 17:51:18,873 FINEST [DAO.fireEvent] (default task-102) Fired event EntityType2 with id 1 fired with qualifiers [@Created()]
2014-10-31 17:51:18,875 FINEST [EntityFired.inProgress] (default task-102) Observed event EntityType2 with id 1 fired with qualifiers [@javax.enterprise.inject.Any(), @Created()]
2014-10-31 17:51:18,890 FINEST [EntityFired.afterSuccess] (default task-102) Observed event EntityType2 with id 1 fired with qualifiers [@javax.enterprise.inject.Any(), @Created()]
2014-10-31 17:51:18,918 FINEST [EntityFired.afterSuccess] (default task-102) Observed event EntityType1 with id 1 fired with qualifiers [@javax.enterprise.inject.Any(), @Created()]
My questions are: Is this intended? Is this just a side-effect of the way JTA handles Synchronizations? Is there some configuration I can change to ensure that events are fired in the same order after the transaction as they were fired during it?
EDIT
I've found some additional information that seems to suggest that Synchronizations themselves are not ordered.
[JBTM-2259] Allow the ordering of some synchronizations to be configurable - JBoss Issue Tracker
As per the spec (10.5. Observer notification), CDI uses Synchronizations to register the after completion observers, so could this be directly related to my issue?