Class TransactionalApplicationListenerAdapter<E extends ApplicationEvent>
java.lang.Object
org.springframework.transaction.event.TransactionalApplicationListenerAdapter<E>
- Type Parameters:
E
- the specificApplicationEvent
subclass to listen to
- All Implemented Interfaces:
EventListener
,ApplicationListener<E>
,Ordered
,TransactionalApplicationListener<E>
public class TransactionalApplicationListenerAdapter<E extends ApplicationEvent>
extends Object
implements TransactionalApplicationListener<E>, Ordered
TransactionalApplicationListener
adapter that delegates the processing of
an event to a target ApplicationListener
instance. Supports the exact
same features as any regular ApplicationListener
but is aware of the
transactional context of the event publisher.
For simple PayloadApplicationEvent
handling,
consider the TransactionalApplicationListener.forPayload(java.util.function.Consumer<T>)
factory methods
as a convenient alternative to custom usage of this adapter class.
- Since:
- 5.3
- Author:
- Juergen Hoeller
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.transaction.event.TransactionalApplicationListener
TransactionalApplicationListener.SynchronizationCallback
-
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
ConstructorDescriptionTransactionalApplicationListenerAdapter
(ApplicationListener<E> targetListener) Construct a new TransactionalApplicationListenerAdapter. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a callback to be invoked on processing within transaction synchronization, i.e.Return an id to identify the listener with.int
getOrder()
Return the synchronization order for the listener.Return the transaction phase to invoke the listener in.void
onApplicationEvent
(E event) Handle an application event.void
processEvent
(E event) Immediately process the givenApplicationEvent
.void
setListenerId
(String listenerId) Specify an id to identify the listener with.void
setOrder
(int order) Specify the synchronization order for the listener.void
setTransactionPhase
(TransactionPhase transactionPhase) Specify the transaction phase to invoke the listener in.
-
Constructor Details
-
TransactionalApplicationListenerAdapter
Construct a new TransactionalApplicationListenerAdapter.- Parameters:
targetListener
- the actual listener to invoke in the specified transaction phase- See Also:
-
-
Method Details
-
setOrder
public void setOrder(int order) Specify the synchronization order for the listener. -
getOrder
public int getOrder()Return the synchronization order for the listener.- Specified by:
getOrder
in interfaceOrdered
- Specified by:
getOrder
in interfaceTransactionalApplicationListener<E extends ApplicationEvent>
- Returns:
- the order value
- See Also:
-
setTransactionPhase
Specify the transaction phase to invoke the listener in.The default is
TransactionPhase.AFTER_COMMIT
. -
getTransactionPhase
Return the transaction phase to invoke the listener in.- Specified by:
getTransactionPhase
in interfaceTransactionalApplicationListener<E extends ApplicationEvent>
-
setListenerId
Specify an id to identify the listener with.The default is an empty String.
-
getListenerId
Return an id to identify the listener with.- Specified by:
getListenerId
in interfaceTransactionalApplicationListener<E extends ApplicationEvent>
- See Also:
-
addCallback
Description copied from interface:TransactionalApplicationListener
Add a callback to be invoked on processing within transaction synchronization, i.e. whenTransactionalApplicationListener.processEvent(E)
is being triggered during actual transactions.- Specified by:
addCallback
in interfaceTransactionalApplicationListener<E extends ApplicationEvent>
- Parameters:
callback
- the synchronization callback to apply
-
processEvent
Description copied from interface:TransactionalApplicationListener
Immediately process the givenApplicationEvent
. In contrast toApplicationListener.onApplicationEvent(ApplicationEvent)
, a call to this method will directly process the given event without deferring it to the associatedtransaction phase
.- Specified by:
processEvent
in interfaceTransactionalApplicationListener<E extends ApplicationEvent>
- Parameters:
event
- the event to process through the target listener implementation
-
onApplicationEvent
Description copied from interface:ApplicationListener
Handle an application event.- Specified by:
onApplicationEvent
in interfaceApplicationListener<E extends ApplicationEvent>
- Parameters:
event
- the event to respond to
-