Class TransactionalApplicationListenerAdapter<E extends ApplicationEvent>
java.lang.Object
org.springframework.transaction.event.TransactionalApplicationListenerAdapter<E>
- Type Parameters:
E- the specificApplicationEventsubclass 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
ConstructorsConstructorDescriptionTransactionalApplicationListenerAdapter(ApplicationListener<E> targetListener) Construct a new TransactionalApplicationListenerAdapter. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a callback to be invoked on processing within transaction synchronization, i.e.Return an id to identify the listener with.intgetOrder()Return the synchronization order for the listener.Return the transaction phase to invoke the listener in.voidonApplicationEvent(E event) Handle an application event.voidprocessEvent(E event) Immediately process the givenApplicationEvent.voidsetListenerId(String listenerId) Specify an id to identify the listener with.voidsetOrder(int order) Specify the synchronization order for the listener.voidsetTransactionPhase(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:
getOrderin interfaceOrdered- Specified by:
getOrderin 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:
getTransactionPhasein 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:
getListenerIdin interfaceTransactionalApplicationListener<E extends ApplicationEvent>- See Also:
-
addCallback
Description copied from interface:TransactionalApplicationListenerAdd a callback to be invoked on processing within transaction synchronization, i.e. whenTransactionalApplicationListener.processEvent(E)is being triggered during actual transactions.- Specified by:
addCallbackin interfaceTransactionalApplicationListener<E extends ApplicationEvent>- Parameters:
callback- the synchronization callback to apply
-
processEvent
Description copied from interface:TransactionalApplicationListenerImmediately 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:
processEventin interfaceTransactionalApplicationListener<E extends ApplicationEvent>- Parameters:
event- the event to process through the target listener implementation
-
onApplicationEvent
Description copied from interface:ApplicationListenerHandle an application event.- Specified by:
onApplicationEventin interfaceApplicationListener<E extends ApplicationEvent>- Parameters:
event- the event to respond to
-