public final class LifecycleManager extends AbstractLifecycle
Lifecycle instance that manages the startup and shutdown of a collection of sub-Lifecycles.
Registered Lifecycles are started when this LifecycleManager is started and shutdown when this
LifecycleManager is shutdown.
The order that sub-Lifecycles are shutdown can be controlled with the optional LifecycleManager.ShutdownOrder parameter
provided in LifecycleManager(ShutdownOrder).
| Modifier and Type | Class and Description |
|---|---|
static class |
LifecycleManager.ShutdownOrder
Modes that control the order in which registered
Lifecycles are shutdown. |
| Constructor and Description |
|---|
LifecycleManager()
Create a
LifecycleManager that shuts down sub-Lifecycles in LifecycleManager.ShutdownOrder.LINEAR order. |
LifecycleManager(LifecycleManager.ShutdownOrder shutdownOrder)
Create a
LifecycleManager that shuts down sub-Lifecycles in the specified LifecycleManager.ShutdownOrder. |
| Modifier and Type | Method and Description |
|---|---|
void |
addLifecycle(Lifecycle lifecycle)
Add a
Lifecycle to be managed. |
Lifecycle |
addShutdownTask(Runnable shutdownTask)
Add logic to run at shutdown.
|
Lifecycle |
addStartupTask(Runnable startupTask)
Add logic to run at startup.
|
protected void |
onShutdown()
Execute shutdown logic, if there is any.
|
protected void |
onStartup()
Execute startup logic, if there is any.
|
void |
removeLifecycle(Lifecycle lifecycle)
Remove a previously added
Lifecycle. |
isNotRunning, isRunning, shutdown, startuppublic LifecycleManager()
LifecycleManager that shuts down sub-Lifecycles in LifecycleManager.ShutdownOrder.LINEAR order.public LifecycleManager(LifecycleManager.ShutdownOrder shutdownOrder)
LifecycleManager that shuts down sub-Lifecycles in the specified LifecycleManager.ShutdownOrder.shutdownOrder - the LifecycleManager.ShutdownOrder to shutdown sub-Lifecycles in.protected void onStartup()
AbstractLifecycleonStartup in class AbstractLifecycleprotected void onShutdown()
AbstractLifecycleonShutdown in class AbstractLifecyclepublic void addLifecycle(Lifecycle lifecycle)
Lifecycle to be managed.
This Lifecycle will have Lifecycle.startup() called when this manager is started and
Lifecycle.shutdown() called when this manager is shutdown.
lifecycle - the Lifecycle to add.public void removeLifecycle(Lifecycle lifecycle)
Lifecycle.lifecycle - the Lifecycle to remove.public Lifecycle addStartupTask(Runnable startupTask)
This is a convenience method for addLifecycle(Lifecycle) where Lifecycle.shutdown() is implied
to be a no-op.
startupTask - logic to run at startup.Lifecycle instance that can be used with removeLifecycle(Lifecycle) if needed.public Lifecycle addShutdownTask(Runnable shutdownTask)
This is a convenience method for addLifecycle(Lifecycle) where Lifecycle.startup() is implied
to be a no-op.
shutdownTask - logic to run at shutdown.Lifecycle instance that can be used with removeLifecycle(Lifecycle) if needed.Copyright © 2021. All rights reserved.