JFinal-event 3.0.0 发布,插件启动速度提升十倍

栏目: 软件资讯 · 发布时间: 5年前

内容简介:前言 JFinal-event 是参考 Spring 中 Event 的使用方式而生,为 JFinal 用户带来更多方便。其核心目标是深层次解耦,为您节约更多时间,去陪恋人、家人和朋友 :) 距 gitee issues #IR96V 6个月,终于把【3.0优化】...

前言

JFinal-event 是参考 SpringEvent 的使用方式而生,为 JFinal 用户带来更多方便。其核心目标是深层次解耦,为您节约更多时间,去陪恋人、家人和朋友 :)

距 gitee issues #IR96V 6个月,终于把【3.0优化】有生之年闲下来了弄吧的第二点优化进行了完善,鼓掌!!!

更新记录

2019-07-19 v3.0.0

  • 升级到jfinal 4.3。

  • 完成【3.0优化 有生之年闲下来了弄吧】#IR96V 之2 将类扫描,改到编译期。

  • 删除 ClassUtil,但愿大伙没用这个类。

更新说明

此次更新主要是采用 Annotation Processor 技术,将运行期的事件类扫描改到了编译期,

加快服务的启动时间,减少各种容器差异导致的类扫描问题。

使用

maven

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

gradle >= 5.x

api("net.dreamlu:JFinal-event:3.0.0")
annotationProcessor("net.dreamlu:JFinal-event:3.0.0")

gradle < 5.x

compile("net.dreamlu:JFinal-event:3.0.0")

注意

  1. 3.0.0 由于使用了 Annotation Processor 技术,Idea 需要开启注解处理器。

  2. 对于手动导入 jar(非 maven、gradle)依赖管理的,您需要手动注入事件类或者在 classes 目录下新建 META-INF/dream.events 文件,格式如下:

net.dreamlu.event.test.Test1Listener
net.dreamlu.event.test.Test2Listener

启动插件(v3.0.0 去掉了类扫描更加简单)

// 初始化插件
EventPlugin plugin = new EventPlugin();
// 设置为异步,默认同步,或者使用`threadPool(ExecutorService executorService)`自定义线程池。
plugin.async();
​
// 手动启动插件,用于main方法启动,jfinal中不需要,添加插件即可。
plugin.start();
​
// 停止插件,用于main方法测试,jfinal中不需要,添加插件即可。
plugin.stop();

新建事件类

public class AccountEvent {
​
    private Integer id;
    private String name;
    private Integer age;
​
    // 省略 get set
}

编写监听方法

public class Test1Listener {
​
    @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的属性或者方法。

回顾

或许这是最后的一个版本了,由于精力问题,笔者已经停止更新其他的几个 JFinal 插件,下面随我一起回顾下 JFinal-event 的这4年多。

  1. 2015-04-27 22:19:33 初始化项目 网名(孤独的√3)

  2. 2015-05-06 23:40:53 v0.1 版本发布推送到 maven 中央库

  3. 2015-06-25 21:01:13 v0.3 支持异步,去掉了 guava 包,因为只用了一个 Multimap 集合。

  4. 2015-07-04 17:43:23 v0.4.2 添加事件排序

  5. 2016-08-19 10:46:58 v1.4.0 添加事件 tag

  6. 2017-04-22 00:10:41 v1.5.1 添加了基于 rmi 的远程 Event(2.x弃用)

  7. 2017-10-10 11:23:34 v2.0.0 基于注解和方法的兼听,不再需要单独编写 Listener 类。

  8. 2018-03-02 17:05:33 v2.1.0 添加CtrlHolderEvent处理同步、异步中request、session、header等参数传递。网名(如梦技术)

  9. 2018-10-09 21:37:18 v2.2.2 升级到 jfinal 3.5 支持JFinal新版本的 bean inject。

  10. 2019-04-08 20:55:52 v2.3.0 支持普通类作为 event 事件源,不再需要继承 ApplicationEvent

感谢码云提供了这么好的一个平台作为码云提供了这么一个优秀的平台,也感谢 JFinal 从 JFinal 中学习到了不少极简设计。

最后

笔者近2年将更多的精力放到的我的新开源——Spring Cloud 微服务开发核心包 mica:https://gitee.com/596392912/mica 欢迎 star ,各种骚操作等你来发现。


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Text Processing in Python

Text Processing in Python

David Mertz / Addison-Wesley Professional / 2003-6-12 / USD 54.99

Text Processing in Python describes techniques for manipulation of text using the Python programming language. At the broadest level, text processing is simply taking textual information and doing som......一起来看看 《Text Processing in Python》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

在线进制转换器
在线进制转换器

各进制数互转换器

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具