public class DefaultLifecycleProcessor extends java.lang.Object implements LifecycleProcessor, BeanFactoryAware
LifecycleProcessor strategy.| Modifier and Type | Class and Description |
|---|---|
private class |
DefaultLifecycleProcessor.LifecycleGroup
Helper class for maintaining a group of Lifecycle beans that should be started
and stopped together based on their 'phase' value (or the default value of 0).
|
private class |
DefaultLifecycleProcessor.LifecycleGroupMember
Adapts the Comparable interface onto the lifecycle phase model.
|
| Modifier and Type | Field and Description |
|---|---|
private ConfigurableListableBeanFactory |
beanFactory |
private Log |
logger |
private boolean |
running |
private long |
timeoutPerShutdownPhase |
| Constructor and Description |
|---|
DefaultLifecycleProcessor() |
| Modifier and Type | Method and Description |
|---|---|
private void |
doStart(java.util.Map<java.lang.String,? extends Lifecycle> lifecycleBeans,
java.lang.String beanName,
boolean autoStartupOnly)
Start the specified bean as part of the given set of Lifecycle beans,
making sure that any beans that it depends on are started first.
|
private void |
doStop(java.util.Map<java.lang.String,? extends Lifecycle> lifecycleBeans,
java.lang.String beanName,
java.util.concurrent.CountDownLatch latch,
java.util.Set<java.lang.String> countDownBeanNames)
Stop the specified bean as part of the given set of Lifecycle beans,
making sure that any beans that depends on it are stopped first.
|
protected java.util.Map<java.lang.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.
|
private void |
startBeans(boolean autoStartupOnly) |
void |
stop()
Stop all registered beans that implement Lifecycle and are
currently running.
|
private void |
stopBeans() |
private final Log logger
private volatile long timeoutPerShutdownPhase
private volatile boolean running
private volatile ConfigurableListableBeanFactory beanFactory
public void setTimeoutPerShutdownPhase(long timeoutPerShutdownPhase)
public void setBeanFactory(BeanFactory beanFactory)
BeanFactoryAwareInvoked after the population of normal bean properties
but before an initialization callback such as
InitializingBean.afterPropertiesSet() or a custom init-method.
setBeanFactory in interface BeanFactoryAwarebeanFactory - owning BeanFactory (never null).
The bean can immediately call methods on the factory.BeanInitializationExceptionpublic void start()
start in interface LifecycleSmartLifecycle.isAutoStartup()public void stop()
stop in interface LifecycleSmartLifecycle.stop(Runnable),
DisposableBean.destroy()public void onRefresh()
LifecycleProcessoronRefresh in interface LifecycleProcessorpublic void onClose()
LifecycleProcessoronClose in interface LifecycleProcessorpublic boolean isRunning()
LifecycleIn the case of a container, this will return true only if all
components that apply are currently running.
private void startBeans(boolean autoStartupOnly)
private void doStart(java.util.Map<java.lang.String,? extends Lifecycle> lifecycleBeans, java.lang.String beanName, boolean autoStartupOnly)
lifecycleBeans - Map with bean name as key and Lifecycle instance as valuebeanName - the name of the bean to startprivate void stopBeans()
private void doStop(java.util.Map<java.lang.String,? extends Lifecycle> lifecycleBeans, java.lang.String beanName, java.util.concurrent.CountDownLatch latch, java.util.Set<java.lang.String> countDownBeanNames)
lifecycleBeans - Map with bean name as key and Lifecycle instance as valuebeanName - the name of the bean to stopprotected java.util.Map<java.lang.String,Lifecycle> getLifecycleBeans()
protected int getPhase(Lifecycle bean)
The default implementation checks for the Phased interface.
Can be overridden to apply other/further policies.
bean - the bean to introspectPhased,
SmartLifecycle