Package javax.enterprise.inject.spi
Interface ObserverMethod<T>
-
- Type Parameters:
T
- the event which should be observed
public 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
Sample: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 ... } }
- See Also:
Observes
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.Class<?>
getBeanClass()
java.util.Set<java.lang.annotation.Annotation>
getObservedQualifiers()
java.lang.reflect.Type
getObservedType()
Reception
getReception()
TransactionPhase
getTransactionPhase()
void
notify(T event)
will actually cann the underlying observer method
-
-
-
Method Detail
-
getBeanClass
java.lang.Class<?> getBeanClass()
-
getObservedType
java.lang.reflect.Type getObservedType()
- Returns:
- the type of the observed event
-
getObservedQualifiers
java.util.Set<java.lang.annotation.Annotation> getObservedQualifiers()
- Returns:
- the defined Qualifiers plus
javax.enterprise.inject.Any
-
getReception
Reception getReception()
- Returns:
- either
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 orReception#ALWAYS
.
-
getTransactionPhase
TransactionPhase getTransactionPhase()
- Returns:
- the appropriate
TransactionPhase
for a transactional observer method orTransactionPhase#IN_PROGRESS
otherwise.
-
notify
void notify(T event)
will actually cann the underlying observer method- Parameters:
event
-
-
-