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
  • Constructor Details

    • SmartLifecycleRoleController

      public SmartLifecycleRoleController()
      Construct an instance without any lifecycle initially: can be added later on via addLifecycleToRole(String, SmartLifecycle).
      Since:
      5.5
    • SmartLifecycleRoleController

      public SmartLifecycleRoleController(List<String> roles, List<SmartLifecycle> lifecycles)
      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

      public SmartLifecycleRoleController(MultiValueMap<String,SmartLifecycle> lifecycles)
      Construct an instance with the provided map of roles/instances.
      Parameters:
      lifecycles - the MultiValueMap of beans in roles.
  • Method Details

    • setApplicationContext

      public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
      Specified by:
      setApplicationContext in interface ApplicationContextAware
      Throws:
      BeansException
    • addLifecycleToRole

      public final void addLifecycleToRole(String role, SmartLifecycle lifecycle)
      Add a SmartLifecycle to the role.
      Parameters:
      role - the role.
      lifecycle - the SmartLifecycle.
    • addLifecycleToRole

      public final void addLifecycleToRole(String role, String lifecycleBeanName)
      Add a SmartLifecycle bean to the role using its name.
      Parameters:
      role - the role.
      lifecycleBeanName - the bean name of the SmartLifecycle.
    • addLifecyclesToRole

      public void addLifecyclesToRole(String role, List<String> lifecycleBeanNames)
      Add a SmartLifecycle beans to the role using their names.
      Parameters:
      role - the role.
      lifecycleBeanNames - the bean names of the SmartLifecycles.
    • startLifecyclesInRole

      public void startLifecyclesInRole(String role)
      Start all registered SmartLifecycles in the role.
      Parameters:
      role - the role.
    • stopLifecyclesInRole

      public void stopLifecyclesInRole(String role)
      Stop all registered SmartLifecycles in the role.
      Parameters:
      role - the role.
    • getRoles

      public Collection<String> getRoles()
      Return a collection of the roles currently managed by this controller.
      Returns:
      the roles.
      Since:
      4.3.8
    • allEndpointsRunning

      public boolean allEndpointsRunning(String role)
      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

      public 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.
      Parameters:
      role - the role.
      Returns:
      true if there are no endpoints or none are running.
      Since:
      4.3.8
    • getEndpointsRunningStatus

      public Map<String,Boolean> getEndpointsRunningStatus(String role)
      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

      public void onApplicationEvent(AbstractLeaderEvent event)
      Specified by:
      onApplicationEvent in interface ApplicationListener<AbstractLeaderEvent>
    • removeLifecycle

      public boolean removeLifecycle(SmartLifecycle lifecycle)
      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