CN105094811B - A kind of method and apparatus of event handling - Google Patents

A kind of method and apparatus of event handling Download PDF

Info

Publication number
CN105094811B
CN105094811B CN201510369678.1A CN201510369678A CN105094811B CN 105094811 B CN105094811 B CN 105094811B CN 201510369678 A CN201510369678 A CN 201510369678A CN 105094811 B CN105094811 B CN 105094811B
Authority
CN
China
Prior art keywords
event
interface
factory
unit
information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201510369678.1A
Other languages
Chinese (zh)
Other versions
CN105094811A (en
Inventor
陈庆伟
鞠丹
胡海涛
李华冈
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Baidu Netcom Science and Technology Co Ltd
Original Assignee
Anyi Hengtong Beijing Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Anyi Hengtong Beijing Technology Co Ltd filed Critical Anyi Hengtong Beijing Technology Co Ltd
Priority to CN201510369678.1A priority Critical patent/CN105094811B/en
Publication of CN105094811A publication Critical patent/CN105094811A/en
Application granted granted Critical
Publication of CN105094811B publication Critical patent/CN105094811B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • User Interface Of Digital Computer (AREA)

Abstract

The present invention provides a kind of method and apparatus of event handling, wherein method includes: that the event interface of itself and the event information to be monitored are registered to event factory by event monitoring unit;The event factory saves the event interface of registration and the corresponding relationship of event information;Event dispatch unit enumerates event interface corresponding to the event of itself binding by the event factory, and the event interface by enumerating sends the event of itself binding.The present invention realizes simply, improves the event handling efficiency of Observer Pattern.

Description

A kind of method and apparatus of event handling
[technical field]
The present invention relates to computer application technology, in particular to a kind of method and apparatus of event handling.
[background technique]
Observer Pattern is one kind of software design pattern, and in such mode, observed person's management is all interdependent It actively gives notice to observer in its observer, and when observed person's state changes, this usually passes through calling Method that each observer provides is realized.This mode is widely used in event handling system, in event handling system, example If user interface can be used as an observer, business datum is observed person, and after user data changes, event is sent out Observer is given, observer responds the event and shows data variation in user interface.
The Observer Pattern of current main-stream is that the mode based on boost signal slot is realized, however boost signal slot is related to Interface call level very much, calling process is using the mode of value copy, therefore efficiency is relatively low.
[summary of the invention]
In view of this, the present invention provides a kind of method and apparatus of event handling, in order to improve Observer Pattern Event handling efficiency.
Specific technical solution is as follows:
The present invention provides a kind of methods of event handling, this method comprises:
The event interface of itself and the event information to be monitored are registered to event factory by event monitoring unit;
The event factory saves the event interface of registration and the corresponding relationship of event information;
Event dispatch unit enumerates event interface corresponding to the event of itself binding by the event factory, and leads to Cross the event that the event interface enumerated sends itself binding.
A preferred embodiment according to the present invention, the event monitoring unit is by the event interface of itself and the thing to be monitored Part information registering includes: to event factory
The addition event monitoring person AddEventListener that event factory described in the event monitoring cell call provides Method, using the event interface of the event monitoring unit itself and the event information to be monitored as the parameter of institute's call method; Alternatively,
AddEventListener method described in the event monitoring cell call, by the event monitoring unit itself Parameter of the event interface as institute's call method is believed wherein the event interface carries the event to be monitored by preset function Breath.
A preferred embodiment according to the present invention, this method further include:
The removal event monitoring person that event factory described in the event monitoring cell call provides RemoveEventListener method makees the event interface of the event monitoring unit itself and the event information to be monitored For the parameter of institute's call method, or using the event interface of the event monitoring unit itself as the parameter of institute's call method, Wherein the event interface carries the event information to be monitored by preset function;
The corresponding relationship of the event interface and event information is deleted by the event factory.
A preferred embodiment according to the present invention, the event dispatch unit enumerate itself by the event factory and tie up Event interface corresponding to fixed event includes:
The enumeration event listener EnumEventListener that the event dispatch unit calls the event factory to provide Method, using the event information of event dispatch unit binding as the parameter of institute's call method;
Obtain event interface corresponding to the event for the event dispatch unit binding that the event factory returns.
A preferred embodiment according to the present invention executes logical when the event of event dispatch unit binding is triggered Cross the step of event factory enumerates event interface corresponding to the event of itself binding.
The present invention also provides a kind of device of event handling, which includes:
Event monitoring unit, for the event interface of itself and the event information to be monitored to be registered to event factory;
Event factory, for saving the event interface of registration and the corresponding relationship of event information;
Event dispatch unit connects for enumerating event corresponding to the event of itself binding by the event factory Mouthful, and the event interface by enumerating sends the event of itself binding.
A preferred embodiment according to the present invention, the event monitoring unit, specifically for calling the event factory to mention Addition event monitoring person's AddEventListener method of confession by the event interface of the event monitoring unit itself and will supervise Parameter of the event information listened as institute's call method;Alternatively,
AddEventListener method described in the event monitoring cell call, by the event monitoring unit itself Parameter of the event interface as institute's call method is believed wherein the event interface carries the event to be monitored by preset function Breath.
A preferred embodiment according to the present invention, the event monitoring unit are also used to that the event factory is called to provide Removal event monitoring person's RemoveEventListener method, the event interface of the event monitoring unit itself and will want Parameter of the event information of monitoring as institute's call method, or using the event interface of the event monitoring unit itself as institute The parameter of call method, wherein the event interface carries the event information to be monitored by preset function;
The event factory, is also used to delete the corresponding relationship of the event interface and event information.
A preferred embodiment according to the present invention, the event factory include: that event factor interface and event factory realize Unit;
The event factor interface, for the event monitoring unit provide AddEventListener method and RemoveEventListener method;
The event factory realizes unit, for saving or the corresponding relationship of deletion event interface and event information.
A preferred embodiment according to the present invention, the event dispatch unit, specifically for calling the event factory to mention The enumeration event listener EnumEventListener method of confession, using the event dispatch unit binding event information as The parameter of institute's call method;Obtain event corresponding to the event for the event dispatch unit binding that the event factory returns Interface.
A preferred embodiment according to the present invention, the event factory include: that event factory realizes unit and event factory Enumerates interface;
Event factory enumerates interface, for providing EnumEventListener method to the event dispatch unit, And the event factory is returned to the event dispatch unit and realizes unit definite event interface;
The event factory realizes unit, for determining that event corresponding to the event of the event dispatch unit binding connects Mouthful.
A preferred embodiment according to the present invention, the event dispatch unit are held when the event that itself binds is triggered Row enumerates the operation of event interface corresponding to the event of itself binding by the event factory.
As can be seen from the above technical solutions, the mode provided through the invention, event monitoring unit are only needed itself Event interface and the event information to be monitored be registered to event factory, event dispatch unit only needs to enumerate by event factory Event interface corresponding to the event of itself binding out, it is unified that event monitoring unit and event dispatch unit are completed by event factory Docking, and between event monitoring unit and event dispatch unit without Multistage Interface call and value copy by way of come into The docking of part and interface is acted, realization is simpler, and treatment effeciency is improved.
[Detailed description of the invention]
Fig. 1 is the structure chart of event processing apparatus provided in an embodiment of the present invention;
Fig. 2 is event-handling method flow chart provided in an embodiment of the present invention;
Fig. 3 is the instance graph of a device provided in an embodiment of the present invention.
[specific embodiment]
To make the objectives, technical solutions, and advantages of the present invention clearer, right in the following with reference to the drawings and specific embodiments The present invention is described in detail.
Fig. 1 is the structure chart of event processing apparatus provided in an embodiment of the present invention, as shown in Figure 1, the apparatus may include: Event monitoring unit 00, event factory 10 and event dispatch unit 20, wherein event factory 10 may further include event work Factory's interface 11, event factory realize unit 12 and event factory enumerates interface 13.Below with reference to event-handling method shown in Fig. 2 The event-handling method realized by the event processing apparatus is described in detail in flow chart.
00 purpose of event monitoring unit be in order to monitor event, usual event monitoring unit 00 in exploitation just with it is specific Functional unit is bound, such as there is the event monitoring unit bound with user interface, is supervised with the event of storage unit binding Listen unit etc..There are corresponding event interfaces for each event monitoring unit, obtain event information by the event interface.The thing Part interface and the event information to be monitored similarly are that developer pre-sets.
As shown in the step 201 in Fig. 2, event monitoring unit 00 at the time of initialization, by the event interface of itself and The event information to be monitored is registered to event factory 10.
Specifically, the AddEventListener that event monitoring unit 00 can call event factor interface 11 to provide (adds Add event monitoring person) method, using the event interface of event monitoring unit 00 and the event information to be monitored as The parameter of AddEventListener method.
Another implementation can also be used, i.e. event monitoring unit 00 can call event factor interface 11 to provide AddEventListener method, using the event interface of event monitoring unit 00 as the ginseng of AddEventListener method Number, wherein carrying the event information to be monitored by preset function in event interface.This mode is actually in advance by thing Part interface is bundled with event information, such as event interface can be bundled with getEventname function in advance, should GetEventname function carries event information.
Wherein, event interface can be the interface class of event monitoring unit 00, and event information can be event monitoring unit Title, number, the mark etc. of 00 monitored event.
In shown in Fig. 2 202, event factory 10 saves the event interface of registration and the corresponding relationship of event information.
Specifically, event factory realizes that unit 12 is responsible for saving the event that event monitoring unit 00 is registered to event factory 10 The corresponding relationship of interface and event information.Since there may be multiple 00 (this hairs of event monitoring unit in event handling system Bright " multiple " refer to more than one), multiple event monitoring unit 00 may monitor identical event, Different events may be monitored respectively.It is whom that event factory 10, which does not spend and distinguishes specific event monitoring unit 00, only There are 00 registered events interface of event monitoring unit and the event information to be monitored, then event factory 10 just saves the event of registration The corresponding relationship of interface and event information.
In addition, event monitoring unit 00 can also be by calling the offer of event factor interface 11 in event factory 10 RemoveEventListener (remove event monitoring person) method by the event interface of event monitoring unit 00 and to be monitored Parameter of the event information as institute's call method.Event factory realizes that unit 12 deletes the event interface saved and event information Corresponding relationship, this process is properly termed as anti-registration process.
In shown in Fig. 2 203, after the event that event dispatch unit 20 is bound is triggered, event dispatch unit 20 is logical It crosses event factory 10 and enumerates event interface corresponding to the event of the event dispatch unit 20 binding.
Usual each event is all corresponding with event dispatch unit 20, which is responsible for calling event interface, thing After part is triggered, event is distributed to corresponding event interface, to realize distributing for event.
In this step, event dispatch unit 20 can call the event factory enumerates interface 13 of event factory 10 to provide EnumEventListener (enumeration event listener) method, using event information that event dispatch unit 20 is bound as being adjusted With the parameter of method.Event factory realization 12 definite event interface of unit is returned to event group by event factory enumerates interface 13 Bill member 20, event realize that unit 12 is responsible for determining that the event information institute carried when calling EnumEventListener method is right The event interface answered.I.e. event dispatch unit 20 provides the event information of binding, such as event title, volume to event factory 10 Number, mark etc., the corresponding relationship between all event interfaces and event information is inquired by event factory 10, is enumerated the event The corresponding event interface of information, and return to event dispatch unit 20.
In addition, it is necessary to illustrate, event interface enumerates the side that can use dynamic enumeration as described above in step 203 Formula, i.e., when the event bound in event dispatch unit 20 is triggered, dynamic enumeration event interface corresponding with the event information.But The present invention is not limited to the modes of this dynamic enumeration, can also be in initialization, and event dispatch unit 20 connects with regard to carry out event Mouthful enumerate, but when this mode needs periodically or have new registration or anti-registration, timely update the event interface enumerated, Therefore, the mode of the preferred dynamic enumeration of the present invention.
In as shown in Figure 2 204, event dispatch unit 20 passes through the event interface enumerated and sends the thing being triggered Part.
Event dispatch unit 20 is without knowing that whom the listener of event is, it is only necessary to pass through the event interface enumerated in advance Send the event information of triggering.For event monitoring unit 00, pass through the event interface inherited EventMethod (event methods) can realize the monitoring of event by event interface.
It gives one example below, it is assumed that for this object of browser address bar, there are multiple listeners, such as browser Display interface and data storage cell etc., in this example embodiment only by taking the two listeners as an example, corresponding device composition can be as Shown in Fig. 3.The event monitoring unit CaddressBarUIEventListener and data of browser display interface store single The event monitoring unit CtabdataEventListener of member is registered to event factory respectively.
Assuming that its event to be monitored includes one of address field change events, i.e. Navigate (navigation) event, that When registration, the AddEventListener method that CaddressBarUIEventListener calls event factory to provide, and Using event interface IaddressBarUIEvent and the event information Navigate of monitoring as the side AddEventListener The parameter of method.The AddEventListener method that CtabdataEventListener calls event factory to provide, and by event The parameter of interface ItabdataEvent and the event information Navigate of monitoring as AddEventListener method.
The corresponding relationship and ItabdataEvent of event factory preservation IaddressBarUIEvent and Navigate With the corresponding relationship of Navigate.
If Navigate event is triggered, such as when " rollback " on browser/" advance " button is clicked and triggers Navigate event then calls thing with the event dispatch unit CnavigateEventDispatcher of Navigate event binding The EnumEventListener method that part factory provides, using the information of Navigate event as the parameter of institute's call method, example Such as by Navigate, this event name is referred to as parameter.Event factory determines that event interface corresponding with Navigate includes IaddressBarUIEvent and ItabdataEvent, then return to IaddressBarUIEvent and ItabdataEvent CnavigateEventDispatcher, so that the event interface for completing CnavigateEventDispatcher is enumerated.
Then, which is distributed to the event interface enumerated by CnavigateEventDispatcher IaddressBarUIEvent and ItabdataEvent.Due to CaddressBarUIEventListener and CtabdataEventListener inherits the EventMethod of IaddressBarUIEvent and ItabdataEvent respectively Method, therefore just realize the monitoring to Navigate event automatically respectively.It mainly include in event when carry out event distributes That holds distributes, which distributes the variation that browser display interface can be caused to show content and data storage cell The variation of institute's storage content.
Event monitoring unit, event dispatch unit, event title and the called side being related to being related in examples detailed above Method is only schematical example, can also be replaced using other titles.
In several embodiments provided by the present invention, it should be understood that disclosed device and method can pass through it Its mode is realized.For example, the apparatus embodiments described above are merely exemplary, for example, the division of the unit, only Only a kind of logical function partition, there may be another division manner in actual implementation.
The unit as illustrated by the separation member may or may not be physically separated, aobvious as unit The component shown may or may not be physical unit, it can and it is in one place, or may be distributed over multiple In network unit.It can select some or all of unit therein according to the actual needs to realize the mesh of this embodiment scheme 's.
It, can also be in addition, the functional units in various embodiments of the present invention may be integrated into one processing unit It is that each unit physically exists alone, can also be integrated in one unit with two or more units.Above-mentioned integrated list Member both can take the form of hardware realization, can also realize in the form of hardware adds SFU software functional unit.
The above-mentioned integrated unit being realized in the form of SFU software functional unit can store and computer-readable deposit at one In storage media.Above-mentioned SFU software functional unit is stored in a storage medium, including some instructions are used so that a computer It is each that equipment (can be personal computer, server or the network equipment etc.) or processor (processor) execute the present invention The part steps of embodiment the method.And storage medium above-mentioned includes: USB flash disk, mobile hard disk, read-only memory (Read- Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic or disk etc. it is various It can store the medium of program code.
The foregoing is merely illustrative of the preferred embodiments of the present invention, is not intended to limit the invention, all in essence of the invention Within mind and principle, any modification, equivalent substitution, improvement and etc. done be should be included within the scope of the present invention.

Claims (8)

1. a kind of method of event handling, which is characterized in that this method comprises:
The event interface of itself and the event information to be monitored are registered to event factory by event monitoring unit;
The event factory saves the event interface of registration and the corresponding relationship of event information;
The enumeration event listener method that event dispatch unit calls the event factory to provide, the event dispatch unit is tied up Parameter of the fixed event information as institute's call method;Obtain the event dispatch unit binding that the event factory returns Event interface corresponding to event;
Wherein the event interface of itself and the event information to be monitored are registered to event factory and include: by the event monitoring unit
The method that event factory described in the event monitoring cell call provides, this method is for adding event monitoring person, by institute State the event interface and parameter of the event information to be monitored as institute's call method of event monitoring unit itself;Alternatively,
Described event monitoring cell call the method, using the event interface of the event monitoring unit itself as institute's called side The parameter of method, wherein the event interface carries the event information to be monitored by preset function.
2. the method according to claim 1, wherein this method further include:
The removal event monitoring person side RemoveEventListener that event factory described in the event monitoring cell call provides Method, using the event interface of the event monitoring unit itself and the event information to be monitored as the parameter of institute's call method, or Person is using the event interface of the event monitoring unit itself as the parameter of institute's call method, wherein the event interface passes through in advance If function carry the event information to be monitored;
The corresponding relationship of the event interface and event information is deleted by the event factory.
3. method according to claim 1 or 2, which is characterized in that when the event of event dispatch unit binding is touched When hair, the step of executing the enumeration event listener method for calling the event factory to provide.
4. a kind of device of event handling, which is characterized in that the device includes:
Event monitoring unit, for the event interface of itself and the event information to be monitored to be registered to event factory;
Event factory, for saving the event interface of registration and the corresponding relationship of event information;
Event dispatch unit, the enumeration event listener method for calling the event factory to provide, the event is distributed Parameter of the event information of unit binding as institute's call method;Obtain the event dispatch unit that the event factory returns Event interface corresponding to the event of binding;
The wherein event monitoring unit, the method specifically for calling the event factory to provide, this method is for adding thing Part listener, using the event interface of the event monitoring unit itself and the event information to be monitored as the ginseng of institute's call method Number;Alternatively, the method is called, using the event interface of the event monitoring unit itself as the parameter of institute's call method, Described in event interface by preset function carry the event information to be monitored.
5. device according to claim 4, which is characterized in that the event monitoring unit is also used to call the event Removal event monitoring person's RemoveEventListener method that factory provides, by the event of the event monitoring unit itself Interface and parameter of the event information to be monitored as institute's call method, or the event of the event monitoring unit itself is connect Parameter of the mouth as institute's call method, wherein the event interface carries the event information to be monitored by preset function;
The event factory, is also used to delete the corresponding relationship of the event interface and event information.
6. device according to claim 5, which is characterized in that the event factory includes: event factor interface and event Factory realizes unit;
The event factor interface, for the event monitoring unit provide AddEventListener method and RemoveEventListener method;
The event factory realizes unit, for saving or the corresponding relationship of deletion event interface and event information.
7. device according to claim 4, which is characterized in that the event factory include: event factory realize unit and Event factory enumerates interface;
Event factory enumerates interface is used for event dispatch unit offer EnumEventListener method, and to The event dispatch unit returns to the event factory and realizes unit definite event interface;
The event factory realizes unit, for determining event interface corresponding to the event of the event dispatch unit binding.
8. according to device described in claim 4,5,6 or 7, which is characterized in that the event dispatch unit was bound at itself When event is triggered, the operation of the enumeration event listener method for calling the event factory to provide is executed.
CN201510369678.1A 2015-06-29 2015-06-29 A kind of method and apparatus of event handling Active CN105094811B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510369678.1A CN105094811B (en) 2015-06-29 2015-06-29 A kind of method and apparatus of event handling

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510369678.1A CN105094811B (en) 2015-06-29 2015-06-29 A kind of method and apparatus of event handling

Publications (2)

Publication Number Publication Date
CN105094811A CN105094811A (en) 2015-11-25
CN105094811B true CN105094811B (en) 2019-07-02

Family

ID=54575339

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510369678.1A Active CN105094811B (en) 2015-06-29 2015-06-29 A kind of method and apparatus of event handling

Country Status (1)

Country Link
CN (1) CN105094811B (en)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108920150A (en) * 2017-04-11 2018-11-30 武汉斗鱼网络科技有限公司 A kind of event management method and device
CN108319509B (en) * 2017-12-20 2020-10-23 瑞斯康达科技发展股份有限公司 Event management method, system and master control equipment
CN108108170B (en) * 2018-01-04 2021-04-27 武汉斗鱼网络科技有限公司 Decoupling method and system of assembly
CN110018821B (en) * 2019-04-09 2020-10-30 苏州浪潮智能科技有限公司 Method and device for processing webpage information
CN110263070B (en) * 2019-05-30 2021-10-08 北京创鑫旅程网络技术有限公司 Event reporting method and device
CN111596975B (en) * 2020-04-29 2021-07-16 五八有限公司 Event calling method and device, electronic equipment and storage medium

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101599029A (en) * 2009-07-09 2009-12-09 浪潮电子信息产业股份有限公司 Utilize case mechanism in the intermodule method of transferring data among a kind of flex

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101599029A (en) * 2009-07-09 2009-12-09 浪潮电子信息产业股份有限公司 Utilize case mechanism in the intermodule method of transferring data among a kind of flex

Also Published As

Publication number Publication date
CN105094811A (en) 2015-11-25

Similar Documents

Publication Publication Date Title
CN105094811B (en) A kind of method and apparatus of event handling
US9602339B2 (en) System and method for supporting a server-side event model in a distributed data grid
CN103714133A (en) Data operation and maintenance management method and device
BR112012017294B1 (en) method, system and server for collecting software versions
CN109783512A (en) Data processing method, device, computer equipment and storage medium
CN110442502B (en) Point burying method, device, equipment and storage medium
US20200186594A1 (en) Rule-based action triggering in a provider network
CN108345483A (en) A kind of reminding method of notification message, terminal and computer readable storage medium
US20120167105A1 (en) Determining the processing order of a plurality of events
CN111142746B (en) System quota calculation method and device
CN106331065A (en) Proxy application for host system with service container and system
CN113391901A (en) RPA robot management method, device, equipment and storage medium
CN109600344A (en) Identify the method, apparatus and electronic equipment of risk group
CN108717380B (en) Message processing method and device
CN110445828A (en) A kind of data distribution formula processing method and its relevant device based on Redis
CN109842621A (en) A kind of method and terminal reducing token storage quantity
CN106250501B (en) Report processing method and reporting system
CN107277022A (en) Processes Tag method and device
CN109614271A (en) Control method, device, equipment and the storage medium of multiple company-data consistency
CN106055348A (en) Method and device for informing system attribute updating
CN107193821B (en) Monitoring method and system
CN112925622A (en) System timing task processing method and device, electronic equipment and storage medium
CN110532457B (en) Method and system for acquiring network segment ID
WO2016013020A1 (en) Event processing systems and methods
CN110908644A (en) Configuration method and device of state node, computer equipment and storage medium

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20190809

Address after: 100085 Beijing, Haidian District, No. ten on the ground floor, No. 10 Baidu building, layer 2

Patentee after: BEIJING BAIDU NETCOM SCIENCE AND TECHNOLOGY Co.,Ltd.

Address before: 100193 room 1-01, 1-03, 1-04, block C, software Plaza, building 4, No. 8, Mong West Road, Beijing, Haidian District

Patentee before: Pacify a Heng Tong (Beijing) Science and Technology Ltd.