I. Overview of the event monitoring mechanism
Second, the event monitoring mechanism structure
Third, spring Monitoring mechanism architecture
Spring's application has the ability to publish events and register event listeners with a complete set of event publishing and monitoring mechanisms. In Java, through Java.util. EventObject to describe the event through Java.util. EventListener to describe event listeners, in many frameworks and components, the creation of a set of event mechanisms is usually based on these two interfaces to extend.
In an event system, there are several important concepts.
1. Event Source: The creator of the event object, any one eventobject has a source
2. Event Listener registry: When an event frame or component receives an event, it needs to notify all relevant event listeners to handle it, and at this point a storage listener is required, that is, the event listener registry.
3. Event broadcaster: Event broadcaster plays an intermediary role throughout the event mechanism, and when an event Publisher publishes an event, it is necessary to notify all relevant listeners of the event to be processed by the broadcaster.
Is the structure diagram of the event mechanism to Download
650) this.width=650; "height=" 525 "width=" src= "http://dl2.iteye.com/upload/attachment/0119/7761/" 709446ae-70da-30ed-a7bd-05b2a23241f2.jpg "title=" Click to view the original size picture "class=" Magplus "style=" border:0px; "/>
Spring Event Publishing mechanism
In spring, the event mechanism is probably the same structure, and the specific implementation takes the Observer pattern. Let's take a look at spring's event mechanism design class diagram Download
650) this.width=650; "height=" 433 "width=" src= "http://dl2.iteye.com/upload/attachment/0119/7759/" F44a881b-218e-37c4-be47-0a1c891f95d6.jpg "title=" Click to view the original size picture "class=" Magplus "style=" border:0px; "/>
1. Applicationeventpublisher is the event publishing interface of spring, and event sources publish events through the Pulishevent method of the interface.
2, Applicationeventmulticaster is the event broadcaster in the spring event mechanism, it provides a simpleapplicationeventmulticaster implementation by default, if the user does not have a custom broadcaster, The default is used. It gets the event listener in the registry through the Getapplicationlisteners method of the parent class Abstractapplicationeventmulticaster, and implement the specific logic of the listener through the Invokelistener method
3, Applicationlistener is the Spring event listener interface, all listeners implement the interface, this figure lists a few typical subclasses. Where Restartapplicationlistnener is used to download in Springboot's startup framework
4, in spring, applicationcontext itself is usually the role of the Listener registry, Event broadcaster Applicationeventmulticaster and event listener Applicationlistnener are aggregated in their subclass Abstractapplicationcontext, and provide a Addapplicationlistnener method for registering listeners.
It is clear to know that when an event source generates an event, it publishes events through the event publisher Applicationeventpublisher, Then event broadcaster Applicationeventmulticaster will go to the event registry ApplicationContext to find the event listener Applicationlistnener, and execute the listener's Onapplicationevent method one by one to complete the logic of the event listener.
Spring Architecture revelation-event monitoring mechanism