T - the event which should be observedpublic interface ObserverMethod<T> extends Prioritized
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 | Field and Description |
|---|---|
static int |
DEFAULT_PRIORITY
The default Priority of any ObserverMethod without a @Priority annotation.
|
| Modifier and Type | Method and Description |
|---|---|
Class<?> |
getBeanClass() |
Set<Annotation> |
getObservedQualifiers() |
Type |
getObservedType() |
default int |
getPriority()
Only synchronous ObserverMethods can be ordered!
|
Reception |
getReception() |
TransactionPhase |
getTransactionPhase() |
default boolean |
isAsync() |
default void |
notify(EventContext<T> eventContext)
Call the observer method with the given eventContext.
|
default void |
notify(T event)
will actually call the underlying observer method
|
static final int DEFAULT_PRIORITY
Class<?> getBeanClass()
Type getObservedType()
Set<Annotation> getObservedQualifiers()
javax.enterprise.inject.AnyReception 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.default void notify(T event)
event - default void notify(EventContext<T> eventContext)
eventContext - default boolean isAsync()
default int getPriority()
getPriority in interface PrioritizedCopyright © 2025. All rights reserved.