Package org.springframework.transaction.event

# Class TransactionalApplicationListenerAdapter<E extends org.springframework.context.ApplicationEvent>

java.lang.Object
org.springframework.transaction.event.TransactionalApplicationListenerAdapter<E>

Type Parameters:
  `E` - the specific `ApplicationEvent` subclass to listen to

All Implemented Interfaces:
  `EventListener`, `org.springframework.context.ApplicationListener<E>`, `org.springframework.core.Ordered`, `TransactionalApplicationListener<E>`

public class TransactionalApplicationListenerAdapter<E extends org.springframework.context.ApplicationEvent> extends Object implements TransactionalApplicationListener<E>, org.springframework.core.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:
  - `TransactionalApplicationListener`
  - `TransactionalEventListener`
  - `TransactionalApplicationListenerMethodAdapter`

## 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

Constructors
Constructor
Description
`TransactionalApplicationListenerAdapter(org.springframework.context.ApplicationListener<E> targetListener)`
Construct a new TransactionalApplicationListenerAdapter.

## Method Summary

Modifier and Type
Method
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)`
`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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.springframework.transaction.event.TransactionalApplicationListener

`supportsAsyncExecution`

## Constructor Details

### TransactionalApplicationListenerAdapter

public TransactionalApplicationListenerAdapter(org.springframework.context.ApplicationListener<E> targetListener)
Construct a new TransactionalApplicationListenerAdapter.

Parameters:
  `targetListener` - the actual listener to invoke in the specified transaction phase
See Also:
  - `setTransactionPhase(org.springframework.transaction.event.TransactionPhase)`
  - `TransactionalApplicationListener.forPayload(java.util.function.Consumer<T>)`

## 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 interface `org.springframework.core.Ordered`
Specified by:
  `getOrder` in interface `TransactionalApplicationListener<E extends org.springframework.context.ApplicationEvent>`
See Also:
  - `TransactionSynchronization.getOrder()`

### setTransactionPhase

public void setTransactionPhase(TransactionPhase transactionPhase)
Specify the transaction phase to invoke the listener in.

The default is `TransactionPhase.AFTER_COMMIT`.

### getTransactionPhase

public TransactionPhase getTransactionPhase()
Return the transaction phase to invoke the listener in.

Specified by:
  `getTransactionPhase` in interface `TransactionalApplicationListener<E extends org.springframework.context.ApplicationEvent>`

### setListenerId

public void setListenerId(String listenerId)
Specify an id to identify the listener with.

The default is an empty String.

### getListenerId

public String getListenerId()
Return an id to identify the listener with.

Specified by:
  `getListenerId` in interface `TransactionalApplicationListener<E extends org.springframework.context.ApplicationEvent>`
See Also:
  - `SmartApplicationListener.getListenerId()`
  - `TransactionalEventListener.id()`
  - `TransactionalApplicationListener.addCallback(org.springframework.transaction.event.TransactionalApplicationListener.SynchronizationCallback)`

### addCallback

public void addCallback(TransactionalApplicationListener.SynchronizationCallback callback)
Description copied from interface: `TransactionalApplicationListener`
Add a callback to be invoked on processing within transaction synchronization, i.e. when `TransactionalApplicationListener.processEvent(E)` is being triggered during actual transactions.

Specified by:
  `addCallback` in interface `TransactionalApplicationListener<E extends org.springframework.context.ApplicationEvent>`
Parameters:
  `callback` - the synchronization callback to apply

### processEvent

public void processEvent(E event)
Description copied from interface: `TransactionalApplicationListener`
Immediately process the given `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`.

Specified by:
  `processEvent` in interface `TransactionalApplicationListener<E extends org.springframework.context.ApplicationEvent>`
Parameters:
  `event` - the event to process through the target listener implementation

### onApplicationEvent

public void onApplicationEvent(E event)

Specified by:
  `onApplicationEvent` in interface `org.springframework.context.ApplicationListener<E extends org.springframework.context.ApplicationEvent>`