org.apache.catalina.Lifecycle 接口統一管理生命週期,全部生命週期組件都要實現Lifecycle接口。apache
該接口定義了13個String類型的常量,用於LifecycleEvent時間的type屬性,做用是區分組件發出的LifecycleEvent事件時的狀態,spa
這種設計方式可讓多中狀態都發送同一種類型的時間,而後用其中的一個屬性來區分狀態,而不用定義多種事件。設計
1 public interface Lifecycle { 2 3 public static final String BEFORE_INIT_EVENT = "before_init"; 4 public static final String AFTER_INIT_EVENT = "after_init"; 5 public static final String START_EVENT = "start"; 6 public static final String BEFORE_START_EVENT = "before_start"; 7 public static final String AFTER_START_EVENT = "after_start"; 8 public static final String STOP_EVENT = "stop"; 9 public static final String BEFORE_STOP_EVENT = "before_stop"; 10 public static final String AFTER_STOP_EVENT = "after_stop"; 11 public static final String AFTER_DESTROY_EVENT = "after_destroy"; 12 public static final String BEFORE_DESTROY_EVENT = "before_destroy"; 13 public static final String PERIODIC_EVENT = "periodic"; 14 public static final String CONFIGURE_START_EVENT = "configure_start"; 15 public static final String CONFIGURE_STOP_EVENT = "configure_stop"; 16 17 public void addLifecycleListener(LifecycleListener listener); 18 19 public LifecycleListener[] findLifecycleListeners(); 20 21 22 public void removeLifecycleListener(LifecycleListener listener); 23 24 25 public void init() throws LifecycleException; 26 27 28 public void start() throws LifecycleException; 29 30 31 public void stop() throws LifecycleException; 32 33 public void destroy() throws LifecycleException; 34 35 public LifecycleState getState(); 36 37 public String getStateName(); 38 39 public interface SingleUse { 40 } 41 }