DefaultLifecycleProcessor class
The LifecycleProcessor every context uses unless it declares its own: it starts the lifecycle beans phase by phase, lowest first, and stops them in the reverse order.
Applications meet it only to change the shutdown timeouts, by declaring
a lifecycleProcessor bean. Plain Lifecycle beans have phase 0.
Beans in the same phase start in registration order and stop in the
reverse order; a bean's dependencies (injected or dependsOn) start
before it and its dependents stop before it, whatever their phase. Like
Spring's getLifecycleBeans, only singletons are considered, and of
the plain Lifecycle beans only those already created: a lazy plain
Lifecycle bean is not created to be started or stopped
(SmartLifecycle beans are). At refresh a plain Lifecycle bean is
started only as the dependency of an auto-startup bean.
On closeAsync() the processor waits, per phase, for the callbacks
of SmartLifecycle.stopWithCallback at most timeoutPerShutdownPhase
(or the phase's entry in timeoutsForShutdownPhases), logs the beans
still running and goes on with the next phase, like Spring. The
synchronous stop() / close() do not wait (Spring's block); a bean
asked to start while its stop callback is still pending (restart(),
or start() right after stop()) is started when the callback fires
instead of being skipped as running.
Like Spring 7, pause() stops the running beans except the
SmartLifecycle beans that are not SmartLifecycle.isPauseable (plain
Lifecycle beans are stopped too) and restart() stops the pauseable
beans if still running, then starts the auto-startup beans again, which
restores the state after refresh.
// Outside a context: drive the lifecycle beans of a bean factory.
final processor = DefaultLifecycleProcessor(context.beanFactory)
..start(); // starts every Lifecycle bean, auto-startup or not
processor.stop();
Spring (Java):
var processor = new DefaultLifecycleProcessor();
processor.setBeanFactory(beanFactory);
processor.start();
- Implemented types
Constructors
-
DefaultLifecycleProcessor(ConfigurableListableBeanFactory beanFactory, {Duration timeoutPerShutdownPhase = const Duration(seconds: 10), Map<
int, Duration> timeoutsForShutdownPhases = const {}}) -
Creates a processor for the lifecycle singletons of
beanFactory.timeoutPerShutdownPhasedefaults to 10 seconds;timeoutsForShutdownPhasesoverrides it for single phases.
Properties
- beanFactory → ConfigurableListableBeanFactory
-
The factory whose lifecycle beans are started and stopped.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isRunning → bool
-
Whether the background work is running; the context asks before
starting or stopping the bean.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- timeoutPerShutdownPhase ↔ Duration
-
How long
closeAsync()andpauseAsync()wait for the stop callbacks of one phase before they log the beans still running and go on; 10 seconds by default (Spring'stimeoutPerShutdownPhase).getter/setter pair -
timeoutsForShutdownPhases
→ Map<
int, Duration> -
Timeouts for single phases, by phase, overriding
timeoutPerShutdownPhase; for example a longer one for the phase of
a server that drains its requests (Spring's
timeoutsForShutdownPhases).final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onClose(
) → void -
Stops the running beans; called by the context's
close()and by a failed refresh. Does not wait for SmartLifecycle.stopWithCallback callbacks that come later.override -
onCloseAsync(
) → Future< void> -
Stops the running beans, waiting for the callbacks of
SmartLifecycle.stopWithCallback phase by phase; called by the
context's
closeAsync().override -
onPause(
) → void -
Stops the running beans except the SmartLifecycle beans that are
not SmartLifecycle.isPauseable; called by the context's
pause()(Spring 7'sonPause()). Does not wait for SmartLifecycle.stopWithCallback callbacks that come later.override -
onPauseAsync(
) → Future< void> -
Like onPause, but waits for the callbacks of
SmartLifecycle.stopWithCallback phase by phase; called by the
context's
pauseAsync().override -
onRefresh(
) → void -
Starts the auto-startup SmartLifecycle beans; called at the end of
the context's refresh.
override
-
onRestart(
) → void -
Stops the pauseable beans if they are still running, then starts the
auto-startup beans again; called by the context's
restart()(Spring 7'sonRestart()).override -
start(
) → void -
Starts every Lifecycle bean that is not running, auto-startup or
not; called by an explicit
context.start().override -
stop(
) → void -
Stops every running Lifecycle bean, highest phase first, without
waiting for stop callbacks; called by
context.stop().override -
timeoutForShutdownPhase(
int phase) → Duration -
The timeout for the shutdown of
phase: its entry in timeoutsForShutdownPhases, else timeoutPerShutdownPhase (Spring'sdetermineTimeout). -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited