1 /* JFox, the OpenSource J2EE Application Server2 *3 * Distributable under GNU LGPL license by gun.org4 * more details please visit http://www.huihoo.org/jfox5 */6 7 package org.jfox.ioc.ext;8 9 import org.jfox.ioc.Component;10 11 /**12 * 可初始化和销毁的组件。13 * 在生成组件实例的时候,容器会调用init方法对组件实例进行初始化。14 * 在Registry停止的时候,会调用destroy方法对组件的资源进行销毁。15 *16 *17 * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>18 */19 20 public interface InitializableComponent extends Component {21 22 /**23 * 生成组件实例的时候,对组件实例进行初始化,24 * 比如:设置一些默认属性,或者建立数据库连接。对于数据库连接这种不能被垃圾回收器回收的资源,25 * 要记住在 {@link #destroy()}中释放26 *27 * @throws Exception28 */29 public void init() throws Exception ;30 31 /**32 * 实现该方法以销毁不能被垃圾回收器回收的资源。33 * <br>34 * 如果一个Component使用了外部的资源(比如:socket 链接),而不能被垃圾回收器回收,35 * 那么应该实现该接口,并实现 destroy 方法36 * <br>37 * 在停止 Registry 时,系统会调用该方法,如果需要在此之前释放资源,需要手动的调用该方法。38 * <br><br>39 * 注意:不要使用已经 destroyed 的 component40 * @throws Exception41 */42 public void destroy() throws Exception ;43 44 }45