当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 134

Leon_wy / JFinal-event
暂停

forked from 如梦技术 / JFinal-event 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载

A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.

Permissions
  • Commercial use
  • Modification
  • Distribution
  • Private use
Limitations
  • Liability
  • Warranty
Conditions
  • License and copyright notice
README.md 3.55 KB
一键复制 编辑 原始数据 按行查看 历史
如梦技术 提交于 2019-04-08 20:55 . v2.3.0

模仿的Spring中的消息事件:详解Spring事件驱动模型

专为JFinal设计,无任何第三方依赖,小巧玲珑。

更新记录

:laughing: JFinal-event 插件,老版本使用请查看文档 wiki

初始化插件

// 初始化插件
EventPlugin plugin = new EventPlugin();
// 设置为异步,默认同步,或者使用`threadPool(ExecutorService executorService)`自定义线程池。
plugin.async();

// 设置扫描jar包,默认不扫描
plugin.scanJar();
// 设置监听器默认包,多个包名使用;分割,默认全扫描
plugin.scanPackage("net.dreamlu");
// bean工厂,默认为DefaultBeanFactory,可实现IBeanFactory自定义扩展
// 对于将@EventListener写在不含无参构造器的类需要使用`ObjenesisBeanFactory`(2.3.0 已经不推荐使用)
plugin.beanFactory(new ObjenesisBeanFactory());

// 手动启动插件,用于main方法启动,jfinal中不需要,添加插件即可。
plugin.start();

// 停止插件,用于main方法测试
plugin.stop();

新建事件类(任意模型即可 2.3.0支持)

public class AccountEvent {

	private Integer id;
	private String name;
	private Integer age;

	// 省略 get set

}

编写监听

@EventListener
public void listenTest1Event(AccountEvent event) {
    System.out.println("AccountEvent:" + event);
}

发送事件

AccountEvent event = new AccountEvent();
event.setId(1);
event.setName("张三");
event.setAge(18);

EventKit.post(event);

@EventListener注解说明

示例

@EventListener(events = Test1Event.class, order = 1, async = true, condition = "event.isExec()")

说明

valueevents支持的事件类型数组,用于将事件方法定义为ApplicationEvent或者自定义父类。

public class Test {

    @EventListener({Test1Event.class, Test2Event.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的属性或者方法。

使用的场景优势

请参考详解Spring事件驱动模型

jar包下载 http://central.maven.org/maven2/net/dreamlu/JFinal-event/

以上版本均已上传到maven仓库~

<dependency>
    <groupId>net.dreamlu</groupId>
    <artifactId>JFinal-event</artifactId>
    <version>2.3.0</version>
</dependency>

欢迎拍砖~~~

License

( The MIT License )

开源推荐

微信公众号

如梦技术

精彩内容每日推荐!!

Java
1
https://gitee.com/hadoop/JFinal-event.git
git@gitee.com:hadoop/JFinal-event.git
hadoop
JFinal-event
JFinal-event
master

搜索帮助