Method and device for uniformly receiving broadcast messages
By introducing a global broadcast receiver and event bus into the target application, the broadcast message is uniformly received and converted into event messages, the problem of decentralized code deployment is solved, and system efficiency and maintenance convenience are improved.
Patent Information
- Application Number
- CN202011635577.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-31
- Publication Date
- 2025-08-29
- Estimated Expiration
- 2040-12-31
AI Technical Summary
In the prior art, each service layer needs to independently receive broadcast messages, resulting in decentralized deployment of codes, increasing system overhead and maintenance difficulty.
A global broadcast receiver is used to register when the target application is started, broadcast messages are received uniformly, and converted into event messages, and distributed to the corresponding service layer through the event bus.
It realizes unified reception of broadcast messages, reduces duplicate code, reduces system overhead, and facilitates code maintenance.
Smart Images

Figure CN112732459B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a method and device for uniformly receiving broadcast messages. Background Art
[0002] Typically, a broadcast message uses an IP (Internet Protocol) address with an identifier field containing all 1s as the broadcast address and is sent to all IP addresses included in the identifier field. Currently, to enable all services within an application to listen for broadcast messages, code for receiving broadcast messages is typically deployed at each service layer within the application. Summary of the Invention
[0003] The embodiments of the present application provide a method and device for uniformly receiving broadcast messages.
[0004] In a first aspect, an embodiment of the present application provides a method for uniformly receiving broadcast messages, including: receiving a broadcast message of a target application; creating an event message corresponding to the broadcast message; searching for a service that registers an event message; and sending the event message to a service that registers an event message.
[0005] In some embodiments, receiving a broadcast message from a target application includes: receiving the broadcast message using a global broadcast receiver of the target application.
[0006] In some embodiments, the global broadcast receiver is registered when the target application is launched.
[0007] In some embodiments, searching for a service that has registered an event message includes: searching for an event receiver registered with a global broadcast receiver; and determining, based on the event receiver, a service that needs to monitor the event message.
[0008] In some embodiments, event receivers are created by services.
[0009] In some embodiments, sending the event message to the service that registered the event message includes: traversing the mapping list in the event sender, and calling the object method of the found event receiver one by one to send the event message.
[0010] In some embodiments, the event receiver saves the object methods into a mapping list when it is created.
[0011] In some embodiments, the global broadcast receiver is a process-level broadcast receiver that registers broadcast messages that need to be monitored and always exists within the process. The event sender uses the target application's internal event bus to uniformly forward broadcast messages.
[0012] In the second aspect, an embodiment of the present application provides a device for uniformly receiving broadcast messages, including: a receiving unit, configured to receive broadcast messages of a target application; a creating unit, configured to create an event message corresponding to the broadcast message; a searching unit, configured to search for services that register event messages; and a sending unit, configured to send event messages to services that register event messages.
[0013] In some embodiments, the receiving unit is further configured to: receive the broadcast message using a global broadcast receiver of the target application.
[0014] In some embodiments, the global broadcast receiver is registered when the target application is launched.
[0015] In some embodiments, the search unit is further configured to: search for an event receiver registered with the global broadcast receiver; and determine, based on the event receiver, a service that needs to monitor event messages.
[0016] In some embodiments, event receivers are created by services.
[0017] In some embodiments, the sending unit is further configured to: traverse the mapping list in the event sender, and call the object methods of the found event receivers one by one to send the event message.
[0018] In some embodiments, the event receiver saves the object methods into a mapping list when it is created.
[0019] In some embodiments, the global broadcast receiver is a process-level broadcast receiver that registers broadcast messages that need to be monitored and always exists within the process. The event sender uses the target application's internal event bus to uniformly forward broadcast messages.
[0020] In a third aspect, an embodiment of the present application provides a computer device comprising: one or more processors; a storage device on which one or more programs are stored; when the one or more programs are executed by one or more processors, the one or more processors implement the method described in any implementation method in the first aspect.
[0021] In a fourth aspect, an embodiment of the present application provides a computer-readable medium having a computer program stored thereon, which, when executed by a processor, implements the method described in any implementation manner in the first aspect.
[0022] The method and device for unified broadcast message reception provided in the embodiments of the present application, upon receiving a broadcast message from a target application, creates an event message corresponding to the broadcast message; then searches for the service that has registered for the event message and sends the event message to the service that has registered for the event message. This unified reception of broadcast messages, followed by conversion of the broadcast messages into event messages and distribution to various service layers, enables unified reception of broadcast messages, reduces duplicate code, and lowers system overhead. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Other features, objects and advantages of the present application will become more apparent upon reading the detailed description of non-limiting embodiments made with reference to the following drawings:
[0024] Figure 1 is a flowchart of an embodiment of a method for uniformly receiving broadcast messages according to the present application;
[0025] Figure 2 is a flowchart of another embodiment of a method for uniformly receiving broadcast messages according to the present application;
[0026] Figure 3 It is the application scenario diagram of the registration process;
[0027] Figure 4 It is an application scenario diagram of the broadcast sending process;
[0028] Figure 5 It is a structural diagram of a computer system suitable for implementing the computer device of the embodiment of the present application. DETAILED DESCRIPTION
[0029] The present application will be further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are merely for the purpose of explaining the relevant invention and are not intended to limit the invention. It should also be noted that, for ease of description, only portions relevant to the relevant invention are shown in the accompanying drawings.
[0030] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments in this application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0031] Figure 1 A process 100 of an embodiment of a method for uniformly receiving broadcast messages according to the present application is shown. The method for uniformly receiving broadcast messages includes the following steps:
[0032] Step 101: Receive a broadcast message from a target application.
[0033] In this embodiment, the execution subject of the method for uniformly receiving broadcast messages may receive broadcast messages of target applications.
[0034] Typically, broadcast messages use an IP address with an identification segment containing all 1s as the broadcast address and are transmitted to all IP addresses included in the identification segment. Here, an improvement has been made so that the target application installed on the terminal device receives broadcast messages uniformly, rather than having each business layer of the target application receive them separately. This allows for a single set of code for receiving broadcast messages to be deployed within the target application, eliminating the need to disperse the code across various business layers. This streamlines the code, enabling unified management and easier maintenance, while reducing unnecessary performance loss caused by code duplication.
[0035] It should be noted that the target application can be any application installed on the terminal device, such as a wireless access point management application.
[0036] Step 102: Create an event message corresponding to the broadcast message.
[0037] In this embodiment, the execution entity can create an event message corresponding to the broadcast message. In other words, the broadcast message is converted into an event message, while the content remains unchanged. The event message can be distributed uniformly through the internal event bus of the target application.
[0038] Step 103: Search for the service that registered the event message.
[0039] In this embodiment, the execution subject can search for services that register event messages. Generally, services that need to monitor event messages can be pre-registered so that the execution subject can determine the services that need to monitor event messages.
[0040] Step 104: Send the event message to the service that registered the event message.
[0041] In this embodiment, the execution entity may send the event message to the business that has registered the event message. There may be multiple businesses that have registered the event message, and the execution entity may distribute the event message to these businesses.
[0042] The method for unified broadcast message reception provided in an embodiment of the present application creates an event message corresponding to the broadcast message upon receiving a broadcast message from a target application. It then searches for services registered for event messages and sends the event message to those services. This unified reception of broadcast messages, followed by conversion of broadcast messages into event messages and distribution to various service layers, enables unified broadcast message reception, reduces code duplication, and lowers system overhead.
[0043] Continue to refer Figure 2 , which shows a process 200 of another embodiment of a method for uniformly receiving broadcast messages according to the present application. The method for uniformly receiving broadcast messages includes the following steps:
[0044] Step 201: Register a global broadcast receiver when the target application is started.
[0045] In this embodiment, the method for uniformly receiving broadcast messages can be implemented by registering a global broadcast receiver when the target application is launched. This global broadcast receiver can be used to uniformly receive broadcast messages, replacing the broadcast receivers at each business layer of the target application. The entire target application has only one broadcast receiver, enabling unified processing of broadcast messages.
[0046] Among them, you can register a global broadcast receiver by calling the following code at the start of the app:
[0047] AllBroadcastReceiverHelp.INSTANCE.registerReceiver(this).
[0048] Step 202: The business creates an event receiver.
[0049] In this embodiment, for a service in a target application that needs to monitor event messages, an event receiver may be created, wherein the event receiver may be used to receive event messages converted from broadcast messages.
[0050] Step 203: Save the object method into a mapping list when creating the event receiver.
[0051] In this embodiment, event receivers created by services can be registered with a global broadcast receiver. This allows the global broadcast receiver to identify services that need to monitor event messages after receiving a broadcast message. Specifically, when creating an event receiver, the execution entity can save the event receiver's object methods to a mapping list in the event sender. By traversing the mapping list, the execution entity can determine the services that need to monitor event messages.
[0052] Among them, the business registers event messages by calling the following code during initialization:
[0053] / / Register event messages (create event receivers and register them with event senders)
[0054]
[0055]
[0056] Step 204: Receive the broadcast message using the global broadcast receiver of the target application.
[0057] In this embodiment, the execution entity may utilize a global broadcast receiver of a target application to receive the broadcast message.
[0058] Typically, broadcast messages use an IP address with an identification segment containing all 1s as the broadcast address and are transmitted to all IP addresses included in the host identification segment. Here, an improvement has been made so that the target application installed on the terminal device receives broadcast messages uniformly, rather than having each business layer of the target application receive them separately. This allows for a single set of code for receiving broadcast messages to be deployed within the target application, eliminating the need to disperse the code across various business layers. This streamlines the code, enabling unified management and easier maintenance, while reducing unnecessary performance loss caused by code duplication.
[0059] It should be noted that the target application can be any application installed on the terminal device, such as a wireless access point management application.
[0060] Among them, the code for the global broadcast receiver to uniformly receive broadcast messages can be as follows:
[0061]
[0062]
[0063] Step 205: Create an event message corresponding to the broadcast message.
[0064] In this embodiment, the execution entity can create an event message corresponding to the broadcast message. In other words, the broadcast message is converted into an event message, while the content remains unchanged. The event message can be distributed uniformly through the internal event bus of the target application.
[0065] The code for sending and receiving broadcast messages as event messages for forwarding is as follows:
[0066]
[0067]
[0068] It should be noted that there are a large number of broadcast messages, and only the names of some broadcast messages are listed here as examples.
[0069] Step 206: Search for an event receiver registered with the global broadcast receiver.
[0070] In this embodiment, the execution subject may search for an event receiver registered with a global broadcast receiver.
[0071] Step 207: Based on the event receiver, determine the services that need to monitor event messages.
[0072] In this embodiment, the execution subject can determine the business that needs to monitor event messages based on the event receiver. The business that creates the event receiver is the business that needs to monitor event messages.
[0073] Step 208: traverse the mapping list in the event sender, and call the object methods of the found event receivers one by one to send the event message.
[0074] In this embodiment, the execution subject can directly send event messages to the service by callback. Specifically, the execution subject can traverse the mapping list in the event sender, call the object method of the event receiver found one by one to send the event message, and pass parameters.
[0075] In some embodiments, a global broadcast receiver can be a process-level broadcast receiver that registers all broadcast messages to be monitored and persists within the process. Event dispatchers can use the target application's internal event bus to uniformly forward broadcast messages. This ensures that all broadcast messages are received by a single broadcast receiver and then distributed to various business layers using low-overhead event bus messages.
[0076] from Figure 2 It can be seen that Figure 1 Compared to the corresponding embodiment, process 200 of the method for uniformly receiving broadcast messages in this embodiment highlights the broadcast message receiving step and the event message sending step. Therefore, the solution described in this embodiment registers a global broadcast receiver when the target application starts, receives all broadcast messages required by the target application, converts the broadcast messages into event messages, and sends them directly to the corresponding business via callback. This completes the entire process of converting broadcast messages into event messages, enabling unified reception of broadcast messages, reducing duplicate code, and lowering system overhead.
[0077] For ease of understanding, Figure 3 The application scenario diagram of the registration process is shown in FIG. Figure 3 As shown in the figure, a global broadcast receiver R is created and registered when the app is started. Furthermore, business A creates an event listener and registers it with the global broadcast receiver R. When creating the event receiver, the event receiver's object methods are saved to the event sender E's Map list, completing the event registration. Subsequently, the object methods can be called one by one by traversing the Map list and passing parameters.
[0078] Furthermore, Figure 4 The application scenario diagram of the broadcast sending process is shown in FIG. Figure 4 As shown, the global broadcast receiver R can receive broadcast messages from external broadcasts. The broadcast messages can be converted into corresponding event messages. The event sender E sends the event message to the registered service A.
[0079] Reference below Figure 5, which shows a structural diagram of a computer device computer system 500 suitable for implementing an embodiment of the present application. Figure 5 The computer device shown is only an example and should not limit the functions and scope of use of the embodiments of the present application.
[0080] like Figure 5 As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage unit 508 into a random access memory (RAM) 503. Various programs and data required for the operation of the system 500 are also stored in the RAM 503. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0081] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, and the like; an output section 507 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and a speaker; a storage section 508 including a hard disk; and a communication section 509 including a network interface card such as a LAN card or a modem. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 510 as needed, so that computer programs read therefrom can be installed into the storage section 508 as needed.
[0082] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 509, and / or installed from a removable medium 511. When the computer program is executed by the central processing unit (CPU) 501, the above-mentioned functions defined in the method of the present application are performed.
[0083] It should be noted that the computer-readable medium of the present application may be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, device, or device. In the present application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device. Program code embodied on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wireline, optical fiber cable, RF, or any suitable combination thereof.
[0084] Computer program code for performing the operations of the present application may be written in one or more programming languages, or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or electronic device. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0085] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, program segment or a part of code, and the module, program segment or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented by a dedicated hardware-based system that performs the specified function or operation, or can be implemented by a combination of dedicated hardware and computer instructions.
[0086] The units involved in the embodiments described in this application can be implemented by software or by hardware. The units described can also be set in a processor. For example, it can be described as: a processor includes a receiving unit, a creation unit, a search unit and a sending unit. Among them, the names of these units do not constitute a limitation of the units themselves in this case. For example, the receiving unit can also be described as a "unit that receives broadcast messages from the target application."
[0087] As another aspect, the present application also provides a computer-readable medium, which may be included in the computer device described in the above embodiments, or may exist independently and not be incorporated into the computer device. The computer-readable medium carries one or more programs, which, when executed by the computer device, cause the computer device to: receive a broadcast message from a target application; create an event message corresponding to the broadcast message; search for a service that has registered for the event message; and send the event message to the service that has registered for the event message.
[0088] The above description is merely a preferred embodiment of the present application and an illustration of the technical principles employed. Those skilled in the art should understand that the scope of the invention involved in this application is not limited to the technical solutions formed by the specific combination of the above-mentioned technical features, but also encompasses other technical solutions formed by any combination of the above-mentioned technical features or their equivalents without departing from the above-mentioned inventive concept. For example, a technical solution formed by replacing the above-mentioned features with (but not limited to) technical features with similar functions disclosed in this application.
Claims
1. A method for uniformly receiving broadcast messages, comprising: Receiving a broadcast message from a target application, wherein the target application receives the broadcast message uniformly rather than being received separately by each business layer of the target application; Creating an event message corresponding to the broadcast message to convert the broadcast message into an event message, wherein the event message is uniformly distributed through an internal event bus of the target application; Searching for a service that registers the event message, including: searching for an event receiver created by the service and registered on a global broadcast receiver; and determining, based on the event receiver, a service that needs to monitor the event message; The event message is sent to the business that registered the event message, including: traversing the mapping list in the event sender, calling the object method of the found event receiver one by one to send the event message.
2. The method according to claim 1, wherein The receiving a broadcast message of the target application includes: The broadcast message is received using a global broadcast receiver of the target application.
3. The method according to claim 2, wherein: The global broadcast receiver is registered when the target application is started.
4. The method according to claim 1, wherein The event receiver saves the object methods into the mapping list when it is created.
5. The method according to claim 4, wherein The global broadcast receiver is a process-level broadcast receiver that registers broadcast messages that need to be monitored and always exists in the process. The event sender uses the internal event bus of the target application to uniformly forward broadcast messages.
6. A computer device comprising: one or more processors; a storage device having one or more programs stored thereon; When one or more programs are executed by one or more processors, the one or more processors are caused to implement the method according to any one of claims 1 to 5.
7. A computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Multi-Android-client service sharing method and system
CN103401896A
Application program event processing method and device and electronic equipment
CN111309406A