org.apache.catalina.Lifecycle 接口统一管理生命周期,所有生命周期组件都要实现Lifecycle接口。
该接口定义了13个String类型的常量,用于LifecycleEvent时间的type属性,作用是区分组件发出的LifecycleEvent事件时的状态,
这种设计方式可以让多中状态都发送同一种类型的时间,然后用其中的一个属性来区分状态,而不用定义多种事件。
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 }
本人(徐自勉)原创内容,转载请注明出处,作者.