org.springframework.transaction.event

## Class TransactionalApplicationListenerAdapter<E extends ApplicationEvent>

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

- Type Parameters:
    `E` - the specific `ApplicationEvent` 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:
    `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 and Description
    `TransactionalApplicationListenerAdapter(ApplicationListener<E> targetListener)` Construct a new TransactionalApplicationListenerAdapter.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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.

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

      `forPayload, forPayload`

- - ### Constructor Detail

    - #### TransactionalApplicationListenerAdapter

          public TransactionalApplicationListenerAdapter(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 Detail

    - #### 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 `Ordered`
      Specified by:
        `getOrder` in interface `TransactionalApplicationListener<E extends ApplicationEvent>`
      Returns:
        the order value
      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 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 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 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 ApplicationEvent>`
      Parameters:
        `event` - the event to process through the target listener implementation

    - #### onApplicationEvent

          public void onApplicationEvent(E event)

      Description copied from interface: `ApplicationListener`
      Handle an application event.
      Specified by:
        `onApplicationEvent` in interface `ApplicationListener<E extends ApplicationEvent>`
      Parameters:
        `event` - the event to respond to