做网站代码的含义,wordpress删除顶部设置菜单,wordpress增加额外链接,网站评论源码串行的处理过程#xff08;含六个事件扩展点 两个函数扩展点#xff09;#xff0c;代码直接、没有什么模式。易明 提醒#xff1a;
启动过程完成后#xff0c;项目才能正常运行#xff08;启动过程中#xff0c;不能把线程卡死了#xff09;AppBeanLoadEndEvent 之前…串行的处理过程含六个事件扩展点 两个函数扩展点代码直接、没有什么模式。易明 提醒
启动过程完成后项目才能正常运行启动过程中不能把线程卡死了AppBeanLoadEndEvent 之前的事件需要启动前通过 EventBus.subscribe(...) 订阅
1、事件订阅示例
AppLoadEndEvent
Component
public class AppLoadEndEventListener implements EventListenerAppLoadEndEvent{Overridepublic void onEvent(AppLoadEndEvent event) throws Throwable {//event.app(); //获取应用对象}
}AppStopEndEventv2.1.0 后支持
Component
public class AppStopEndEventListener implements EventListenerAppStopEndEvent{Overridepublic void onEvent(AppStopEndEvent event) throws Throwable {//event.app(); //获取应用对象}
}2、插件在应用生命周期里的时机点
插件的本质即在应用生命周期中获得关键执行时机的接口。从而有效获得应用扩展能力。
插件接口 Plugin
FunctionalInterface
public interface Plugin {void start(AopContext context) throws Throwable;default void prestop() throws Throwable{}default void stop() throws Throwable{}
}执行时机
接口执行时机说明start在 7 时机点执行启动prestop在 ::stop 前执行预停止stop在 ::ShutdownHook 时执行停止启用安全停止时prestop 后等几秒再执行 stop
3、注解能力注册的合适时机点
比如时机点5
public class DemoApp{public void static main(String[] args){Solon.start(DemoApp.clas, args, app-{//比如注册Demo注解Solon.context().beanAroundAdd(DemoAop.class, new DemoInterceptor());});}
}比如时机点6借用 SolonBuilder提前注册事件
public class DemoApp{public void static main(String[] args){new SolonBuilder().onAppInitEnd(e - {//...时机点6}).onAppLoadEnd(e-{//...时间点e }).start(JobApp.class, args);}
}比如时机点7通过插件机制。如果是独立插件请另参考 《插件扩展机制》
定义一个插件
public class DemoPluginImp implements Plugin {Overridepublic void start(AopContext context) {//比如注册Demo注解context.beanAroundAdd(DemoAop.class, new DemoInterceptor());}
}//可通过[时机点5]注册插件
public class DemoApp{public void static main(String[] args){Solon.start(DemoApp.clas, args, app-{app.pluginAdd(0, new DemoPluginImp()); //此处注册的插件会在[时机点7]运行});}
}//或可通过 app.yml 的配置借用[时机点4]申明插件
//solon.plugin: xxx.xxx.DemoPluginImp