Class SpringLifecycleRegistry

java.lang.Object
org.axonframework.extension.spring.config.SpringLifecycleRegistry
All Implemented Interfaces:
LifecycleRegistry, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware

@Internal public class SpringLifecycleRegistry extends Object implements org.springframework.beans.factory.BeanFactoryAware, LifecycleRegistry
A LifecycleRegistry implementation that registers all lifecycle handlers as Spring SmartLifecycle beans to ensure Spring weaves these lifecycles into the other Spring bean lifecycles.

By being a BeanFactory implementation, this LifecycleRegistry is capable of registering the aforementioned SmartLifecycle beans based on the LifecycleHandlers provided through onStart(int, LifecycleHandler) and onShutdown(int, LifecycleHandler).

Since:
5.0.0
Author:
Allard Buijze
  • Constructor Details

    • SpringLifecycleRegistry

      public SpringLifecycleRegistry()
  • Method Details

    • setBeanFactory

      public void setBeanFactory(@Nonnull org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException
      Specified by:
      setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
      Throws:
      org.springframework.beans.BeansException
    • registerLifecyclePhaseTimeout

      public LifecycleRegistry registerLifecyclePhaseTimeout(long timeout, @Nonnull TimeUnit timeUnit)
      Description copied from interface: LifecycleRegistry
      Configures the timeout of each lifecycle phase. The LifecycleRegistry invokes lifecycle phases during start-up and shutdown of an application.

      Note that if a lifecycle phase exceeds the configured timeout and timeUnit combination, the LifecycleRegistry will proceed with the following phase. A phase-skip is marked with a warn logging message, as the chances are high this causes undesired side effects.

      The default lifecycle phase timeout is five seconds.

      Specified by:
      registerLifecyclePhaseTimeout in interface LifecycleRegistry
      Parameters:
      timeout - The amount of time to wait for lifecycle phase completion.
      timeUnit - The unit in which the timeout is expressed.
      Returns:
      The current instance of the LifecycleRegistry, for chaining purposes.
      See Also:
    • onStart

      public LifecycleRegistry onStart(int phase, @Nonnull LifecycleHandler startHandler)
      Description copied from interface: LifecycleRegistry
      Registers an asynchronous startHandler to be executed in the given phase when the configuration this registry belongs to is started.

      Handlers cannot be registered when the configuration has already been created from this registry.

      Specified by:
      onStart in interface LifecycleRegistry
      Parameters:
      phase - Defines a phase in which the start handler will be invoked during AxonConfiguration.start(). When starting the configuration the given handlers are started in ascending order based on their phase.
      startHandler - The handler to be executed asynchronously when the AxonConfiguration is started.
      Returns:
      The current instance of the LifecycleRegistry for a fluent API.
      See Also:
    • onShutdown

      public LifecycleRegistry onShutdown(int phase, @Nonnull LifecycleHandler shutdownHandler)
      Description copied from interface: LifecycleRegistry
      Registers an asynchronous shutdownHandler to be executed in the given phase when the configuration this registry belongs to is shut down.

      The behavior for handlers that are registered when the configuration is already shut down is undefined.

      Specified by:
      onShutdown in interface LifecycleRegistry
      Parameters:
      phase - Defines a phase in which the shutdown handler will be invoked during AxonConfiguration.shutdown(). When shutting down the configuration the given handlers are executing in descending order based on their phase.
      shutdownHandler - The handler to be executed asynchronously when the AxonConfiguration is shut down.
      Returns:
      The current instance of the LifecycleRegistry for a fluent API.
      See Also: