PayloadApplicationEvent<T extends Object> class
The envelope the context puts around a published object that is not an ApplicationEvent, adding a source and a timestamp.
You rarely see it: when you publish OrderPlaced(...), listeners of
OrderPlaced receive the object itself. The context creates the
envelope, typed with the static type of the published object. Listen to
PayloadApplicationEvent<T> only when you also want the source (the
context that published it) and the timestamp. An @EventListener
method (or ApplicationListener) of PayloadApplicationEvent<T>
matches on the payload's runtime type, as in Spring; a listener added
with addListener matches on the envelope's type argument.
context.addListener<OrderPlaced>((order) => log.info(order.id));
context.publishEvent(OrderPlaced(1, 20)); // wrapped automatically
// Listeners of the wrapper see the source too:
context.addListener<PayloadApplicationEvent<OrderPlaced>>(
(event) => log.info('${event.payload} from ${event.source}'),
);
@EventListener()
void on(PayloadApplicationEvent<OrderPlaced> event) { ... }
Spring (Java):
context.publishEvent(new OrderPlaced(1, 20));
@EventListener
void on(PayloadApplicationEvent<OrderPlaced> event) { ... }
- Inheritance
-
- Object
- ApplicationEvent
- PayloadApplicationEvent
Constructors
- PayloadApplicationEvent(Object source, T payload, {DateTime? timestamp})
-
Wraps
payload, published bysource;timestampdefaults to the current time. The context does this for you.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- payload → T
-
The object that was published.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- source → Object
-
The object that raised the event, usually the publishing bean (or
the context, for the context's own events).
finalinherited
- timestamp → DateTime
-
When the event was created (not when a listener receives it).
finalinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited