Java event listeners and dispatcher

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.