If an observer method wishes to receive events as part of the before or after completion phases of a transaction in which the event was fired, they are referred to as transactional observer methods.
We could incorporate the transaction phase into our preceding observer with the following:
public void refreshOnBookRemoval (@Observes( during = AFTER_SUCCESS ) @Removed Book bk) { ... }
The possible values for during
are defined on javax.enterprise.event.TransactionPhase
. In the context of a transactional observer method, the values for TransactionPhase
have the following meanings:
IN_PROGRESS
: An observer method is called immediately. As this is the default value for all observers, there is no need to set it if the standard behavior is required.BEFORE_COMPLETION
: An observer method is triggered during the before completion phase of the transaction.AFTER_COMPLETION
: An observer method is triggered during the after completion phase of the transaction...