Class TransactionAwareEventPublisher

java.lang.Object
com.atlassian.crowd.core.event.DelegatingMultiEventPublisher
com.atlassian.crowd.core.event.TransactionAwareEventPublisher
All Implemented Interfaces:
MultiEventPublisher, com.atlassian.event.api.EventListenerRegistrar, com.atlassian.event.api.EventPublisher

public class TransactionAwareEventPublisher extends DelegatingMultiEventPublisher implements com.atlassian.event.api.EventPublisher, MultiEventPublisher
Delays publishing any events if a transaction is active, until that transaction commits. Events not published in transaction are unaffected. If the active transaction is rolled back, the events are not published.

Note that any transactional operations done in afterCommit(), need to be wrapped in a PROPAGATION_REQUIRES_NEW transaction, (see TransactionSynchronization.afterCommit()). This is guaranteed by TransactionAwareEventDispatcher

Since publishing an event during a transaction causes a TransactionSynchronization to be registered for cases where many events are sent at once, it makes sense to use publishAll(Collection), to wrap them in a single TransactionSynchronization, as transaction performance degrades notably with the number of distinct synchronizations registered.