为JFinal添加event消息事件

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

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

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.github

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).spring

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

JFinal-event实现得比较简单,整个代码结构如图: 代码结构app

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

源码地址:

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

欢迎拍砖~.~google

参考代码:

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

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

相关文章
相关标签/搜索