event object - a Java object
zero or more qualifier types - the event qualifiers
@Any: default qualifier
obtain javax.enterprise.event.Event<CustomEventType> by injection:
@Inject @QualifierType Event<CustomEventType> customEvent;
call fire method with payload:
customEvent.fire(customEventTypeInstance)
Optionally, call event.select to choose child event before firing.
public void creditPayment(@Observes @Credit PaymentEvent event) {
...
}
public void debitPayment(@Observes @Debit PaymentEvent event) {
...
}
takes a parameter of an event of a specific event type
annotated @Observers + qualifiers
can take additional parameters - they are injection points
conditional or transactional
conditional - fire only observer exists
@Observes(notifyObserver=IF_EXISTS): be notified only if an instance of the bean defines the observer method already exists in the current context
@Observes(notifyObserver=ALWAYS): default, unconditional behavior
transactional: be notified during the phase of the transaction in which the event was fired or on success / failure
@Observes(during=BEFORE_COMPLETION) - may call "setRollbackOnly"
@Observes(during=AFTER_COMPLETION)
@Observes(during=AFTER_SUCCESS)
@Observes(during=AFTER_FAILURE)
@Observes(during=IN_PROGRESS): default, non-transactional
exceptions
non-transactional observer: terminates processing of the event and no other observer methods or event called
transactional observer: caught by container