为JFinal添加event消息事件

在之前使用spring mvc的时候,在复杂的下单和支付中有一部分功能使用的Spring事件驱动模型去完成!具体优点不啰嗦了,发现涛哥有篇文章讲得比较详细:详解Spring事件驱动模型

最初准备基于Guava 的Eventbus去实现,发现其并不太适合!以下来自官方的wiki

Why must I create my own Event Bus, rather than using a singleton?
EventBus doesn’t specify how you use it; there’s nothing stopping your application from having separate EventBus instances for each component, or using separate instances to separate events by context or topic. This also makes it trivial to set up and tear down EventBus objects in your tests.

Of course, if you’d like to have a process-wide EventBus singleton, there’s nothing stopping you from doing it that way. Simply have your container (such as Guice) create the EventBus as a singleton at global scope (or stash it in a static field, if you’re into that sort of thing).

In short, EventBus is not a singleton because we’d rather not make that decision for you. Use it how you like.

JFinal-event实现得比较简单,整个代码结构如图:
为JFinal添加event消息事件

其核心原理是,使用guava Multimap转载所有的监听器和监听器监听的泛型ApplicationEvent的子类!

源码地址:

http://git.oschina.net/596392912/JFinal-event

欢迎拍砖~.~

参考代码:

https://github.com/google/guava/tree/master/guava/src/com/google/common/eventbus

https://github.com/spring-projects/spring-framework/blob/master/spring-context/src/main/java/org/springframework/context/event


发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注