ApplicationRunListeners class final

Coordinates the execution of multiple ApplicationRunListener instances during the JetLeaf application lifecycle.

This class serves as the central event dispatcher for JetLeaf’s bootstrap process, invoking each registered listener in sequence as the application progresses through its various lifecycle stages (e.g., startup, environment preparation, context initialization, readiness, and failure).

The ApplicationRunListeners implementation ensures that all listeners execute safely and that failures in one listener do not prevent others from being notified. It also integrates with ApplicationStartup to record structured startup metrics for performance analysis and debugging.

Example

final listeners = ApplicationRunListeners(
  [MyStartupListener(), MyTelemetryListener()],
  DefaultApplicationStartup(),
);

listeners.onStarting(context, Class<MyApp>(MyApp));
listeners.onEnvironmentPrepared(context, environment);
listeners.onStarted(context, Duration(milliseconds: 850));

Key Responsibilities

  • Dispatches lifecycle events to registered ApplicationRunListeners.
  • Records structured startup telemetry through ApplicationStartup.
  • Gracefully handles listener exceptions during startup and shutdown.
  • Provides internal error logging via JetLeaf’s LogFactory.

JetLeaf developers typically do not instantiate this class directly. Instead, the framework constructs it automatically during application boot.

Implemented types

Constructors

ApplicationRunListeners(List<ApplicationRunListener> _listeners, ApplicationStartup _startup)
Coordinates the execution of multiple ApplicationRunListener instances during the JetLeaf application lifecycle.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onContextLoaded(ConfigurableApplicationContext context) FutureOr<void>
Called when the application context has loaded all configurations.
override
onContextPrepared(ConfigurableApplicationContext context) FutureOr<void>
Called after the application context has been created but not yet loaded.
override
onEnvironmentPrepared(ConfigurableBootstrapContext context, ConfigurableEnvironment environment) FutureOr<void>
Called once the application environment has been prepared.
override
onFailed(ConfigurableApplicationContext? context, Object exception) FutureOr<void>
Called if the application fails to start.
override
onReady(ConfigurableApplicationContext context, Duration timeTaken) FutureOr<void>
Called when the application is fully ready to service requests.
override
onStarted(ConfigurableApplicationContext context, Duration timeTaken) FutureOr<void>
Called after the application context has been refreshed and started.
override
onStarting(ConfigurableBootstrapContext context, Class<Object> mainClass) FutureOr<void>
Called immediately when the application starts.
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited