Interface LifecycleRegistry

All Known Implementing Classes:
DefaultAxonApplication, HierarchicalConfiguration, SpringLifecycleRegistry

public interface LifecycleRegistry
Interface describing the configuration of start and shutdown handlers within Axon's configuration.

Allows for configuration of Runnables, suppliers of CompletableFutures, consumers of the AxonConfiguration, and LifecycleHandlers. The invocation order is defined through the (optional) phase parameter. The Phase enumeration may be used as a guidance to add operations before/after Axon's regular steps when stating the phase for the various registration methods.

Since:
4.6.0
Author:
Steven van Beelen
See Also:
  • Method Details

    • registerLifecyclePhaseTimeout

      LifecycleRegistry registerLifecyclePhaseTimeout(long timeout, @Nonnull TimeUnit timeUnit)
      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.

      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

      default LifecycleRegistry onStart(@Nonnull Runnable startHandler)
      Registers a startHandler to be executed in the default phase 0 when the configuration this registry belongs to is started.

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

      Parameters:
      startHandler - The handler to execute when the AxonConfiguration is started.
      Returns:
      The current instance of the LifecycleRegistry for a fluent API.
      See Also:
    • onStart

      default LifecycleRegistry onStart(int phase, @Nonnull Runnable startHandler)
      Registers a 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.

      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 execute when the AxonConfiguration is started.
      Returns:
      The current instance of the LifecycleRegistry for a fluent API.
      See Also:
    • onStart

      default LifecycleRegistry onStart(int phase, @Nonnull Supplier<CompletableFuture<?>> startHandler)
      Registers a 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.

      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 execute when the AxonConfiguration is started.
      Returns:
      The current instance of the LifecycleRegistry for a fluent API.
      See Also:
    • onStart

      default LifecycleRegistry onStart(int phase, @Nonnull Consumer<Configuration> startHandler)
      Registers a 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.

      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 execute when the AxonConfiguration is started.
      Returns:
      The current instance of the LifecycleRegistry for a fluent API.
      See Also:
    • onStart

      LifecycleRegistry onStart(int phase, @Nonnull LifecycleHandler startHandler)
      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.

      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

      default LifecycleRegistry onShutdown(@Nonnull Runnable shutdownHandler)
      Registers a shutdownHandler to be executed in the default phase 0 when the configuration this registry belongs to is shut down.

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

      Parameters:
      shutdownHandler - The handler to execute when the AxonConfiguration is shut down.
      Returns:
      The current instance of the LifecycleRegistry for a fluent API.
      See Also:
    • onShutdown

      default LifecycleRegistry onShutdown(int phase, @Nonnull Runnable shutdownHandler)
      Registers a shutdownHandler to be executed in the given phase when the configuration this registry belongs to is shut down.

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

      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 execute when the AxonConfiguration is shut down.
      Returns:
      The current instance of the LifecycleRegistry for a fluent API.
      See Also:
    • onShutdown

      default LifecycleRegistry onShutdown(int phase, @Nonnull Supplier<CompletableFuture<?>> shutdownHandler)
      Registers a 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.

      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 execute when the AxonConfiguration is shut down.
      Returns:
      The current instance of the LifecycleRegistry for a fluent API.
      See Also:
    • onShutdown

      default LifecycleRegistry onShutdown(int phase, @Nonnull Consumer<Configuration> shutdownHandler)
      Registers a 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.

      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 execute when the AxonConfiguration is shut down.
      Returns:
      The current instance of the LifecycleRegistry for a fluent API.
      See Also:
    • onShutdown

      LifecycleRegistry onShutdown(int phase, @Nonnull LifecycleHandler shutdownHandler)
      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.

      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: