CN114546625A - Cross-platform asynchronous message processing method, device, equipment and storage medium - Google Patents

Cross-platform asynchronous message processing method, device, equipment and storage medium Download PDF

Info

Publication number
CN114546625A
CN114546625A CN202210200013.8A CN202210200013A CN114546625A CN 114546625 A CN114546625 A CN 114546625A CN 202210200013 A CN202210200013 A CN 202210200013A CN 114546625 A CN114546625 A CN 114546625A
Authority
CN
China
Prior art keywords
message
reference count
red
response
black tree
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
CN202210200013.8A
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.)
Suzhou Inspur Intelligent Technology Co Ltd
Original Assignee
Suzhou Inspur Intelligent 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 Suzhou Inspur Intelligent Technology Co Ltd filed Critical Suzhou Inspur Intelligent Technology Co Ltd
Priority to CN202210200013.8A priority Critical patent/CN114546625A/en
Publication of CN114546625A publication Critical patent/CN114546625A/en
Pending legal-status Critical Current

Links

Images

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/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/485Task life-cycle, e.g. stopping, restarting, resuming execution
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The invention belongs to the technical field of asynchronous task processing, and particularly provides a cross-platform asynchronous message processing method, a device, equipment and a storage medium, wherein the method comprises the following steps: when the message is sent, registering the message and the overtime processing function thereof into a time wheel timer, simultaneously adding the message into a red-black tree, and setting reference counting to increase; receiving a response message, and judging whether an overtime processing function of the message is called or not; if not, inquiring a red-black tree to judge whether the message exists; if yes, acquiring a specific object in the red and black tree for response processing; if not, discarding the response message, and decreasing the reference count; if yes, judging that the response is overtime, deleting the message from the red-black tree, and removing the message from the timing task; the reference count is decremented and when the reference count value is zero, the object is destroyed. The objects are managed by introducing the reference count, so that the objects can be correctly released.

Description

Cross-platform asynchronous message processing method, device, equipment and storage medium
Technical Field
The invention relates to the technical field of asynchronous task processing, in particular to a cross-platform asynchronous message processing method, a cross-platform asynchronous message processing device, cross-platform asynchronous message processing equipment and a cross-platform asynchronous message processing storage medium.
Background
In the currently common asynchronous task implementation schemes, there are the following:
one is to set up a thread for each task to process, so that other tasks can continue to run in the main thread, and in the message processing thread, wait for the response of the message. The advantage of this solution is that it is simple to implement, and the disadvantage is that each task needs to individually enable one thread, and the system resource is consumed when there are too many tasks.
Another implementation scheme is to generate a device descriptor for each event, and then add the device descriptor to the system monitor through the IO multiplexing technique of the system, so as to implement notification of the response message. The advantage of this scheme is that a single thread can manage multiple events, the disadvantage is that the implementation is complex, and different system implementations need to be adapted.
Disclosure of Invention
In order to solve the problems of high system resource consumption, complex realization and high cross-platform development difficulty in the realization of asynchronous tasks, the invention provides a cross-platform asynchronous task realization scheme with simple interface and high efficiency, and particularly provides a cross-platform asynchronous message processing method, a device, equipment and a storage medium.
The technical scheme of the invention is as follows:
in a first aspect, a technical solution of the present invention provides a cross-platform asynchronous message processing method, including the following steps:
when the message is sent, registering the message and the overtime processing function thereof into a time wheel timer, simultaneously adding the message into a red-black tree, and setting reference counting to increase;
receiving a response message, and judging whether an overtime processing function of the message is called or not;
if not, inquiring a red-black tree to judge whether the message exists;
if yes, acquiring a specific object in the red and black tree for response processing;
if not, discarding the response message, and decreasing the reference count;
if yes, judging that the response is overtime, deleting the message from the red-black tree, and removing the message from the timing task; the reference count is decremented and when the reference count value is zero, the object is destroyed.
Further, when sending the message, registering the message and the overtime processing function thereof into the time round timer, and adding the message into the red-black tree, wherein the step of setting the reference count to be increased comprises the following steps:
when a message needs to be sent, a message object is constructed; the message object comprises a globally unique process-related message id, a reference count and information contained in the message, wherein the reference count is used for managing the life cycle of the object;
after the message object is generated, adding the message id serving as a key value and the object itself serving as a value into the red and black tree, and adding one to the reference count;
the message is registered in a time wheel timer, and a timed task timeout processing function is registered, and the reference count is increased by one.
Further, the step of querying the red and black tree to determine whether the message exists includes:
receiving and analyzing the response message;
acquiring a message id corresponding to the response message;
and searching the message id in the red and black tree as a key value, and judging whether the message id exists in the red and black tree.
Further, the step of acquiring the specific object in the red-black tree for response processing includes:
acquiring a specific object serving as value in the red and black tree, and performing message response processing;
deleting the message from the time wheel timer after the message is processed, and when the reference count is not zero, subtracting one from the reference count and deleting the message from the red-black tree at the same time, and when the reference count is not zero, subtracting one from the reference count; when the reference count is zero, the object is destroyed.
Further, judging that the response is overtime, deleting the message from the red-black tree, and removing the message from the timing task; the reference count is decremented and when the reference count value is zero, the step of destroying the object includes:
and judging the response is overtime, deleting the message from the red-black tree, when the reference count is not zero, subtracting one from the reference count, removing the message from the timing task, when the reference count is not zero, subtracting one from the reference count, and when the reference count is zero, destroying the object.
In a second aspect, a technical solution of the present invention provides a cross-platform asynchronous message processing apparatus, including a sending setting processing module and a receiving setting processing module;
a sending setting processing module, which is used for registering the message and the overtime processing function thereof into a time wheel timer when the message is sent, and simultaneously adding the message into the red and black tree and setting the increase of the reference count;
the receiving and setting processing module comprises a receiving and judging unit, an inquiring unit, a response processing unit and a setting processing unit;
a receiving judgment unit, configured to receive the response message and judge whether the timeout processing function of the message is called;
the query unit is used for querying the red and black tree to judge whether the message exists or not;
the response processing unit is used for acquiring a specific object in the red and black tree to perform response processing;
the setting processing unit is used for discarding the response message and setting the reference count to be reduced if the response message does not exist in the red and black tree; if the response is overtime, deleting the message from the red-black tree, and simultaneously removing the message from the timing task; the reference count is decremented and when the reference count value is zero, the object is destroyed.
Further, the sending setting processing module comprises a construction unit, an insertion setting unit and a registration setting unit;
the building unit is used for building a message object when a message needs to be sent; the message object comprises a globally unique process-related message id, a reference count and information contained in the message, wherein the reference count is used for managing the life cycle of the object;
the inserting setting unit is used for adding the message id serving as a key value and the object itself serving as a value into the red-black tree after the message object is generated, and adding one to the reference count;
and the registration setting unit is used for registering the message into the time wheel timer, registering a timed task overtime processing function and increasing one by reference count.
Furthermore, the receiving setting processing module also comprises an analysis unit and an acquisition unit;
the analysis unit is used for receiving and analyzing the response message;
the acquiring unit is used for acquiring the message id corresponding to the response message;
and the query unit is specifically used for searching the message id in the red and black tree as a key value and judging whether the message id exists in the red and black tree.
Further, the response processing unit comprises a response submodule and a processing submodule;
the response submodule is specifically used for acquiring a specific object serving as a value in the red-black tree and performing message response processing;
the processing submodule is used for deleting the message from the time wheel timer after the message is processed, subtracting one from the reference count when the reference count is not zero, deleting the message from the red-black tree at the same time, and subtracting one from the reference count when the reference count is not zero; when the reference count is zero, the object is destroyed.
Further, a processing unit is configured to specifically determine that the response is overtime, delete the message from the red-black tree, subtract one from the reference count when the reference count is not zero, remove the message from the timed task, subtract one from the reference count when the reference count is not zero, and destroy the object when the reference count is zero.
In a third aspect, the present invention provides a computer device, including a processor and a memory, where the processor and the memory complete communication with each other through a bus; the memory stores program instructions executable by the processor, the processor invoking the program instructions capable of performing the cross-platform asynchronous message processing method of the first aspect.
In a fourth aspect, the invention is a non-transitory computer readable storage medium storing computer instructions that cause the computer to perform the cross-platform asynchronous message processing method of the first aspect.
According to the technical scheme, the invention has the following advantages: the problem of using relatively less system consumption and relatively simple interfaces to realize a cross-platform asynchronous message solution is solved, wherein a time wheel timer is used, and the time wheel timer is an efficient and platform-independent timer and has the characteristics of simple specific interface and less resource consumption. The invention is used for storing the message object is the red-black tree, compared with the common linked list, the invention has higher efficiency, and meanwhile, the scheme of the invention has simple interface and is convenient for being fast transplanted in the existing system.
1. Whether the management message is sent by the machine or not is judged, a red-black tree is used, when the red-black tree has the advantages of inserting and deleting the object, the tree balance is maintained only by 3 times of rotation, and the comprehensive performance is better compared with other data structures in the scene with larger randomness.
2. The timer is realized by adopting a time wheel, which is an efficient timer realization method and can be used in a cross-platform manner.
3. The objects are managed by introducing the reference count, so that the objects can be correctly released.
4. The interface realized by packaging is simple and convenient for integrated realization.
In addition, the invention has reliable design principle, simple structure and very wide application prospect.
Therefore, compared with the prior art, the invention has prominent substantive features and remarkable progress, and the beneficial effects of the implementation are also obvious.
Drawings
In order to more clearly illustrate the embodiments or technical solutions in the prior art of the present invention, the drawings used in the description of the embodiments or prior art will be briefly described below, and it is obvious for those skilled in the art that other drawings can be obtained based on these drawings without creative efforts.
FIG. 1 is a schematic flow diagram of a method of one embodiment of the invention.
Fig. 2 is a schematic block diagram of an apparatus of one embodiment of the present invention.
Detailed Description
In the currently common asynchronous task implementation schemes, there are the following: one is to set up a thread for each task to process, so that other tasks can continue to run in the main thread, and in the message processing thread, wait for the response of the message. The advantage of this solution is that it is simple to implement, and the disadvantage is that each task needs to individually enable one thread, and the system resource is consumed when there are too many tasks. Another implementation scheme is to generate a device descriptor for each event, and then add the device descriptor to the system monitor through the IO multiplexing technique of the system, so as to implement notification of the response message. The advantage of this scheme is that a single thread can manage multiple events, the disadvantage is that the implementation is complex, and different system implementations need to be adapted. In order to solve the problems of high system resource consumption, complex realization and high cross-platform development difficulty in the realization of asynchronous tasks, the invention provides a cross-platform asynchronous task realization scheme with simple interface and high efficiency, and particularly provides a cross-platform asynchronous message processing method, a device, equipment and a storage medium.
In order to make those skilled in the art better understand the technical solution of the present invention, the technical solution in the embodiment of the present invention will be clearly and completely described below with reference to the drawings in the embodiment of the present invention, and it is obvious that the described embodiment is only a part of the embodiment of the present invention, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
As shown in fig. 1, an embodiment of the present invention provides a cross-platform asynchronous message processing method, including the following steps:
step 1: when the message is sent, registering the message and the overtime processing function thereof into a time wheel timer, simultaneously adding the message into a red-black tree, and setting reference counting to increase;
it should be noted that each node of the Red-Black tree has a storage bit to indicate the color of the node, which may be Red (Red) or Black (Black). The red-black tree is characterized by (1) each node being either black or red. (2) The root node is black. (3) Each leaf Node (NIL) is black. Here, the leaf node refers to a leaf node that is empty (NIL or NULL). (4) If a node is red, its children must be black. (5) All paths from a node to the descendant node of the node contain the same number of black nodes. The step of adding a message to the red and black tree generally comprises: the first step is to take the red and black tree as a binary search tree and insert the nodes. The second step is that: the inserted node is colored "red". And thirdly, reforming the tree into a red-black tree through a series of operations such as rotation or coloring.
Step 2: receiving a response message, and judging whether an overtime processing function of the message is called or not; if not, executing the step 3, and if so, executing the step 6;
and 3, step 3: inquiring the red and black tree to judge whether the message exists; if yes, executing the step 4, and if not, executing the step 5;
and 4, step 4: acquiring specific objects in the red and black trees for response processing;
and 5: discarding the response message, the reference count decreasing;
step 6: judging the response is overtime, deleting the message from the red-black tree, and removing the message from the timing task; the reference count is decremented and when the reference count value is zero, the object is destroyed.
In some embodiments, when the message is sent in step 1, the message and its timeout processing function are registered in the time round timer, and the message is added to the red-black tree, and the step of setting the reference count to be incremented includes:
step 11: when a message needs to be sent, a message object is constructed; the message object comprises a globally unique process-related message id, a reference count and information contained in the message, wherein the reference count is used for managing the life cycle of the object;
step 12: after the message object is generated, adding the message id serving as a key value and the object itself serving as a value into the red and black tree, and adding one to the reference count;
it should be noted that, according to the case of the parent node of the inserted node, the case when the node z is colored as a red node and the insertion of the binary tree is divided into three cases to be handled.
The inserted node is the root node.
The treatment method comprises the following steps: the node is directly painted black.
The parent node of the inserted node is black.
The treatment method comprises the following steps: after the node is inserted, it is still a red-black tree.
And the parent node of the inserted node is red.
The treatment method comprises the following steps: this situation conflicts with the property (5) of the red-black tree. In this case, the inserted node is one where a non-empty grandparent node must exist; furthermore, the inserted node must have a tertiary node (even if the tertiary node is empty, we also consider that the tertiary node exists, and the empty node is a black node). With this in mind, we further divided this Case into 3 cases (Case) based on the Case of tertiary nodes.
(1) The parent node of the current node is red, and the other child node (tertiary node) of the grandparent node of the current node is also red.
(01) The parent node is set to black.
(02) The tertiary node is set to black.
(03) The grandfather node is set to red.
(04) Setting the grandfather node as a current node (red node); i.e. thereafter the operation continues with the current node.
(2) The parent of the current node is red, the tertiary node is black, and the current node is the right child of its parent.
(01) And taking the parent node as a new current node.
(02) And carrying out left-handed rotation by taking the new current node as a fulcrum.
(3) The parent of the current node is red, the tertiary node is black, and the current node is the left child of its parent.
(01) The parent node is set to black.
(02) The grandfather node is set to red.
(03) And (5) taking the grandfather node as a fulcrum to rotate rightwards.
The core ideas for processing the problems are as follows: moving the red node to the root node; then, the root node is set to black.
Step 13: the message is registered in a time wheel timer, and a timed task timeout processing function is registered, and the reference count is increased by one.
Reference count this count is generated to prevent memory leaks. The basic idea is to count the references of dynamically allocated objects, and every time a reference to the same object is added, the reference count of the referenced object is increased, every time a reference is deleted, the reference count is decreased, and when the reference count of an object is decreased to zero, the pointed heap memory is automatically deleted. The reference counting is not garbage collection, the reference technology can recover the objects which are not used any more as soon as possible, meanwhile, long-time waiting is not caused in the collection process, and the life cycle of the resources can be clearly and definitely indicated.
In some embodiments, the step of querying the red-black tree in step 3 to determine whether the message exists includes:
step 31: receiving and analyzing the response message;
step 32: acquiring a message id corresponding to the response message;
step 33: and searching the message id in the red and black tree as a key value, and judging whether the message id exists in the red and black tree.
In some embodiments, the step of obtaining the specific object in the red-black tree in step 4 for response processing includes:
step 41: acquiring a specific object serving as value in the red and black tree, and performing message response processing;
step 42: deleting the message from the time wheel timer after the message is processed, and when the reference count is not zero, subtracting one from the reference count and deleting the message from the red-black tree at the same time, and when the reference count is not zero, subtracting one from the reference count; when the reference count is zero, the object is destroyed.
Note that, any node in the red-black tree is deleted. The operations to be performed are in turn: firstly, taking the red and black tree as a binary search tree, and deleting the node from the binary search tree; the tree is then modified by a series of rotations and recoloring to re-create a red-black tree. The detailed description is as follows:
the first step is as follows: and (4) taking the red and black trees as a binary search tree, and deleting the nodes.
This is the same as the method for deleting nodes in a conventional binary search tree, and there are 3 cases:
(1) the deleted node has no child node, i.e. is a leaf node. Then it is OK to delete the node directly.
(2) The deleted node has only one child node. Then the node is directly deleted and its location is replaced with the node's unique child node.
(3) The deleted node has two children. Then, find out its successor node first; then copying the content of its successor node to the content of the node; after that, its successor node is deleted. Here, the successor node is equivalent to a substitute, and after copying the contents of the successor node to the deleted node, the successor node is deleted. This translates the problem into the case of deleting the successor node. In the case of a deleted node having two non-null child nodes, its successor nodes cannot be dual-child non-null. Since it is unlikely that the successor node will have both children non-empty, this means that the successor node for that node will either have no children or only one child. If no child node exists, processing according to the condition (1); if there is only one child node, the process proceeds as in case (2).
The second step is that: the tree is modified by a series of rotations and recoloring to become a red-black tree. Since the properties of the red and black tree may be violated after the nodes are deleted in the first step. It is necessary to correct the tree by rotating and recoloring to become a red-black tree.
In some embodiments, the response is timed out in step 6, and the message is deleted from the red-black tree and removed from the timed task; the reference count is decremented and when the reference count value is zero, the step of destroying the object includes:
and judging the response is overtime, deleting the message from the red-black tree, when the reference count is not zero, subtracting one from the reference count, removing the message from the timing task, when the reference count is not zero, subtracting one from the reference count, and when the reference count is zero, destroying the object.
The invention uses two background threads, one thread is used for realizing a timer, and the timer is realized by adopting a time wheel. When the message is sent, the message and the overtime processing function thereof are registered in the time wheel through a registration interface, and the message is added into the red and black tree at the same time, so that the life cycle management is realized through reference counting. And when the timer is up, the message response is overtime, a timeout processing function is called, and the object is finally destroyed by referring to the value of the count. And the other thread is used for receiving a message response, judging whether the message is sent out by the process or not in the message response by inquiring the red-black tree, if so, performing message response processing, if not, discarding the message response, and meanwhile, reducing through reference counting, and finally destroying the object. Specifically, when a current program needs to send a message, a message object is constructed that contains a globally unique process-related message id, a reference count, and the necessary information contained in the message itself. Reference counting is used to manage the life cycle of an object. After the message object is generated, the message id is used as a key value, the object itself is used as a value to be added into the red and black tree, and meanwhile, the reference count is increased by one. The message is registered in a timer, and a timed task timeout processing function is registered, and the object reference count is increased by one. When the current program receives the response message, the message id corresponding to the response message is obtained from the analysis message, the message id is used as a key value to search in the message red and black tree, if the message id exists in the red and black tree, the message is sent by the current process, and no current message task is overtime, in this case, a specific object which is used as a value in the red and black tree can be obtained, and the message is further processed. After the message is processed, the message is deleted from the timer, the reference count is reduced by one, and meanwhile, the message is deleted from the red-black tree, and the reference count needs to be reduced by one again. Each time the reference count changes it needs to be determined if it is zero, and if it is zero, the object needs to be destroyed. If the message id is not found in the message red and black tree, which means that the currently received message is not sent by the program, or that the message task is overtime, the message is abandoned. In the timed task timeout processing function of a certain message, if the timer of the message is up, namely the timeout processing function is called, the message is indicated to be overtime, fails to receive a response before the timer is overtime and is processed normally. The timeout handling function needs to define the message handling logic in case of timeout, then delete the message from the message red-black tree, and reduce the reference count by one. If the timeout has elapsed, the system receives a response to the message and the message is not processed again because it has been deleted. It should be noted that, since there is a task that may be time-consuming to process the response message, in a specific implementation, for the time-consuming processing, it may be implemented by using a thread pool or a system asynchronous method to process the response in other threads separately. And will not be described in detail herein.
As shown in fig. 2, an embodiment of the present invention provides a cross-platform asynchronous message processing apparatus, which includes a sending setting processing module and a receiving setting processing module;
a sending setting processing module, which is used for registering the message and the overtime processing function thereof into a time wheel timer when the message is sent, and simultaneously adding the message into the red and black tree and setting the increase of the reference count;
the receiving and setting processing module comprises a receiving and judging unit, an inquiring unit, a response processing unit and a setting processing unit;
a receiving judgment unit, configured to receive the response message and judge whether the timeout processing function of the message is called;
the query unit is used for querying the red and black tree to judge whether the message exists or not;
the response processing unit is used for acquiring a specific object in the red and black tree to perform response processing;
the setting processing unit is used for discarding the response message and setting the reference count to be reduced if the response message does not exist in the red and black tree; if the response is overtime, deleting the message from the red-black tree, and simultaneously removing the message from the timing task; the reference count is decremented and when the reference count value is zero, the object is destroyed.
In some embodiments, the sending setting processing module comprises a construction unit, an insertion setting unit and a registration setting unit;
the building unit is used for building a message object when a message needs to be sent; the message object comprises a globally unique process-related message id, a reference count and information contained in the message, wherein the reference count is used for managing the life cycle of the object;
the inserting setting unit is used for adding the message id serving as a key value and the object itself serving as a value into the red-black tree after the message object is generated, and adding one to the reference count;
and the registration setting unit is used for registering the message into the time wheel timer, registering a timed task overtime processing function and increasing the reference count by one.
In some embodiments, the receiving setting processing module further comprises an analyzing unit and an obtaining unit;
the analysis unit is used for receiving and analyzing the response message;
the acquiring unit is used for acquiring the message id corresponding to the response message;
and the query unit is specifically used for searching the message id in the red and black tree as a key value and judging whether the message id exists in the red and black tree.
In some embodiments, the response processing unit includes a response submodule and a processing submodule;
the response submodule is specifically used for acquiring a specific object serving as a value in the red-black tree and performing message response processing;
the processing submodule is used for deleting the message from the time wheel timer after the message is processed, subtracting one from the reference count when the reference count is not zero, deleting the message from the red-black tree at the same time, and subtracting one from the reference count when the reference count is not zero; when the reference count is zero, the object is destroyed.
In some embodiments, the processing unit is specifically configured to determine that the response is timed out, delete the message from the red-black tree, decrement the reference count by one when the reference count is not zero, remove the message from the timed task, decrement the reference count by one when the reference count is not zero, and destroy the object when the reference count is zero.
The computer device provided by the embodiment of the invention can comprise: the system comprises a processor, a communication interface, a memory and a bus, wherein the processor, the communication interface and the memory are communicated with each other through the bus. The bus may be used for information transfer between the electronic device and the sensor. The processor may call logic instructions in memory to perform the following method: step 1: when the message is sent, registering the message and the overtime processing function thereof into a time wheel timer, simultaneously adding the message into a red-black tree, and setting reference counting to increase; step 2: receiving a response message, and judging whether an overtime processing function of the message is called or not; if not, executing the step 3, and if so, executing the step 6; and step 3: inquiring the red and black tree to judge whether the message exists; if yes, executing the step 4, and if not, executing the step 5; and 4, step 4: acquiring specific objects in the red and black trees for response processing; and 5: discarding the response message, the reference count decreasing; step 6: judging the response is overtime, deleting the message from the red-black tree, and removing the message from the timing task; the reference count is decremented and when the reference count value is zero, the object is destroyed.
In addition, the logic instructions in the memory may be implemented in the form of software functional units and may be stored in a computer readable storage medium when sold or used as a stand-alone product. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
Embodiments of the present invention provide a non-transitory computer-readable storage medium storing computer instructions that cause a computer to perform a method provided by the above method embodiments, for example, including: step 1: when the message is sent, registering the message and the overtime processing function thereof into a time wheel timer, simultaneously adding the message into a red-black tree, and setting reference counting to increase; step 2: receiving a response message, and judging whether an overtime processing function of the message is called or not; if not, executing the step 3, and if so, executing the step 6; and step 3: inquiring the red and black tree to judge whether the message exists; if yes, executing the step 4, and if not, executing the step 5; and 4, step 4: acquiring specific objects in the red and black trees for response processing; and 5: discarding the response message, the reference count decreasing; step 6: judging the response is overtime, deleting the message from the red-black tree, and removing the message from the timing task; the reference count is decremented and when the reference count value is zero, the object is destroyed.
In some specific embodiments, the program instructions executed by the processor in the readable storage medium may specifically implement the following steps: step 11: when a message needs to be sent, a message object is constructed; the message object comprises a globally unique process-related message id, a reference count and information contained in the message, wherein the reference count is used for managing the life cycle of the object; step 12: after the message object is generated, adding the message id serving as a key value and the object itself serving as a value into the red and black tree, and adding one to the reference count; step 13: the message is registered in a time wheel timer, and a timed task timeout processing function is registered, and the reference count is increased by one.
In some specific embodiments, the program instructions executed by the processor in the readable storage medium may specifically implement the following steps: step 31: receiving and analyzing the response message; step 32: acquiring a message id corresponding to the response message; step 33: and searching the message id in the red and black tree as a key value, and judging whether the message id exists in the red and black tree.
In some specific embodiments, the program instructions executed by the processor in the readable storage medium may specifically implement the following steps: step 41: acquiring a specific object serving as value in the red and black tree, and performing message response processing; step 42: deleting the message from the time wheel timer after the message is processed, and when the reference count is not zero, subtracting one from the reference count and deleting the message from the red-black tree at the same time, and when the reference count is not zero, subtracting one from the reference count; when the reference count is zero, the object is destroyed.
Although the present invention has been described in detail by referring to the drawings in connection with the preferred embodiments, the present invention is not limited thereto. Various equivalent modifications or substitutions can be made on the embodiments of the present invention by those skilled in the art without departing from the spirit and scope of the present invention, and these modifications or substitutions are within the scope of the present invention/any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the appended claims.

Claims (10)

1. A cross-platform asynchronous message processing method is characterized by comprising the following steps:
when the message is sent, registering the message and the overtime processing function thereof into a time wheel timer, simultaneously adding the message into a red-black tree, and setting reference counting to increase;
receiving a response message, and judging whether an overtime processing function of the message is called or not;
if not, inquiring a red-black tree to judge whether the message exists;
if yes, acquiring a specific object in the red and black tree for response processing;
if not, discarding the response message, and decreasing the reference count;
if yes, judging that the response is overtime, deleting the message from the red-black tree, and removing the message from the timing task; the reference count is decremented and when the reference count value is zero, the object is destroyed.
2. The cross-platform asynchronous message processing method according to claim 1, wherein when sending the message, registering the message and its timeout processing function in a time round timer, and adding the message to the red-black tree, the step of setting the reference count to increase comprises:
when a message needs to be sent, a message object is constructed; the message object comprises a globally unique process-related message id, a reference count and information contained in the message, wherein the reference count is used for managing the life cycle of the object;
after the message object is generated, adding the message id serving as a key value and the object itself serving as a value into the red and black tree, and adding one to the reference count;
the message is registered in a time wheel timer, and a timed task timeout processing function is registered, and the reference count is increased by one.
3. The cross-platform asynchronous message processing method as claimed in claim 2, wherein the step of querying the red and black tree to determine whether the message exists comprises:
receiving and analyzing the response message;
acquiring a message id corresponding to the response message;
and searching the message id in the red and black tree as a key value, and judging whether the message id exists in the red and black tree.
4. The cross-platform asynchronous message processing method of claim 3, wherein the step of obtaining the specific object in the Reddish Tree for response processing comprises:
acquiring a specific object serving as value in the red and black tree, and performing message response processing;
deleting the message from the time wheel timer after the message is processed, and when the reference count is not zero, subtracting one from the reference count and deleting the message from the red-black tree at the same time, and when the reference count is not zero, subtracting one from the reference count; when the reference count is zero, the object is destroyed.
5. The cross-platform asynchronous message processing method as claimed in claim 4, wherein the response is judged to be overtime, the message is deleted from the Reynebe tree, and the message is removed from the timed task; the reference count is decremented and when the reference count value is zero, the step of destroying the object includes:
and judging the response is overtime, deleting the message from the red-black tree, when the reference count is not zero, subtracting one from the reference count, removing the message from the timing task, when the reference count is not zero, subtracting one from the reference count, and when the reference count is zero, destroying the object.
6. A cross-platform asynchronous message processing device is characterized by comprising a sending setting processing module and a receiving setting processing module;
a sending setting processing module, which is used for registering the message and the overtime processing function thereof into a time wheel timer when the message is sent, and simultaneously adding the message into the red and black tree and setting the increase of the reference count;
the receiving and setting processing module comprises a receiving and judging unit, an inquiring unit, a response processing unit and a setting processing unit;
a receiving judgment unit, configured to receive the response message and judge whether the timeout processing function of the message is called;
the query unit is used for querying the red and black tree to judge whether the message exists or not;
the response processing unit is used for acquiring a specific object in the red and black tree to perform response processing;
the setting processing unit is used for discarding the response message and setting the reference count to be reduced if the response message does not exist in the red and black tree; if the response is overtime, deleting the message from the red-black tree, and simultaneously removing the message from the timing task; the reference count is decremented and when the reference count value is zero, the object is destroyed.
7. The cross-platform asynchronous message processing device of claim 6, wherein the sending setup processing module comprises a construction unit, an insertion setup unit, and a registration setup unit;
the building unit is used for building a message object when a message needs to be sent; the message object comprises a globally unique process-related message id, a reference count and information contained in the message, wherein the reference count is used for managing the life cycle of the object;
the inserting setting unit is used for adding the message id serving as a key value and the object itself serving as a value into the red-black tree after the message object is generated, and adding one to the reference count;
and the registration setting unit is used for registering the message into the time wheel timer, registering a timed task overtime processing function and increasing the reference count by one.
8. The cross-platform asynchronous message processing device of claim 7, wherein the receive setup processing module further comprises a parsing unit, an obtaining unit;
the analysis unit is used for receiving and analyzing the response message;
the acquiring unit is used for acquiring the message id corresponding to the response message;
and the query unit is specifically used for searching the message id in the red and black tree as a key value and judging whether the message id exists in the red and black tree.
9. A computer device comprising a processor and a memory, wherein the processor and the memory communicate with each other via a bus; the memory stores program instructions executable by the processor, the processor invoking the program instructions to perform the cross-platform asynchronous message processing method of any of claims 1 to 5.
10. A non-transitory computer-readable storage medium storing computer instructions for causing a computer to perform the cross-platform asynchronous message processing method according to any one of claims 1 to 5.
CN202210200013.8A 2022-03-01 2022-03-01 Cross-platform asynchronous message processing method, device, equipment and storage medium Pending CN114546625A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210200013.8A CN114546625A (en) 2022-03-01 2022-03-01 Cross-platform asynchronous message processing method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210200013.8A CN114546625A (en) 2022-03-01 2022-03-01 Cross-platform asynchronous message processing method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114546625A true CN114546625A (en) 2022-05-27

Family

ID=81661972

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210200013.8A Pending CN114546625A (en) 2022-03-01 2022-03-01 Cross-platform asynchronous message processing method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114546625A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115599575A (en) * 2022-09-09 2023-01-13 中电信数智科技有限公司(Cn) Novel method for solving concurrent activation and deactivation of cluster logical volume
CN117806905A (en) * 2023-12-25 2024-04-02 湖北安博通科技有限公司 Memory abnormality detection method and system

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115599575A (en) * 2022-09-09 2023-01-13 中电信数智科技有限公司(Cn) Novel method for solving concurrent activation and deactivation of cluster logical volume
CN115599575B (en) * 2022-09-09 2024-04-16 中电信数智科技有限公司 Novel method for solving concurrent activation and deactivation of cluster logical volumes
CN117806905A (en) * 2023-12-25 2024-04-02 湖北安博通科技有限公司 Memory abnormality detection method and system

Similar Documents

Publication Publication Date Title
CN114546625A (en) Cross-platform asynchronous message processing method, device, equipment and storage medium
CN102902583B (en) Managing process under suspended state and executing state
CN109375922A (en) A kind of automatic generation method and terminal device of interface document
CA2424006A1 (en) A technique to generically manage extensible correlation data
CN101477386B (en) Timer implementing method and apparatus
CN103365852A (en) Concurrency control method and system for document library systems
CN102999384A (en) Managing processes within suspend states and execution states
CN110535928B (en) Event pushing method for JAVA intelligent contract of block chain
CN109828960A (en) Log library expansion method, system, computer installation and readable storage medium storing program for executing
CN114124918A (en) Message parsing method and device
CN107329842B (en) Method and terminal for acquiring data based on Qt signal slot mechanism
CN102209016A (en) Data processing method, device and data processing system
CN103646015B (en) Transmission, the method and system for receiving and transmitting XML message
WO2023185335A1 (en) Crash clustering method and apparatus, electronic device and storage medium
CN109146672B (en) Matching method and device based on production mode
CN110535758A (en) A kind of email processing method and device
CN115526586A (en) Business process processing method based on intelligent operation
CN113448647B (en) Resource synchronization method, implementation equipment and electronic equipment
CN108830724A (en) A kind of resource data packet processing method and terminal device
CN114531479A (en) General data acquisition system based on MQTT
CN110442404B (en) Object release method, device, equipment and storage medium
CN104572432B (en) A kind of no chain table managing device
CN110018912A (en) Data cache method, storage medium, equipment and the system for having informing function
CN108881401A (en) Joint behavior document handling method, intermediate server, node, system and medium
CN111767185A (en) Data point burying method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination