Class SmartLifecycleRoleController

java.lang.Object
org.springframework.integration.support.SmartLifecycleRoleController
All Implemented Interfaces:
java.util.EventListener, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener<AbstractLeaderEvent>

public class SmartLifecycleRoleController
extends java.lang.Object
implements org.springframework.context.ApplicationListener<AbstractLeaderEvent>, org.springframework.context.ApplicationContextAware
Bulk start/stop SmartLifecycle in a particular role in phase order.
Since:
4.2
  • Constructor Summary

    Constructors 
    Constructor Description
    SmartLifecycleRoleController​(java.util.List<java.lang.String> roles, java.util.List<org.springframework.context.SmartLifecycle> lifecycles)
    Construct an instance with the provided lists of roles and lifecycles, which must be of equal length.
    SmartLifecycleRoleController​(org.springframework.util.MultiValueMap<java.lang.String,​org.springframework.context.SmartLifecycle> lifecycles)
    Construct an instance with the provided map of roles/instances.
  • Method Summary

    Modifier and Type Method Description
    void addLifecyclesToRole​(java.lang.String role, java.util.List<java.lang.String> lifecycleBeanNames)
    Add a SmartLifecycle beans to the role using their names.
    void addLifecycleToRole​(java.lang.String role, java.lang.String lifecycleBeanName)
    Add a SmartLifecycle bean to the role using its name.
    void addLifecycleToRole​(java.lang.String role, org.springframework.context.SmartLifecycle lifecycle)
    Add a SmartLifecycle to the role.
    boolean allEndpointsRunning​(java.lang.String role)
    Return true if all endpoints in the role are running.
    java.util.Map<java.lang.String,​java.lang.Boolean> getEndpointsRunningStatus​(java.lang.String role)
    Return the running status of each endpoint in the role.
    java.util.Collection<java.lang.String> getRoles()
    Return a collection of the roles currently managed by this controller.
    boolean noEndpointsRunning​(java.lang.String role)
    Return true if none of the endpoints in the role are running or if there are no endpoints in the role.
    void onApplicationEvent​(AbstractLeaderEvent event)  
    boolean removeLifecycle​(org.springframework.context.SmartLifecycle lifecycle)
    Remove the provided SmartLifecycle from all the roles, for example when a SmartLifecycle bean is destroyed.
    void setApplicationContext​(org.springframework.context.ApplicationContext applicationContext)  
    void startLifecyclesInRole​(java.lang.String role)
    Start all registered SmartLifecycles in the role.
    void stopLifecyclesInRole​(java.lang.String role)
    Stop all registered SmartLifecycles in the role.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SmartLifecycleRoleController

      public SmartLifecycleRoleController​(java.util.List<java.lang.String> roles, java.util.List<org.springframework.context.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​(org.springframework.util.MultiValueMap<java.lang.String,​org.springframework.context.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​(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Throws:
      org.springframework.beans.BeansException
    • addLifecycleToRole

      public final void addLifecycleToRole​(java.lang.String role, org.springframework.context.SmartLifecycle lifecycle)
      Add a SmartLifecycle to the role.
      Parameters:
      role - the role.
      lifecycle - the SmartLifecycle.
    • addLifecycleToRole

      public final void addLifecycleToRole​(java.lang.String role, java.lang.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​(java.lang.String role, java.util.List<java.lang.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​(java.lang.String role)
      Start all registered SmartLifecycles in the role.
      Parameters:
      role - the role.
    • stopLifecyclesInRole

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

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

      public boolean allEndpointsRunning​(java.lang.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​(java.lang.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 java.util.Map<java.lang.String,​java.lang.Boolean> getEndpointsRunningStatus​(java.lang.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 org.springframework.context.ApplicationListener<AbstractLeaderEvent>
    • removeLifecycle

      public boolean removeLifecycle​(org.springframework.context.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