Class AbstractSmartLifecycle
java.lang.Object
io.microsphere.spring.context.lifecycle.AbstractSmartLifecycle
- All Implemented Interfaces:
org.springframework.context.Lifecycle
,org.springframework.context.Phased
,org.springframework.context.SmartLifecycle
- Direct Known Subclasses:
LoggingSmartLifecycle
public abstract class AbstractSmartLifecycle
extends Object
implements org.springframework.context.SmartLifecycle
Abstract base class for implementing
SmartLifecycle
strategies.
This class provides a skeletal implementation of the SmartLifecycle
interface,
making it easier to create custom lifecycle beans with specific startup and shutdown logic.
Key Features
- Centralizes common lifecycle state management.
- Offers phase-based control for startup and shutdown order.
- Ensures consistent lifecycle behavior across implementations.
Example Usage
public class MyCustomLifecycle extends AbstractSmartLifecycle {
private boolean running = false;
@Override
protected void doStart() {
// Initialize resources
running = true;
}
@Override
protected void doStop() {
// Release resources
running = false;
}
@Override
public boolean isRunning() {
return running;
}
}
This class is designed to be extended, requiring subclasses to implement the
abstract methods doStart()
and doStop()
to define custom behavior.
- Since:
- 1.0.0
- Author:
- Mercy
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Compatible withSmartLifecycle.DEFAULT_PHASE
before Spring Framework 5.1static final int
The earliest phasestatic final int
The latest phase -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
EARLIEST_PHASE
public static final int EARLIEST_PHASEThe earliest phase- See Also:
-
LATEST_PHASE
public static final int LATEST_PHASEThe latest phase- See Also:
-
DEFAULT_PHASE
public static final int DEFAULT_PHASECompatible withSmartLifecycle.DEFAULT_PHASE
before Spring Framework 5.1- See Also:
-
SmartLifecycle.DEFAULT_PHASE
- Constant Field Values
-
-
Constructor Details
-
AbstractSmartLifecycle
public AbstractSmartLifecycle()
-
-
Method Details
-
start
public final void start()- Specified by:
start
in interfaceorg.springframework.context.Lifecycle
-
doStart
protected abstract void doStart() -
stop
public final void stop()- Specified by:
stop
in interfaceorg.springframework.context.Lifecycle
-
doStop
protected abstract void doStop() -
isRunning
public final boolean isRunning()- Specified by:
isRunning
in interfaceorg.springframework.context.Lifecycle
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartup
in interfaceorg.springframework.context.SmartLifecycle
-
stop
- Specified by:
stop
in interfaceorg.springframework.context.SmartLifecycle
-
getPhase
public final int getPhase()- Specified by:
getPhase
in interfaceorg.springframework.context.Phased
- Specified by:
getPhase
in interfaceorg.springframework.context.SmartLifecycle
-
isStarted
public boolean isStarted() -
setPhase
public final void setPhase(int phase) -
setStarted
protected void setStarted(boolean started)
-