15. sharding-jdbc源码之EventBus-轻量级进程内事件分发组件

阿飞Javaer,转载请注明原创出处,谢谢!

EventBus来自于google-guava包中。源码注释如下:

Dispatches events to listeners, and provides ways for listeners to register themselves.
The EventBus allows publish-subscribe-style communication between components 
without requiring the components to explicitly register with one another (and thus be 
aware of each other).  It is designed exclusively to replace traditional Java in-process 
event distribution using explicit registration. It is not a general-purpose publish-subscribe
system, nor is it intended for interprocess communication.

翻译:将事件分派给监听器,并为监听器提供注册自己的方法。EventBus允许组件之间的发布 - 订阅式通信,而不需要组件彼此明确注册(并且因此彼此意识到)。 它专门用于使用显式注册替换传统的Java进程内事件分发。 它不是一个通用的发布 - 订阅系统,也不是用于进程间通信。

使用参考

关于EventBus的用例代码提取自sharding-jdbc源码,并结合lombok最大限度的简化:
- EventBusInstance–用于获取EventBus实例(饿汉式单例模式)

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class EventBusInstance {
   

    private static final EventBus INSTANCE = new EventBus();

    public static EventBus getInstance() {
        return INS
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值