Reference to
blog.csdn.net/5iasp/article/details/37054171
First, the scenario hypothesis
Suppose you have a blog system that needs to implement the following features:
Users in the system to publish articles, modify articles, delete articles, need some relevant action needs to be executed.
Post articles, to send friends email notification, add points to the user, the article to do full-text indexing.
After modifying the article, send a message to friends to modify the notification, add points to the user, the article re-full-text index.
After deleting the article, send a message to friends to modify the notification, to reduce points to the user, the article re-full-text index.
Second, the related concept analysis
Analysis, such as the above scenario, can be implemented using event distribution and listening mechanisms.
There are several concepts for event distribution and monitoring:
Event Source: The object that triggered the event, as in the previous scenario we used the entity object as the event source, and the published article is the event source.
Events: Events generated for event source operations, such as posting article modification articles, deleting articles that trigger related articles being published, articles being deleted, articles being modified events
Event Listener: An abstraction that triggers the execution behavior of various events on the event source, including interfaces and several implementation classes.
For example, an interface needs to define an interface for an operation that needs to be implemented when event source related events are triggered.
Event Dispatcher: Event dispatcher primarily handles distribution of events and management of event listeners, registering and deleting event listeners, and so on.
Analysis:
Java event listeners and dispatcher