CN107515793A - A kind of module communication means for supporting message mechanism - Google Patents

A kind of module communication means for supporting message mechanism Download PDF

Info

Publication number
CN107515793A
CN107515793A CN201710720836.2A CN201710720836A CN107515793A CN 107515793 A CN107515793 A CN 107515793A CN 201710720836 A CN201710720836 A CN 201710720836A CN 107515793 A CN107515793 A CN 107515793A
Authority
CN
China
Prior art keywords
message
send
communication means
manager
hook
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.)
Pending
Application number
CN201710720836.2A
Other languages
Chinese (zh)
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.)
Sichuan Changhong Electric Co Ltd
Original Assignee
Sichuan Changhong Electric 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 Sichuan Changhong Electric Co Ltd filed Critical Sichuan Changhong Electric Co Ltd
Priority to CN201710720836.2A priority Critical patent/CN107515793A/en
Publication of CN107515793A publication Critical patent/CN107515793A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

The invention discloses a kind of module communication means for supporting message mechanism, method and step is as follows, Step 1: creating a Message dictionary MsgID;Step 2: create the base class BaseMsg of a message;Step 3: create a message manager MsgManager;Step 4: create a self-defined message msg1, inherit BaseMsg, the message that the message is registered in message sink object B initial method is monitored, bind execution method fun (),, it is necessary to send the place of message in message sending object A, message m sg1 is sent by post or send modes, so after A has sent message, the method monitored in B will be performed immediately.Compared with prior art, the present invention allows module on the basis of good communication, by introducing local message communication mechanism, makes module decoupled, and the extension beneficial to module can just solve the above problems well.

Description

A kind of module communication means for supporting message mechanism
Technical field
The present invention relates to one kind to be related to Programming pattern field, the application of multimode, primary structure (non-container injection) Program development, most widely used is flash web games, more particularly to a kind of module communication means for supporting message mechanism.
Background technology
In the medium-and-large-sized application of any language structure, there are many modules, how to allow these modules to communicate to each other, Need to think thinking and design architecture, to meet good autgmentability.Here cast aside as javaEE etc. is with container injection Server architecture, discussion is the framework voluntarily realized based on flash.Flash can regard a pure front end as in itself (V) when, but it is as an operation simultaneously, inside can also include structure and the processing of controller (C) and data model (M). As many large, medium and small web games, all gone to build whole performance with flash.In one flash application, several moulds are included Block.Such as web game, toward big point, there are mapping module, role module, task module, knapsack module, store module, fight mould Block, good friend's module, module etc. of forming a team;It is divided into several submodules again under each big module, under role module, includes male Player, women player, NPC etc..Between these modules, may all there is contact.Appoint as male's player's cutting falls a band When the BOSS of business, it is notified that task module completes a task, while be also notified that broadcast system is wide to full server Cutting boss is broadcast, may can also be broadcasted to good friend and obtain what superfine product equipment, bound new achievement to achievement system, support or oppose Article that packet system renewal newly harvests etc..That is, an event, several other events may be triggered, and these Event is dispersed in different modules.Way before very early is to use " singleton pattern+combination ", and which module needs to change, Just directly invoke the method under the module.Such degree of coupling is very high, it is easy to malfunctions, and to extending and safeguarding pole not side Just.
In Windows systems, program is event driven, all IO inputs all Windows monitoring, when an event During generation, the message of input is first put into system message queue by Windows, then again by the message copying of input to accordingly In application queue, the message loop in application program retrieves each information and sending to corresponding from its message queue Window function in carry out event processing.In flash, flash also has case mechanism (Event), and event machine in itself It is formed with the flow of event of complete set.But the case mechanism requires that the listener of event must inherit IEventDispatcher and connect Mouthful;The self-defined controllability of event is not strong, for example is unable to hook;In registered events, coupling still can occur (such as using group Close to declare member variable or singleton).
The content of the invention
The purpose of the present invention is that providing one kind solves the above problems, the local message communication mechanism based on flash
Support the module communication means of message mechanism.
To achieve these goals, the technical solution adopted by the present invention is:A kind of module communication party for supporting message mechanism Method, it is characterised in that:Method and step is as follows,
Step 1: a Message dictionary MsgID is created, for preserving the ID of all self-defined messages;
Step 2: creating the base class BaseMsg of a message, remaining any self-defined message inherits the base class;
Step 3: create a message manager MsgManager, be responsible for the monitoring of message, transmission, execution, nullify it is interior Section mechanism is realized;
Step 4: creating a self-defined message msg1, BaseMsg is inherited, has a message id in the message:MsgID, It is tied in an ID in MsgID, sets object A as message sending object, object B is message sink object (listener), Fun () method is the specific monitor method of message, and the message of the message is registered in message sink object B initial method Monitor, binding execution method fun (), it is necessary to send the place of message in message sending object A, pass through post or send side Formula sends message m sg1, and so after A has sent message, the method monitored in B will be performed immediately.Send message side Method is as follows, and the message that the message is registered in the initial method in B is monitored, and passes through MsgManager.registerMsg (msgID, fun), binding execution method fun ();Object B fun () place is called in object A, is entrusted It is MsgManager.postMsg (msg1) or MsgManager.sendMsg that MsgManager, which sends the message m sg1, msg1, (msg1)。
Preferably, this method is the framework voluntarily realized based on flash, Flash regards a pure front end as in itself (V) when, but it is as an operation simultaneously, inside can also include structure and the processing of controller (C) and data model (M), This patent is to be based on flash, but thought can be used for any language.
Preferably, in step 4, created in message manager MsgManager a message queue (such as:Number Group Array types), the message sended over for caching post, to perform asynchronous process.
Preferably, in step 4, registerMsg methods, this method are created in message manager MsgManager Receive and be responsible for receiving two msgID, message call back function parameters, array, call back function deposit number are created using msgID as key Group (i.e. observer), so as to which all observers when receiving the message that send or post come, can be broadcast to, perform all disappear Breath readjustment.
Preferably, in step 4, in message manager MsgManager, postMsg methods and sendMsg side are created Method, the two methods are used to send message, and post is that delay is called (i.e. asynchronous execution message is adjusted back) after sending, and send is to send Call (i.e. synchronous to perform) immediately afterwards, two methods all receive a parameter msg, i.e. BaseMsg subclass object, pass through send The message to come over, can take out the msgID of msg objects, travel through and find from message queue, find out corresponding to the message id and own Observer, the message readjustment of these observers is performed immediately after, the message to be come by post, will not be immediately performed, but First it is put into another message and performs queue, then passage time piece asynchronous execution.
Preferably, the message sended over by post, is placed in message queue, timing is gone by a timer Check, once it is not sky to detect queue, just take out (shift) message from queue to perform by intervals;And lead to The message that send is sended over is crossed, is not put into message queue, but be immediately performed.
Preferably, in step 4, message manager MsgManager processing message circulates, and is monitored in message sink object Returned to message, perform method fun ().
Preferably, in step 3, Observer Pattern that message manager mainly uses sees message distribution to corresponding On the person of examining, last listener performs corresponding method;Message can be by hook, hook Message Listener elder generation registration message simultaneously Hook is monitored, and sender of the message retransmits message, and message manager intercepts message, by message distribution according to hook messaging list Seen to corresponding on hook, last hook performs corresponding hook methods.
Compared with prior art, the advantage of the invention is that:The present invention allows module on the basis of good communication, beneficial to expansion Exhibition and maintenance, so as to make system more healthy and stronger.(the container injection that many frameworks provide being cast aside, just for primary exploitation) traditional mould Communication between block, otherwise it is at a relatively high using the method for combination, directly tune object, such degree of coupling;Using language in itself from The case mechanism of band, so with certain limitation.By introducing local message communication mechanism, make module decoupled, beneficial to mould The extension of block can just solve the above problems well., developer develop multimode application when can experience the convenient of the program.
Brief description of the drawings
Fig. 1 is normal messages schematic flow sheet;
Fig. 2 is the message flow schematic diagram with hook mechanism.
Embodiment
The invention will be further described below.
Embodiment 1:A kind of module communication means for supporting message mechanism of the present invention, is performed in local message communication mechanism, So-called local is exactly message without network, only using internal circulation;So-called " message communicating ", exactly send, receive and disappear Breath.Be somewhat like http communication send, post, only overall process inside application without walking network.Also it is somewhat like in js Event, be divided into action listener person, Event senders, event executor, only with event handling or different.The present invention's The means of communication, the communication of all intermodules can be regarded as " local message " one by one, there is a message manager and one Messaging list, the registration of message manager management message are monitored, send, received;Messaging list manages unique ID of every message. The place of transmission message is being needed, message manager is being allowed to act on behalf of and sends message (send and post);Needing received message Place, message manager agency is allowed to carry out received message (first registering regist).The sender and recipient of message do not recognize mutually, hair That send sends by all means, and reception receives by all means, to reach full decoupled.The observer that message manager mainly uses Pattern.Meanwhile message can be by hook, to solve some sudden work.
Normal message flow, referring to Fig. 1, message manager is with Observer Pattern structure message system;Listener is first Registration message is monitored, and sender of the message retransmits message;Manager is responsible for, by message distribution to corresponding observer, finally supervising Hearer performs corresponding method, and whole information communication mechanism has 5 roles:Message manager, message id dictionary, message, message Sender, message recipient (also referred to as listener)." fun () method that object A calls object B " is called according to traditional combination, It is put into message mechanism, then object A is exactly the sender of message, and object B is exactly recipient's (listener) of message, fun () method is exactly the specific monitor method of message.
A kind of module communication means for supporting message mechanism, specific method step is as follows,
First, Message dictionary MsgID, then create the base class BaseMsg and a message of a message one by one is created Manager MsgManager.In MsgID, the ID of all message is preserved.Each customized message inherits BaseMsg, simultaneously An ID is bound in MsgID.In MsgManager, it is responsible for monitoring, transmission, execution, the internal mechanism realization nullified of message. Secondly, a self-defined message msg1 is created, inherits BaseMsg;The message prison of the message is registered in initial method in B Listen (by MsgManager.registerMsg (msgID, fun)), binding execution method fun ();B.fun is called in A The place of (), commission MsgManager send message m sg1 (MsgManager.postMsg (msg1), or MsgManager.sendMsg(msg1)).So, after A has sent message, the method monitored in B will be performed.It is above-mentioned The post and send talked about, it is the modes of two kinds of transmission message, different from the post and send in http agreements, here Post is to postpone to call after sending, and send is called immediately after sending, and specific implementation is in MsgManager, is sent out by post The message brought, is placed in message queue, and regular check is gone by a timer, once it is not sky to detect queue, just (shift) message is taken out to perform from queue by intervals;And the message sended over by send, it is not put into and disappears Queue is ceased, but is immediately performed
Created in message manager MsgManager message queue (such as:Array Array types), for caching The message that post is sended over, to perform asynchronous process.
The establishment registerMsg methods in message manager MsgManager, the responsible reception msgID of this method reception, Two parameters of message call back function, using msgID as key create array, call back function deposit array (i.e. observer), so as to When receiving the message that send or post come, all observers can be broadcast to, perform all message readjustments.
In message manager MsgManager, create postMsg methods and sendMsg methods, the two methods are used for Message is sent, post is to postpone to call (i.e. asynchronous execution message is adjusted back) after sending, and send is called immediately (i.e. synchronously after sending Perform), two methods all receive a parameter msg, i.e. BaseMsg subclass object, the message to be come by send, can incite somebody to action The msgID of msg objects takes out, and travels through and finds from message queue, finds out all observers corresponding to the message id, immediately after The message readjustment of these observers is performed, the message to be come by post, will not be immediately performed, but be first put into another message Queue is performed, then passage time piece asynchronous execution.
Message manager MsgManager processing message is circulated, and message return, the side of execution are listened in message sink object Method fun ().
The Observer Pattern that message manager mainly uses, by message distribution to corresponding observer, last listener Perform corresponding method;Message can be by hook, the message flow with hook mechanism simultaneously, and referring to Fig. 2, hook message is monitored Person elder generation registration message hook is monitored, and sender of the message retransmits message, and message manager disappears according to hook messaging list, interception Breath, message distribution is seen on hook to corresponding, last hook performs corresponding hook methods.
And the local message communication mechanism of this programme, do not require that the listener of message realizes any interface or inherits any class Type, but entrust to message manager to go to monitor;The manual hook of energy, truncated message do other things;Complete decoupled, the hair of message The person of sending and recipient only come into contacts with message manager respectively, do not know the presence of other side mutually.Message in this programme is led to Letter mechanism, (and and non-substituted) can be combined with many frameworks, such as MVC;Simultaneously can also be complete with case mechanism that language carries U.S.'s fusion (also and non-substituted).
Exhaustive presentation is carried out to a kind of module communication means for supporting message mechanism provided by the present invention above, herein In apply specific case to the present invention principle and embodiment be set forth, the explanation of above example is only intended to help Assistant solves the method and its core concept of the present invention;Meanwhile for those of ordinary skill in the art, the think of according to the present invention To think, in specific embodiments and applications there will be changes, the change and improvement to the present invention will be possible, and Without departing from the spirit and scope of accessory claim defined, in summary, this specification content should not be construed as to this hair Bright limitation.

Claims (8)

  1. A kind of 1. module communication means for supporting message mechanism, it is characterised in that:Method and step is as follows,
    Step 1: a Message dictionary MsgID is created, for preserving the ID of all self-defined messages;
    Step 2: creating the base class BaseMsg of a message, remaining any self-defined message inherits the base class;
    Step 3: a message manager MsgManager is created, the monitoring of responsible message, transmission, execution, the inside machine nullified System is realized;
    Step 4: creating a self-defined message msg1, BaseMsg is inherited, has a message id in the message:MsgID, binding In an ID into MsgID, object A is set as message sending object, and object B is message sink object (listener), fun () method is the specific monitor method of message, and the message prison of the message is registered in message sink object B initial method Listen, binding execution method fun (), it is necessary to send the place of message in message sending object A, pass through post or send modes Message m sg1 is sent, so after A has sent message, the method monitored in B will be performed immediately.
  2. A kind of 2. module communication means for supporting message mechanism according to claim 1, it is characterised in that:This method is base In the framework that flash is voluntarily realized.
  3. A kind of 3. module communication means for supporting message mechanism according to claim 1 or 2, it is characterised in that:In step In four, a message queue, the message sended over for caching post are created in message manager MsgManager.
  4. A kind of 4. module communication means for supporting message mechanism according to claim 3, it is characterised in that:In step 4, RegisterMsg methods are created in message manager MsgManager, this method, which receives, to be responsible for receiving msgID, message readjustment Two parameters of function, array, call back function deposit array, to receive send or post mistakes are created using msgID as key During the message come, all observers can be broadcast to, perform all message readjustments.
  5. A kind of 5. module communication means for supporting message mechanism according to claim 4, it is characterised in that:In step 4, In message manager MsgManager, postMsg methods and sendMsg methods are created.The two methods are used to send message, Post is to postpone to call after sending, and send is called immediately after sending, and two methods all receive a parameter msg, i.e. BaseMsg Subclass object, the msgID of msg objects can take out, travel through and find from message queue, look for by the message to be come by send Go out all observers corresponding to the message id, perform the message readjustment of these observers immediately after, disappeared by what post came Breath, will not be immediately performed, but is first put into another message and performs queue, then passage time piece asynchronous execution.
  6. A kind of 6. module communication means for supporting message mechanism according to claim 5, it is characterised in that:Sent out by post The message brought, is placed in message queue, and regular check is gone by a timer, once it is not sky to detect queue, just (shift) message is taken out to perform from queue by intervals;And the message sended over by send, it is not put into and disappears Queue is ceased, but is immediately performed.
  7. A kind of 7. module communication means for supporting message mechanism according to claim 1 or 2, it is characterised in that:Step 4 In, message manager MsgManager processing message is circulated, and message return is listened in message sink object, performs method fun ()。
  8. A kind of 8. module communication means for supporting message mechanism according to claim 1 or 2, it is characterised in that:Step 3 In, Observer Pattern that message manager mainly uses, by message distribution to corresponding observer, last listener performs phase The method answered;Message can be monitored by hook, hook Message Listener elder generation registration message hook simultaneously, and sender of the message retransmits Message;Message manager intercepts message, message distribution seen on hook to corresponding, last hook according to hook messaging list Perform corresponding hook methods.
CN201710720836.2A 2017-08-22 2017-08-22 A kind of module communication means for supporting message mechanism Pending CN107515793A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710720836.2A CN107515793A (en) 2017-08-22 2017-08-22 A kind of module communication means for supporting message mechanism

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710720836.2A CN107515793A (en) 2017-08-22 2017-08-22 A kind of module communication means for supporting message mechanism

Publications (1)

Publication Number Publication Date
CN107515793A true CN107515793A (en) 2017-12-26

Family

ID=60723462

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710720836.2A Pending CN107515793A (en) 2017-08-22 2017-08-22 A kind of module communication means for supporting message mechanism

Country Status (1)

Country Link
CN (1) CN107515793A (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108182121A (en) * 2017-12-29 2018-06-19 广州小鹏汽车科技有限公司 In a kind of Android control large-size screen monitors system module between communication means and system
CN108762943A (en) * 2018-03-22 2018-11-06 武汉斗鱼网络科技有限公司 Obtain method, terminal device and the storage medium of the internal realization process of notice
CN109669787A (en) * 2018-12-05 2019-04-23 恒生电子股份有限公司 Data transmission method and device, storage medium, electronic equipment
CN110413271A (en) * 2019-07-26 2019-11-05 福建省天奕网络科技有限公司 Smart message management method based on Unity3D life cycle
CN111061576A (en) * 2019-11-29 2020-04-24 深圳猛犸电动科技有限公司 Method and system for creating entity object

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030023952A1 (en) * 2001-02-14 2003-01-30 Harmon Charles Reid Multi-task recorder
US6668284B1 (en) * 1998-11-04 2003-12-23 Beckman Coulter, Inc. Software messaging system
US20060031362A1 (en) * 2004-07-01 2006-02-09 International Business Machines Corporation Method and apparatus for instant messaging
CN101141417A (en) * 2007-10-24 2008-03-12 中兴通讯股份有限公司 Inter-task message communicating method in equipment
US20080134155A1 (en) * 2006-11-30 2008-06-05 Ncr Corporation System and method for interpreting a specification language file to implement a business system
CN102402457A (en) * 2010-09-17 2012-04-04 希姆通信息技术(上海)有限公司 Method for processing mobile phone application program alterative events
CN103995752A (en) * 2014-06-16 2014-08-20 上海斐讯数据通信技术有限公司 Intermodule notification callback method and module interaction structure

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6668284B1 (en) * 1998-11-04 2003-12-23 Beckman Coulter, Inc. Software messaging system
US20030023952A1 (en) * 2001-02-14 2003-01-30 Harmon Charles Reid Multi-task recorder
US20060031362A1 (en) * 2004-07-01 2006-02-09 International Business Machines Corporation Method and apparatus for instant messaging
US20080134155A1 (en) * 2006-11-30 2008-06-05 Ncr Corporation System and method for interpreting a specification language file to implement a business system
CN101141417A (en) * 2007-10-24 2008-03-12 中兴通讯股份有限公司 Inter-task message communicating method in equipment
CN102402457A (en) * 2010-09-17 2012-04-04 希姆通信息技术(上海)有限公司 Method for processing mobile phone application program alterative events
CN103995752A (en) * 2014-06-16 2014-08-20 上海斐讯数据通信技术有限公司 Intermodule notification callback method and module interaction structure

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108182121A (en) * 2017-12-29 2018-06-19 广州小鹏汽车科技有限公司 In a kind of Android control large-size screen monitors system module between communication means and system
CN108182121B (en) * 2017-12-29 2020-10-20 广州小鹏汽车科技有限公司 Method and system for communication between modules of Android central control large screen system
CN108762943A (en) * 2018-03-22 2018-11-06 武汉斗鱼网络科技有限公司 Obtain method, terminal device and the storage medium of the internal realization process of notice
CN109669787A (en) * 2018-12-05 2019-04-23 恒生电子股份有限公司 Data transmission method and device, storage medium, electronic equipment
CN110413271A (en) * 2019-07-26 2019-11-05 福建省天奕网络科技有限公司 Smart message management method based on Unity3D life cycle
CN110413271B (en) * 2019-07-26 2022-04-05 福建省天奕网络科技有限公司 Intelligent message management method based on Unity3D life cycle
CN111061576A (en) * 2019-11-29 2020-04-24 深圳猛犸电动科技有限公司 Method and system for creating entity object
CN111061576B (en) * 2019-11-29 2024-04-09 深圳猛犸电动科技有限公司 Method and system for creating entity object

Similar Documents

Publication Publication Date Title
CN107515793A (en) A kind of module communication means for supporting message mechanism
CN110392052A (en) A kind of block chain intelligence contract processing system and method
US20120198004A1 (en) System and method for managing multiple queues of non-persistent messages in a networked environment
CN107172187A (en) A kind of SiteServer LBS and method
CN107273228B (en) Message transmission method based on star topology architecture
CN104901815B (en) A kind of group technology of user terminal, Conference server, conference system
US10063647B2 (en) Systems, apparatuses, and methods for intelligent network communication and engagement
CN109639782A (en) Message sends platform, method
CN106302090B (en) A kind of message treatment method, apparatus and system
CN111614618A (en) Cross-region data transmission method and system for physical isolation device
CN110392106A (en) A kind of method for pushing and device of job state
CN104954321B (en) A kind of connection switching method, apparatus and system
CA2606919A1 (en) Method, system and apparatus for automatic notification to a plurality of communication nodes
JP2008109657A5 (en)
CN107517238A (en) A kind of smart machine control method, device and equipment for Internet of Things
CN109348434A (en) A kind of sending method of scene information, sending device and terminal device
WO2018188381A1 (en) Event routing framework between software modules, and method
CN105490960A (en) SDN configuration, and message forwarding method based on same
CN106997537A (en) Information processing method, apparatus and system for complaint
WO2012174838A1 (en) Method and system of parallel transmitting network element messages
CN109040086A (en) A kind of industrial control system DDOS attack emulation mode and device
CN110290139B (en) Message transmission method and device
CN106293970B (en) Asynchronous processing method and system between a kind of process based on IPC
CN110071952A (en) The control method and device of service call amount
CN103546433B (en) Information synchronization system and method

Legal Events

Date Code Title Description
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20171226

RJ01 Rejection of invention patent application after publication