Class SmartLifecycleRoleController
java.lang.Object
org.springframework.integration.support.SmartLifecycleRoleController
- All Implemented Interfaces:
EventListener
,Aware
,ApplicationContextAware
,ApplicationListener<AbstractLeaderEvent>
public class SmartLifecycleRoleController
extends Object
implements ApplicationListener<AbstractLeaderEvent>, ApplicationContextAware
Bulk start/stop
SmartLifecycle
in a particular role in phase order.- Since:
- 4.2
- Author:
- Gary Russell, Artem Bilan, Christian Tzolov, Ngoc Nhan
-
Constructor Summary
ConstructorDescriptionConstruct an instance without any lifecycle initially: can be added later on viaaddLifecycleToRole(String, SmartLifecycle)
.SmartLifecycleRoleController
(List<String> roles, List<SmartLifecycle> lifecycles) Construct an instance with the provided lists of roles and lifecycles, which must be of equal length.SmartLifecycleRoleController
(MultiValueMap<String, SmartLifecycle> lifecycles) Construct an instance with the provided map of roles/instances. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addLifecyclesToRole
(String role, List<String> lifecycleBeanNames) Add aSmartLifecycle
beans to the role using their names.final void
addLifecycleToRole
(String role, String lifecycleBeanName) Add aSmartLifecycle
bean to the role using its name.final void
addLifecycleToRole
(String role, SmartLifecycle lifecycle) Add aSmartLifecycle
to the role.boolean
allEndpointsRunning
(String role) Return true if all endpoints in the role are running.Return the running status of each endpoint in the role.getRoles()
Return a collection of the roles currently managed by this controller.boolean
noEndpointsRunning
(String role) Return true if none of the endpoints in the role are running or if there are no endpoints in the role.void
boolean
removeLifecycle
(SmartLifecycle lifecycle) Remove the provided SmartLifecycle from all the roles, for example when a SmartLifecycle bean is destroyed.void
setApplicationContext
(ApplicationContext applicationContext) void
startLifecyclesInRole
(String role) Start all registeredSmartLifecycle
s in the role.void
stopLifecyclesInRole
(String role) Stop all registeredSmartLifecycle
s in the role.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecution
-
Constructor Details
-
SmartLifecycleRoleController
public SmartLifecycleRoleController()Construct an instance without any lifecycle initially: can be added later on viaaddLifecycleToRole(String, SmartLifecycle)
.- Since:
- 5.5
-
SmartLifecycleRoleController
Construct an instance with the provided lists of roles and lifecycles, which must be of equal length.- Parameters:
roles
- the roles.lifecycles
- the lifecycles corresponding to the roles.
-
SmartLifecycleRoleController
Construct an instance with the provided map of roles/instances.- Parameters:
lifecycles
- theMultiValueMap
of beans in roles.
-
-
Method Details
-
setApplicationContext
- Specified by:
setApplicationContext
in interfaceApplicationContextAware
- Throws:
BeansException
-
addLifecycleToRole
Add aSmartLifecycle
to the role.- Parameters:
role
- the role.lifecycle
- theSmartLifecycle
.
-
addLifecycleToRole
Add aSmartLifecycle
bean to the role using its name.- Parameters:
role
- the role.lifecycleBeanName
- the bean name of theSmartLifecycle
.
-
addLifecyclesToRole
Add aSmartLifecycle
beans to the role using their names.- Parameters:
role
- the role.lifecycleBeanNames
- the bean names of theSmartLifecycle
s.
-
startLifecyclesInRole
Start all registeredSmartLifecycle
s in the role.- Parameters:
role
- the role.
-
stopLifecyclesInRole
Stop all registeredSmartLifecycle
s in the role.- Parameters:
role
- the role.
-
getRoles
Return a collection of the roles currently managed by this controller.- Returns:
- the roles.
- Since:
- 4.3.8
-
allEndpointsRunning
Return true if all endpoints in the role are running.- Parameters:
role
- the role.- Returns:
- true if at least one endpoint in the role, and all are running.
- Since:
- 4.3.8
-
noEndpointsRunning
Return true if none of the endpoints in the role are running or if there are no endpoints in the role.- Parameters:
role
- the role.- Returns:
- true if there are no endpoints or none are running.
- Since:
- 4.3.8
-
getEndpointsRunningStatus
Return the running status of each endpoint in the role.- Parameters:
role
- the role.- Returns:
- A map of component names : running status
- Since:
- 4.3.8
-
onApplicationEvent
- Specified by:
onApplicationEvent
in interfaceApplicationListener<AbstractLeaderEvent>
-
removeLifecycle
Remove the provided SmartLifecycle from all the roles, for example when a SmartLifecycle bean is destroyed. The role entry in the lifecycles map is cleared as well if its value list is empty after SmartLifecycle removal.- Parameters:
lifecycle
- the SmartLifecycle to remove.- Returns:
- the removal status
- Since:
- 5.0
-