A data processing method, device, terminal and storage medium
By directly obtaining or sending messages in a message container outside of EventBus, the memory leak problem caused by EventBus registration and cancellation is solved, and the message processing process is simplified.
Patent Information
- Application Number
- CN202110859265.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-28
- Publication Date
- 2025-02-28
- Estimated Expiration
- 2041-07-28
AI Technical Summary
The existing message distribution scheme based on EventBus needs to register before subscribing to messages, and needs to be unregistered after sending messages, resulting in the risk of memory leaks in the project.
By obtaining the request data, querying the target message container based on the request data, and obtaining or sending messages directly from the container without registering and canceling in EventBus.
It effectively solves the memory leak problem caused by the cumbersome registration and cancellation steps in the prior art, and simplifies the message subscription and sending process.
Smart Images

Figure CN113590351B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing, and in particular to a data processing method, device, terminal and storage medium. Background Art
[0002] In the process of Android enterprise-level engineering development, message distribution is a very important link. An excellent message distribution solution can greatly increase development efficiency. EventBus is an event publish-subscribe bus for Android. Its main function is to pass messages between threads. EventBus can simplify the complexity of communication between components in an application, especially the communication between fragments, and avoid many inconveniences caused by using broadcast communication.
[0003] However, the existing message distribution solution based on EventBus requires registration with EventBus before subscribing to messages, and unregistration with EventBus after sending messages. Since the existing message distribution solution based on EventBus must go through cumbersome registration and unregistration steps, there is a risk of memory leak in the project.
[0004] Therefore, the existing technology still needs to be improved and developed. Summary of the invention
[0005] The technical problem to be solved by the present invention is that, in view of the above-mentioned defects of the prior art, a data processing method, device, terminal and storage medium are provided, aiming to solve the problem that the existing message distribution scheme based on EventBus must go through cumbersome registration and deregistration steps, thus causing the risk of memory leakage in the project.
[0006] The technical solution adopted by the present invention to solve the problem is as follows:
[0007] In a first aspect, an embodiment of the present invention provides a data processing method, wherein the method includes:
[0008] Obtain request data, and query the target message container according to the request data;
[0009] When the query is successful, obtaining a target message corresponding to the request data from the target message container;
[0010] The data category corresponding to the request data is obtained, and the target message is processed according to the data category.
[0011] In one implementation, querying a target message container according to the request data includes:
[0012] Get the message class name in the request data;
[0013] Get the preset message container mapping relationship;
[0014] The target message container corresponding to the message class name is searched from a preset message container mapping relationship.
[0015] In one implementation, the processing the target message according to the data category includes:
[0016] When the data category is a monitoring category, the target message is monitored to obtain update information corresponding to the target message.
[0017] In one implementation, the processing the target message according to the data category includes:
[0018] When the data category is a sending category, reviewing the target message;
[0019] When the target message passes the review, the target message is sent.
[0020] In one implementation, the reviewing the target message includes:
[0021] Using the code corresponding to the target message as the code to be verified;
[0022] Obtaining the review mechanism code corresponding to the target message;
[0023] The code to be checked is reviewed according to the review mechanism code.
[0024] In one implementation, sending the target message includes:
[0025] Obtaining subscriber list data corresponding to the target message;
[0026] The targeted message is sent according to the subscriber list data.
[0027] In one implementation, sending the target message according to the subscriber list data includes:
[0028] Obtaining life cycle status information corresponding to each subscriber in the subscriber list data;
[0029] The subscriber whose lifecycle status information is in active state is used as the target subscriber;
[0030] The target message is sent to the target subscriber.
[0031] In a second aspect, an embodiment of the present invention further provides a data processing device, wherein the device comprises:
[0032] A query module, used to obtain request data and query a target message container according to the request data;
[0033] An acquisition module, used for acquiring a target message corresponding to the request data from the target message container when the query is successful;
[0034] The processing module is used to obtain the data category corresponding to the request data and process the target message according to the data category.
[0035] In a third aspect, an embodiment of the present invention further provides a terminal, wherein the terminal includes a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by one or more processors, including for executing any of the data processing methods described above.
[0036] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium on which a plurality of instructions are stored, wherein the instructions are suitable for being loaded and executed by a processor to implement the steps of any of the above-mentioned data processing methods.
[0037] Beneficial effects of the present invention: The embodiment of the present invention obtains request data, queries the target message container according to the request data; when the query is successful, obtains the target message corresponding to the request data from the target message container; obtains the data category corresponding to the request data, and processes the target message according to the data category. When subscribing to messages and sending messages, the present invention only needs to generate corresponding request data, query the target message container according to the request data, and directly use the target message container to get the message for subscription or sending, without registering and unregistering in EventBus. Therefore, it can effectively solve the problem that the existing message distribution scheme based on EventBus must go through cumbersome registration and unregistration steps, thus causing the risk of memory leaks in the project. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0039] Figure 1 It is a flowchart of a data processing method provided by an embodiment of the present invention.
[0040] Figure 2 It is a schematic diagram of a process of monitoring a target message provided by an embodiment of the present invention.
[0041] Figure 3 It is a schematic diagram of a process of sending a target message provided by an embodiment of the present invention.
[0042] Figure 4 It is a reference diagram of the message scope provided by an embodiment of the present invention.
[0043] Figure 5 It is a connection diagram of internal modules of a data processing device provided by an embodiment of the present invention.
[0044] Figure 6 It is a principle block diagram of a terminal provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0045] In order to make the purpose, technical solution and advantages of the present invention clearer and more specific, the present invention is further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0046] It should be noted that if the embodiments of the present invention involve directional indications (such as up, down, left, right, front, back, etc.), the directional indications are only used to explain the relative position relationship, movement status, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly.
[0047] In the process of Android enterprise-level engineering development, message distribution is a very important link. An excellent message distribution solution can greatly increase development efficiency. EventBus is an event publish-subscribe bus for Android. Its main function is to pass messages between threads. EventBus can simplify the complexity of communication between components in an application, especially the communication between fragments, and avoid many inconveniences caused by using broadcast communication.
[0048] The existing message distribution solutions based on EventBus have the following main defects:
[0049] 1. Registration and deregistration are required, and the project may have the risk of memory leaks.
[0050] 2. The number of messages sent by EventBus increases exponentially, increasing the risk of errors.
[0051] 3. The location where the positioning message is sent is more complicated.
[0052] 4. Each event in EventBus is a separate class, which makes maintenance more difficult.
[0053] 5. There is no scope limit for messages.
[0054] 6. There is no business control review mechanism for messages.
[0055] In general, the existing message distribution solutions based on EventBus require registration with EventBus before subscribing to messages, and unregistration with EventBus after sending messages. Since the existing message distribution solutions based on EventBus must go through cumbersome registration and unregistration steps, there is a risk of memory leaks in the project.
[0056] In view of the above-mentioned defects of the prior art, the present invention provides a data processing method, the method comprising: obtaining request data, querying a target message container according to the request data; when the query is successful, obtaining a target message corresponding to the request data from the target message container; obtaining a data category corresponding to the request data, and processing the target message according to the data category. When subscribing to messages and sending messages, the present invention only needs to generate corresponding request data, query the target message container according to the request data, and directly use the target message container to obtain the message for subscription or sending, without the need to register and unregister in EventBus. Therefore, it can effectively solve the problem that the existing message distribution scheme based on EventBus must go through cumbersome registration and unregistration steps, thus causing the risk of memory leaks in the project.
[0057] like Figure 1 As shown, the method comprises the following steps:
[0058] Step S100: Obtain request data, and query the target message container according to the request data.
[0059] Specifically, the present embodiment pre-creates multiple message containers, each of which can contain multiple messages, and has high maintenance efficiency. When a user needs to subscribe to or send a message, request data corresponding to the message is generated first, and the request data is sent to the terminal, so that the terminal searches for the message container storing the message according to the request data, and uses the searched message container as the target message container.
[0060] In one implementation, Figure 4 As shown in the figure, each message container has its corresponding message scope. There are two types of message scopes: global message scope and local message scope. The global message scope can send and subscribe messages in the entire project, while the local message scope can only send and subscribe messages within the specified module.
[0061] In one implementation, querying the target message container according to the request data specifically includes the following steps:
[0062] Step S101, obtaining the message class name in the request data;
[0063] Step S102: Obtain a preset message container mapping relationship;
[0064] Step S103: query the target message container corresponding to the message class name from the preset message container mapping relationship.
[0065] Specifically, in addition to the corresponding control instructions, the request data also includes the message class name corresponding to the message that the user requests to subscribe to or send. After the terminal obtains the request data, it analyzes the request data to obtain the message class name. Then, the terminal will call the pre-stored message container mapping relationship. Since the message container mapping relationship can reflect the correspondence between different message class names and message containers, the target message container corresponding to the message that the user requests to subscribe to / send can be queried based on the obtained message class name and message container mapping relationship.
[0066] For example, Figure 2 or Figure 3 As shown, assuming that the user requests to subscribe or send a message M, the request data will include the message class name corresponding to the message M. After the terminal obtains the message class name in the request data, it searches for the message container corresponding to the message M in the pre-stored message container mapping relationship. If the query is successful, the message container obtained by the query is used as the target message container corresponding to the message M.
[0067] like Figure 1 As shown, the method further comprises the following steps:
[0068] Step S200: When the query is successful, obtain the target message corresponding to the request data from the target message container.
[0069] Specifically, when the query is successful, it means that there is a target message container corresponding to the request data, that is, the message requested to be subscribed / sent by the user is a historical message, so the message requested to be subscribed / sent by the user can be directly obtained from the target message container, that is, the target message is obtained.
[0070] like Figure 1 As shown, the method comprises the following steps:
[0071] Step S300: Obtain the data category corresponding to the request data, and process the target message according to the data category.
[0072] Since users can subscribe to messages, that is, monitor a message to obtain the update status of the message in real time; users can also send messages, that is, send a message to other subscribers to achieve message sharing. Therefore, the data category corresponding to the request data can reflect the specific operation that the user expects to perform on the target message, that is, whether the user expects to perform a subscription operation or a sending operation on the target message, so that the terminal can perform different processing on the target message.
[0073] In one implementation, step S300 specifically includes the following steps:
[0074] Step S301: When the data category is a monitoring category, monitor the target message to obtain update information corresponding to the target message.
[0075] Specifically, when the data category corresponding to the request data is the monitoring category, it means that the user expects to monitor the target message to obtain the updated information corresponding to the target message in real time. Then the terminal will generate a corresponding monitoring event according to the target message and set the user as the listener. When the terminal obtains the updated information corresponding to the target message according to the monitoring event, it will pass the updated information to the listener so that the user can know the update of the target message in time (such as Figure 2 shown).
[0076] In one implementation, step S300 specifically includes the following steps:
[0077] Step S302: When the data category is a sending category, the target message is examined;
[0078] Step S303: When the target message passes the review, the target message is sent.
[0079] Specifically, when the data category corresponding to the request data is the sending category, it means that the user expects to send the target message to other subscribers so that other subscribers can view the target message. In this embodiment, the business end does not need to consider the initialization problem, and implements non-perceptual initialization based on Android ContentProvider. In addition, the sending of each message can control the number of output code lines of logcat and directly jump to the line of code for debugging. Therefore, before sending the target message, the terminal needs to review the target message to ensure that the corresponding code is correct. Only after the target message passes the review will the terminal send the target message to other subscribers (such as Figure 3 shown).
[0080] In one implementation, the reviewing of the target message specifically includes the following steps:
[0081] Step S3021: taking the code corresponding to the target message as the code to be verified;
[0082] Step S3022: Obtain the review mechanism code corresponding to the target message;
[0083] Step S3023: review the code to be verified according to the review mechanism code.
[0084] Specifically, when the business end creates each message in this embodiment, a review mechanism code corresponding to the message will be created at the same time. The review mechanism code can reflect the review logic corresponding to the message, so that the message is reviewed according to the review logic. After the review by the review logic, it can be determined whether the message complies with the specifications, thereby realizing the selective sending of messages, that is, messages that do not comply with the specifications are rejected and messages that comply with the specifications are sent.
[0085] In one implementation, sending the target message specifically includes the following steps:
[0086] Step S3031, obtaining subscriber list data corresponding to the target message;
[0087] Step S3032: Send the target message according to the subscriber list data.
[0088] Specifically, in order to control the exponential growth notification of messages, this embodiment will set the subscriber list data that can receive the message when creating each message. Therefore, when the user needs to send the target message, the terminal will first obtain the subscriber list corresponding to the target message, and then selectively send the target message according to the subscriber list data. Since this embodiment sends the target message based on the subscriber list data, rather than sending the target message based on Java reflection call like the existing message distribution method based on EventBus, it can effectively control the exponential growth notification of messages.
[0089] In one implementation, sending the target message based on the subscriber list data includes: obtaining life cycle status information corresponding to each subscriber in the subscriber list data; taking the subscriber whose life cycle status information is active as the target subscriber; and sending the target message to the target subscriber.
[0090] As time goes by, some of the subscribers who originally existed in the subscriber list data may have disappeared. Therefore, it is unrealistic to send the target message to each subscriber in the subscriber list data. Therefore, before sending the target message, this embodiment needs to obtain the life cycle status information of each subscriber in the subscriber list data. The life cycle status information can reflect the current existence status of the subscriber. If the life cycle status information of the subscriber is in the extinct state, it means that the subscriber no longer exists. If the life cycle status information of the subscriber is in the active state, it means that the subscriber still exists. Therefore, this embodiment filters out subscribers whose life cycle status information is in the active state as target subscribers, and sends the target message to each target subscriber, thereby avoiding sending messages to subscribers who no longer exist.
[0091] In one implementation, before sending the target message to the target subscriber, the method further includes: obtaining a preset sending frequency mapping table, determining the sending frequency corresponding to each target subscriber according to the sending frequency mapping table, selecting a valid subscriber from the target subscriber according to the sending frequency, and sending the target message to the valid subscriber. This avoids the problem of LiveData sticky messages.
[0092] In one implementation, the method further includes the following steps:
[0093] Step S1: when the query is unsuccessful, create a new message container corresponding to the request data according to the message class name;
[0094] Step S3: Obtain a preset container mapping relationship, and add a corresponding relationship between the message class name and the newly added message container to the container mapping relationship.
[0095] Specifically, when the query is unsuccessful, it means that the message that the user requested to subscribe / send is a new message and has not been stored before. Then, according to the preset network key (DEFAULT_KEY) and the message class name in the request data, a new message container is automatically created, and the new message container is used to store the message data corresponding to the request data. In addition, it is necessary to add the corresponding relationship between the message class name and the new message container in the original container mapping relationship for the next acquisition.
[0096] Compared with the existing message distribution solution based on EventBus, the embodiments of the present invention have the following advantages:
[0097] 1. No memory leak will occur;
[0098] 2. It will not crash due to Activity stopping;
[0099] 3. No need to manually handle the life cycle;
[0100] 4. The data will always be kept up to date;
[0101] 5. You can write message containers and control the message scope;
[0102] 6. The business adds review logic to control the message sending entry;
[0103] 7. Based on the Jetpack library, there is no need to introduce other third-party libraries;
[0104] 8. No need to register or log out, reducing code risks;
[0105] 9.Log positioning, each message can be directly located to the sending code position, which is convenient for debugging.
[0106] Based on the above embodiments, the present invention further provides a data processing device, such as Figure 5 As shown, the device comprises:
[0107] Query module 01, used to obtain request data and query the target message container according to the request data;
[0108] The acquisition module 02 is used to acquire the target message corresponding to the request data from the target message container when the query is successful;
[0109] The processing module 03 is used to obtain the data category corresponding to the request data and process the target message according to the data category.
[0110] In one implementation, the query module 01 includes:
[0111] An unpacking unit, used for obtaining a message class name in the request data;
[0112] An acquisition unit, used to acquire a preset message container mapping relationship;
[0113] The query unit is used to query the target message container corresponding to the message class name from a preset message container mapping relationship.
[0114] In one implementation, the processing module 03 includes:
[0115] A monitoring unit, configured to monitor the target message when the data category is a monitoring category, and obtain update information corresponding to the target message;
[0116] A review unit, configured to review the target message when the data category is a sending category;
[0117] A sending unit is used to send the target message when the target message passes the review.
[0118] Based on the above embodiment, the present invention further provides a terminal, whose principle block diagram can be shown as follows: Figure 6 As shown. The terminal includes a processor, a memory, a network interface, and a display screen connected through a system bus. Among them, the processor of the terminal is used to provide computing and control capabilities. The memory of the terminal includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the terminal is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a data processing method is implemented. The display screen of the terminal can be a liquid crystal display screen or an electronic ink display screen.
[0119] Those skilled in the art will understand that Figure 6 The principle block diagram shown in the figure is only a block diagram of a partial structure related to the scheme of the present invention, and does not constitute a limitation on the terminal to which the scheme of the present invention is applied. The specific terminal may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0120] In an implementation manner, one or more programs are stored in the memory of the terminal, and the one or more programs are configured to be executed by one or more processors, and include instructions for performing the data processing method.
[0121] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided by the present invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0122] In summary, the present invention discloses a data processing method, device, terminal and storage medium, the method comprising: obtaining request data, querying a target message container according to the request data; when the query is successful, obtaining a target message corresponding to the request data from the target message container; obtaining a data category corresponding to the request data, and processing the target message according to the data category. When subscribing to messages and sending messages, the present invention only needs to generate corresponding request data, query the target message container according to the request data, and directly use the target message container to obtain the message for subscription or sending, without the need to register and unregister in EventBus. Therefore, it can effectively solve the problem that the existing message distribution scheme based on EventBus must go through cumbersome registration and unregistration steps, thus causing the risk of memory leaks in the project.
[0123] It should be understood that the application of the present invention is not limited to the above examples. For ordinary technicians in this field, improvements or changes can be made based on the above description. All these improvements and changes should fall within the scope of protection of the claims attached to the present invention.
Claims
1. A data processing method, characterized in that: The method comprises: Obtain request data, and query the target message container according to the request data; When the query is successful, obtaining a target message corresponding to the request data from the target message container; Obtaining a data category corresponding to the request data, and processing the target message according to the data category; The querying of the target message container according to the request data includes: Get the message class name in the request data; Get the preset message container mapping relationship; Query the target message container corresponding to the message class name from the preset message container mapping relationship; wherein each message container has its corresponding message scope; there are two types of message scopes, one is the global message scope and the other is the local message scope; the global message scope can send and subscribe messages within the entire project, and the local message scope can only send and subscribe messages within the specified module; The processing of the target message according to the data category includes: When the data category is a monitoring category, monitoring the target message to obtain update information corresponding to the target message; The processing of the target message according to the data category includes: When the data category is a sending category, reviewing the target message; When the target message passes the review, sending the target message; The sending of the target message according to the subscriber list data comprises: Obtaining life cycle status information corresponding to each subscriber in the subscriber list data; The subscriber whose lifecycle status information is in active state is used as the target subscriber; Sending the target message to the target subscriber; Before sending the target message to the target subscriber, the method further includes: A preset sending frequency mapping table is obtained, and a sending frequency corresponding to each target subscriber is determined according to the sending frequency mapping table, and a valid subscriber is selected from the target subscribers according to the sending frequency, and the target message is sent to the valid subscriber.
2. The data processing method according to claim 1, characterized in that: The reviewing of the target message includes: Using the code corresponding to the target message as the code to be verified; Obtaining the review mechanism code corresponding to the target message; The code to be checked is reviewed according to the review mechanism code.
3. The data processing method according to claim 1, characterized in that: The sending of the target message comprises: Obtaining subscriber list data corresponding to the target message; The targeted message is sent according to the subscriber list data.
4. A data processing device, characterized in that: The device comprises: A query module, used to obtain request data and query a target message container according to the request data; An acquisition module, used for acquiring a target message corresponding to the request data from the target message container when the query is successful; A processing module, used for obtaining a data category corresponding to the request data, and processing the target message according to the data category; The querying of the target message container according to the request data includes: Get the message class name in the request data; Get the preset message container mapping relationship; Query the target message container corresponding to the message class name from the preset message container mapping relationship; wherein each message container has its corresponding message scope; there are two types of message scopes, one is the global message scope and the other is the local message scope; the global message scope can send and subscribe messages within the entire project, and the local message scope can only send and subscribe messages within the specified module; The processing of the target message according to the data category includes: When the data category is a monitoring category, monitoring the target message to obtain update information corresponding to the target message; The processing of the target message according to the data category includes: When the data category is a sending category, reviewing the target message; When the target message passes the review, sending the target message; The sending of the target message according to the subscriber list data comprises: Obtaining life cycle status information corresponding to each subscriber in the subscriber list data; The subscriber whose lifecycle status information is in active state is used as the target subscriber; Sending the target message to the target subscriber; Before sending the target message to the target subscriber, the method further includes: A preset sending frequency mapping table is obtained, and a sending frequency corresponding to each target subscriber is determined according to the sending frequency mapping table, and a valid subscriber is selected from the target subscribers according to the sending frequency, and the target message is sent to the valid subscriber.
5. A terminal, characterized in that: The terminal includes a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by one or more processors, including for executing the data processing method as described in any one of claims 1-3.
6. A computer-readable storage medium having a plurality of instructions stored thereon, characterized in that: The instructions are suitable for being loaded and executed by a processor to implement the steps of the data processing method described in any one of claims 1 to 3 above.
Citation Information
Patent Citations
Distributed event bus processing method based on message queue, terminal and medium
CN112527525A