Guava EventBus

Understanding Guava's EventBus starts with Shiro's EventBus, just wondering what's the difference between the two and why Shiro has to re-implement his own set of EventBus. With such a problem, I took a look at Guava's EventBus. Generally speaking, it is easy to implement, and the important thing is the idea. It is handled by EventBus, Subscriber, SubscriberRegistry, Dispatcher, these large Objects. 

 

EventBus: The bus for events.

Subscriber: Find methods marked with @Subscribe on the method by reflection to form a Subscriber ( Subscriber. create ( bus , listener, method ) ).

SubscriberRegistry: 处理Subscriber. 如:void register(Object listener), void unregister(Object listener) 

Dispatcher: Implements different Dispatch strategy patterns. Such as:  LegacyAsyncDispatcher, ImmediateDispatcher, PerThreadQueuedDispatcher, and  finally call the dispatchEvent(Object event) method of Subscriber.java, that is, the reflection method .invoke( target , checkNotNull (event));

 

The activity flow chart is as follows:

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326211077&siteId=291194637