Top Description Interfaces Annotations Classes Enums
[default module]

Package jakarta.enterprise.event


Annotations and interfaces relating to events.

Beans may produce and consume events. Events allows beans to interact in a completely decoupled fashion, with no compile-time dependency between the interacting beans. Most importantly, it allows stateful beans in one architectural tier of the application to synchronize their internal state with state changes that occur in a different tier.

Events may be fired synchronously or asynchronously.

An event comprises:

The jakarta.enterprise.event.Event interface is used to fire events.

Event objects and event types

The event object acts as a payload, to propagate state from producer to consumer. An event object is an instance of a concrete Java class with no type variables.

The event types of the event include all superclasses and interfaces of the runtime class of the event object. An event type may not contain a type variable.

Event qualifiers

The event qualifiers act as topic selectors, allowing the consumer to narrow the set of events it observes. An event qualifier may be an instance of any qualifier type.

Observer methods

An observer method allows the application to receive and respond synchronously to event notifications. And an async observer method allows the application to receive and respond asynchronously to event notifications. they both act as event consumers, observing events of a specific type, with a specific set of qualifiers. Any Java type may be observed by an observer method.

An observer method is a method of a bean class or extension with a parameter annotated @Observes or @ObservesAsync.

An observer method will be notified of an event if:

If a synchronous observer method is a transactional observer method and there is a JTA transaction in progress when the event is fired, the observer method is notified during the appropriate transaction completion phase. Otherwise, the observer is notified when the event is fired.

The order in which observer methods are called depends on the value of the @Priority applied to the observer.

If no priority is defined on a observer, its priority is jakarta.interceptor.Interceptor.Priority.APPLICATION+500.

If two observer have the same priority their relative order is undefined.

Observer methods may throw exceptions:

See Also
jakarta.enterprise.inject, jakarta.enterprise.event.Observes, jakarta.enterprise.event.Event, jakarta.inject.Qualifier

Interface Summary

Modifier and TypeInterface and Description
public interface
Event<
the type of the event object
T
>

Allows the application to fire events of a particular type.

public interface
NotificationOptions

Notification options are used to configure observer notification.

Annotation Summary

Modifier and TypeAnnotation and Description
public @interface
Observes

Identifies the event parameter of an observer method.

public @interface
ObservesAsync

Identifies the event parameter of an asynchronous observer method.

Class Summary

Modifier and TypeClass and Description
pack-priv class
ImmutableNotificationOptions

The immutable implementation of NotificationOptions.

public class
ObserverException

Indicates that a checked exception was thrown by an observer method during event notification.

public class
Shutdown

A CDI event with payload of type Shutdown and qualifier jakarta.enterprise.inject.Any is synchronously fired by CDI container during application shutdown.

public class
Startup

A CDI event with payload of type Startup and qualifier jakarta.enterprise.inject.Any is synchronously fired by CDI container during application initialization.

Enum Summary

Modifier and TypeEnum and Description
public enum
Reception

Distinguishes conditional observer methods from observer methods which are always notified.

public enum
TransactionPhase

Distinguishes the various kinds of transactional observer methods from regular observer methods which are notified immediately.