代码拉取完成,页面将自动刷新
同步操作将从 如梦技术/JFinal-event 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
模仿的Spring中的消息事件:详解Spring事件驱动模型
专为JFinal设计,无任何第三方依赖,小巧玲珑。
JFinal-event
插件,老版本
使用请查看文档 wiki
// 初始化插件
EventPlugin plugin = new EventPlugin();
// 设置为异步,默认同步,或者使用`threadPool(ExecutorService executorService)`自定义线程池。
plugin.async();
// 设置扫描jar包,默认不扫描
plugin.scanJar();
// 设置监听器默认包,默认全扫描
plugin.scanPackage("net.dreamlu");
// 手动启动插件,用于main方法启动,jfinal中不需要,添加插件即可。
plugin.start();
// 停止插件,用于main方法测试
plugin.stop();
// 继承 ApplicationEvent
public class Test1Event extends ApplicationEvent {
private static final long serialVersionUID = 6994987952247306131L;
public Test1Event(Object source) {
super(source);
}
}
@EventListener
public void listenTest1Event(Test1Event event) {
System.out.println("Test1Event:" + event.getSource());
}
EventKit.post(new Test1Event("hello1"));
@EventListener(events = Test1Event.class, order = 1, async = true, condition = "event.isExec()")
events
支持的事件类型数组,用于将事件方法定义为ApplicationEvent
或者自定义父类。
@EventListener(events = Test1Event.class)
public void applicationEvent(ApplicationEvent event) {
String xx = (String) event.getSource();
System.out.println(Thread.currentThread().getName() + "\tsource:" + xx);
}
order
排序,数值越小越先执行,默认为Integer.MAX_VALUE
async
异步执行,需要插件开启async()
或者自定义线程池。
condition
表达式条件,使用event.xxxx,event.isExec() == true
判定event的属性或者方法。
jar包下载 http://maven.aliyun.com/nexus/#nexus-search;quick~jfinal-event
以上版本均已上传到maven仓库~
<dependency>
<groupId>net.dreamlu</groupId>
<artifactId>JFinal-event</artifactId>
<version>2.0.0</version>
</dependency>
欢迎拍砖~~~
2017-10-10 v2.0.0
基于注解和方法的兼听,简化使用,不兼容1.x
2017-04-20 v1.5.1
基于rmi的远程Event
2017-03-22 v1.4.2
- 更改默认线程池为SingleThreadExecutor,使异步执行有序化。
- 添加EventThreadFactory,处理异步时的异常避免影响服务请求。 建议:如果event需要发送大量的异步事件,建议使用自定义线程池。
eventPlugin.threadPool(Executors.newCachedThreadPool(new EventThreadFactory()));
2017-02-15 v1.4.1
- 添加自定义线程池EventPlugin.threadPool(ExecutorService executorService)方法
2016-08-19 v1.4.0
- 升级到JFinal2.2,JFinal低版本用户请使用
v1.2.0
。EventKit.postEvent(event)
更改为EventKit.post(event)
,postEvent
不再建议使用。- 添加
EventKit.post(tag, event)
方法,@Listener(order = 2, tag = "save")
添加tag
。
2015-12-30 v1.3.0
- 升级到JFinal2.1,JFinal低版本用户请使用
v1.2.0
2015-08-20 v1.2.0
- 解决部署时中文路径或者是空格找不到监听器
2015-07-05 v1.0
- 调优,减少不必要的实例
2015-07-04 v0.4.2
- 编译改为JDK1.6
- 新增监听器执行顺序@Listener(order = 1) 越小越优先执行,Default is Integer.MAX_VALUE
- 新增单个监听器的,同步或者异步开关@Listener(enableAsync = true)
如梦技术:237587118
( The MIT License )
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。