E
- the specific ApplicationEvent
subclass to listen topublic 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.
TransactionalApplicationListener
,
TransactionalEventListener
,
TransactionalApplicationListenerMethodAdapter
TransactionalApplicationListener.SynchronizationCallback
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
TransactionalApplicationListenerAdapter(ApplicationListener<E> targetListener)
Construct a new TransactionalApplicationListenerAdapter.
|
Modifier and Type | Method and Description |
---|---|
void |
addCallback(TransactionalApplicationListener.SynchronizationCallback callback)
Add a callback to be invoked on processing within transaction synchronization,
i.e.
|
String |
getListenerId()
Return an id to identify the listener with.
|
int |
getOrder()
Return the synchronization order for the listener.
|
TransactionPhase |
getTransactionPhase()
Return the transaction phase to invoke the listener in.
|
void |
onApplicationEvent(E event)
Handle an application event.
|
void |
processEvent(E event)
Immediately process the given
ApplicationEvent . |
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forPayload, forPayload
public TransactionalApplicationListenerAdapter(ApplicationListener<E> targetListener)
targetListener
- the actual listener to invoke in the specified transaction phasesetTransactionPhase(org.springframework.transaction.event.TransactionPhase)
,
TransactionalApplicationListener.forPayload(java.util.function.Consumer<T>)
public void setOrder(int order)
public int getOrder()
getOrder
in interface Ordered
getOrder
in interface TransactionalApplicationListener<E extends ApplicationEvent>
TransactionSynchronization.getOrder()
public void setTransactionPhase(TransactionPhase transactionPhase)
The default is TransactionPhase.AFTER_COMMIT
.
public TransactionPhase getTransactionPhase()
getTransactionPhase
in interface TransactionalApplicationListener<E extends ApplicationEvent>
public void setListenerId(String listenerId)
The default is an empty String.
public String getListenerId()
public void addCallback(TransactionalApplicationListener.SynchronizationCallback callback)
TransactionalApplicationListener
TransactionalApplicationListener.processEvent(E)
is being triggered during actual transactions.addCallback
in interface TransactionalApplicationListener<E extends ApplicationEvent>
callback
- the synchronization callback to applypublic void processEvent(E event)
TransactionalApplicationListener
ApplicationEvent
. In contrast to
ApplicationListener.onApplicationEvent(ApplicationEvent)
, a call to this method will
directly process the given event without deferring it to the associated
transaction phase
.processEvent
in interface TransactionalApplicationListener<E extends ApplicationEvent>
event
- the event to process through the target listener implementationpublic void onApplicationEvent(E event)
ApplicationListener
onApplicationEvent
in interface ApplicationListener<E extends ApplicationEvent>
event
- the event to respond to