public class DefaultLifecycleProcessor extends Object implements LifecycleProcessor, BeanFactoryAware
LifecycleProcessor
strategy.Constructor and Description |
---|
DefaultLifecycleProcessor() |
Modifier and Type | Method and Description |
---|---|
protected Map<String,Lifecycle> |
getLifecycleBeans()
Retrieve all applicable Lifecycle beans: all singletons that have already been created,
as well as all SmartLifecycle beans (even if they are marked as lazy-init).
|
protected int |
getPhase(Lifecycle bean)
Determine the lifecycle phase of the given bean.
|
boolean |
isRunning()
Check whether this component is currently running.
|
void |
onClose()
Notification of context close phase, e.g.
|
void |
onRefresh()
Notification of context refresh, e.g.
|
void |
setBeanFactory(BeanFactory beanFactory)
Callback that supplies the owning factory to a bean instance.
|
void |
setTimeoutPerShutdownPhase(long timeoutPerShutdownPhase)
Specify the maximum time allotted in milliseconds for the shutdown of
any phase (group of SmartLifecycle beans with the same 'phase' value).
|
void |
start()
Start all registered beans that implement
Lifecycle and are not
already running. |
void |
stop()
Stop all registered beans that implement
Lifecycle and are
currently running. |
public void setTimeoutPerShutdownPhase(long timeoutPerShutdownPhase)
The default value is 30 seconds.
public void setBeanFactory(BeanFactory beanFactory)
BeanFactoryAware
Invoked after the population of normal bean properties
but before an initialization callback such as
InitializingBean.afterPropertiesSet()
or a custom init-method.
setBeanFactory
in interface BeanFactoryAware
beanFactory
- owning BeanFactory (never null
).
The bean can immediately call methods on the factory.BeanInitializationException
public void start()
Lifecycle
and are not
already running. Any bean that implements SmartLifecycle
will be
started within its 'phase', and all phases will be ordered from lowest to
highest value. All beans that do not implement SmartLifecycle
will be
started in the default phase 0. A bean declared as a dependency of another bean
will be started before the dependent bean regardless of the declared phase.start
in interface Lifecycle
SmartLifecycle.isAutoStartup()
public void stop()
Lifecycle
and are
currently running. Any bean that implements SmartLifecycle
will be
stopped within its 'phase', and all phases will be ordered from highest to
lowest value. All beans that do not implement SmartLifecycle
will be
stopped in the default phase 0. A bean declared as dependent on another bean
will be stopped before the dependency bean regardless of the declared phase.stop
in interface Lifecycle
SmartLifecycle.stop(Runnable)
,
DisposableBean.destroy()
public void onRefresh()
LifecycleProcessor
onRefresh
in interface LifecycleProcessor
public void onClose()
LifecycleProcessor
onClose
in interface LifecycleProcessor
public boolean isRunning()
Lifecycle
In the case of a container, this will return true
only if all
components that apply are currently running.
protected Map<String,Lifecycle> getLifecycleBeans()
protected int getPhase(Lifecycle bean)
The default implementation checks for the Phased
interface, using
a default of 0 otherwise. Can be overridden to apply other/further policies.
bean
- the bean to introspectPhased.getPhase()
,
SmartLifecycle