T
- the event which should be observedpublic interface ObserverMethod<T>
ObserverMethod is the SPI to handle an observer method, which is an event consumer for an event of the given type T. An instance of ObserverMethod exists for every observer method of every enabled bean.
A class may have n observer methods.
Each observer method must have a void return value and exactly one parameter
which defines which event it javax.enterprise.event.Observes
.
The observed event may be further specified by using an optional Qualifier.
public class UserHandler { public void afterUserLogin(@Observes UserLoginEvent userHasLoggedIn) { // prepare some data for the user, ... int userId = userHadLoggedIn.getUserId(); ... } public void afterAdminLogin(@Observes @Admin UserLoginEvent userHasLoggedIn) { // prepare stuff for the admin user ... } public void afterUserLogout(@Observes UserLogoutEvent userHasLoggedOut) { // cleanup afterwards ... } }
Observes
Modifier and Type | Method and Description |
---|---|
Class<?> |
getBeanClass() |
Set<Annotation> |
getObservedQualifiers() |
Type |
getObservedType() |
Reception |
getReception() |
TransactionPhase |
getTransactionPhase() |
void |
notify(T event)
will actually cann the underlying observer method
|
Class<?> getBeanClass()
Type getObservedType()
Set<Annotation> getObservedQualifiers()
javax.enterprise.inject.Any
Reception getReception()
Reception#IF_EXISTS
if the observed method must only be called if an instance
of the bean which defines the observer method aready exists in the specified context or Reception#ALWAYS
.TransactionPhase getTransactionPhase()
TransactionPhase
for a transactional observer method or
TransactionPhase#IN_PROGRESS
otherwise.void notify(T event)
event
- Copyright © 2013. All rights reserved.