Methods, apparatus, equipment, media, and program products for handling message subscription events.
By creating associated objects for message subscribers in the iOS system and monitoring reference counts, message subscribers can be automatically removed, thus resolving memory leaks and crashes caused by message subscriptions in the iOS system and improving development efficiency and system stability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA CONSTRUCTION BANK
- Filing Date
- 2022-04-01
- Publication Date
- 2026-07-03
AI Technical Summary
In existing technologies, message subscription methods are prone to memory leaks and system crashes, especially in iOS systems where it is easy to forget to manually remove message subscribers, leading to dangling pointer issues.
By adding associated objects of target message subscribers to the notification registration list, and using runtime mechanisms to monitor the reference count of target properties, the target message subscriber is automatically removed when the count reaches zero, thus avoiding memory leaks and system crashes.
Automatic removal of message subscriptions is implemented, which avoids crashes caused by released message subscribers receiving message notifications, improves development efficiency and reduces the risk of memory leaks.
Smart Images

Figure CN114706697B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of computer technology, and in particular relates to a method, apparatus, device, medium and program product for processing message subscription events. Background Technology
[0002] In order to provide users with information from various applications during mobile device use, mobile devices provide a notification center. This notification center can display push messages from various applications, allowing users to keep up with the latest application updates by viewing the push messages.
[0003] In existing technologies, the common practice is to register as a subscriber to a message with a notification center, which then sends the message to the subscriber when it occurs. However, current message subscription methods carry the risk of memory leaks and system crashes. Summary of the Invention
[0004] This application provides a method, apparatus, device, medium, and program product for processing message subscription events, which can automatically remove message subscribers and prevent released message subscribers from receiving message notifications, thus avoiding crashes.
[0005] On one hand, embodiments of this application provide a method for processing message subscription events, the method including:
[0006] Add the target message subscriber corresponding to the message subscription event to the notification registration list, and create an associated object for the target message subscriber, the associated object including the target attribute created for the target message subscriber;
[0007] Monitor the reference count of the target message subscriber in the target attributes;
[0008] If the reference count is zero, the target message subscriber corresponding to the target attribute is determined;
[0009] Remove the target message subscriber from the notification registration list associated with the message subscription event.
[0010] On the other hand, embodiments of this application provide a message subscription event processing apparatus, the apparatus comprising:
[0011] The add module is used to add a target message subscriber corresponding to the message subscription event to the notification registration list, and create an associated object of the target message subscriber, wherein the associated object includes a target attribute created for the target message subscriber;
[0012] The monitoring module is used to monitor the reference count of the target message subscriber in the target attribute;
[0013] The determination module is used to determine the target message subscriber corresponding to the target attribute when the reference count is detected to be zero.
[0014] The removal module is used to remove the target message subscriber from the notification registration list associated with the message subscription event.
[0015] In another aspect, embodiments of this application provide a message subscription event processing device, the device including: a processor and a memory storing computer program instructions; when the processor executes the computer program instructions, it implements the message subscription event processing method described above.
[0016] In another aspect, embodiments of this application provide a computer storage medium on which computer program instructions are stored. When the computer program instructions are executed by a processor, they implement the message subscription event processing method described above.
[0017] In another aspect, embodiments of this application provide a computer program product in which instructions, when executed by a processor of an electronic device, cause the electronic device to perform the message subscription event processing method described above.
[0018] The message subscription event processing method, apparatus, device, and computer storage medium of this application embodiment, when a message subscriber needs to subscribe to a message event, adds a target message subscriber corresponding to the message subscription event to the notification registration list, creates an associated object of the target message subscriber, monitors the reference count of the target message subscriber in the target attribute of the associated object, and determines the target message subscriber corresponding to the target attribute when the reference count of the message subscriber in the target attribute is zero; then, the target message subscriber is removed from the notification registration list associated with the message subscription event. That is, by creating an associated attribute of the target message subscriber and monitoring the reference count of the target message subscriber through the associated attribute to determine the lifecycle of the target message subscriber, the target message subscriber is automatically removed when the reference count of the target message subscriber is zero, thereby achieving automatic removal of message subscriptions and preventing message subscribers that have already been released from receiving message notifications from crashing. Attached Figure Description
[0019] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 This is a flowchart illustrating a method for processing message subscription events according to an embodiment of this application;
[0021] Figure 2 This is a schematic diagram of the structure of a message subscription event processing apparatus provided in another embodiment of this application;
[0022] Figure 3 This is a schematic diagram of the structure of a message subscription event processing device provided in another embodiment of this application. Detailed Implementation
[0023] The features and exemplary embodiments of various aspects of this application will be described in detail below. To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain this application and not to limit it. For those skilled in the art, this application can be implemented without some of these specific details. The following description of the embodiments is merely to provide a better understanding of this application by illustrating examples.
[0024] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising..." does not exclude the presence of additional identical elements in the process, method, article, or apparatus that includes said element.
[0025] NSNotificationCenter: The NSNotificationCenter is a message broadcasting mechanism provided by the iOS system itself, primarily designed to solve the problem of decoupled message communication between different objects within an application. It is based on the Observer pattern and cannot communicate across application processes. When the NotificationCenter receives a message, it sends the message to its subscribers according to its internally maintained message forwarding table.
[0026] Message subscription: Objects in an application that need to subscribe to notifications must register with the notification center (an instance of the NSNotificationCenter class) to become listeners for that message event. During the registration process, the listener needs to specify a method for the notification center to call when the event occurs. This process is called message subscription.
[0027] Automatic message subscription removal: When a message subscriber's lifecycle expires, the message subscription will be automatically destroyed, releasing memory. There is no need to manually remove the message subscription to release memory. Failure to release memory can cause dangling pointers, leading to an app crash.
[0028] In existing technologies, taking the iOS system as an example, the message subscription and message broadcasting process in the iOS system notification center is as follows:
[0029] 1. Objects in an application that need to subscribe to notifications register with the notification center (an instance of the NSNotificationCenter class) as subscribers to a specific message, thus making the message subscriber a listener for that message event. During the registration process, the listener needs to specify a method for the notification center to call when the message event occurs.
[0030] 2. When a message event occurs, the message broadcasting object sends a notification (an instance of NSNotification) to the notification center. This notification object includes a unique identifier for the notification, a unique ID of the object that issued the notification, and optional additional message information dictionary values.
[0031] 3. The notification center sends a message to each listener that has registered for the message. Calling the method specified by the listener will send the notification to these listeners.
[0032] 4. Message subscribers should remove message subscriptions and release memory in their own dealloc function (called before the object's lifecycle ends) to avoid memory occupation and dangling pointer issues that could cause the app to crash.
[0033] However, the inventors discovered that step 4 above requires manually removing message subscriptions in the dealloc function called before the lifecycle ends. If developers forget to manually move the message subscriptions when using the message center, it will cause memory leaks, which in turn will cause wild pointer problems and lead to app crashes.
[0034] To address the problems of the prior art, embodiments of this application provide a method, apparatus, device, and computer storage medium for processing message subscription events. The method for processing message subscription events provided in this application embodiment will be described first below.
[0035] Figure 1 A flowchart illustrating a method for processing message subscription events according to an embodiment of this application is shown. Figure 1 As shown, the message subscription event processing method provided in this application embodiment includes the following steps: S101 to S104:
[0036] S101. Add the target message subscriber corresponding to the message subscription event to the notification registration list, and create an associated object for the target message subscriber. The associated object includes the target attribute created for the target message subscriber.
[0037] S102. Monitor the reference count of the target message subscriber in the target attribute.
[0038] S103. If the reference count is zero, determine the target message subscriber corresponding to the target attribute.
[0039] S104. Remove the target message subscriber from the notification registration list associated with the message subscription event.
[0040] The message subscription event processing method in this application embodiment adds a target message subscriber corresponding to the message subscription event to the notification registration list when a message subscriber needs to subscribe to a message event, creates an associated object of the target message subscriber, monitors the reference count of the target message subscriber in the target attribute of the associated object, and determines the target message subscriber corresponding to the target attribute when the reference count of the message subscriber in the target attribute is zero; then, the target message subscriber is removed from the notification registration list associated with the message subscription event. That is, by creating an associated attribute of the target message subscriber and monitoring the reference count of the target message subscriber through the associated attribute, the lifecycle of the target message subscriber is determined. When the reference count of the target message subscriber is zero, the target message subscriber is automatically removed, thereby achieving automatic removal of message subscriptions and preventing message subscribers that have already been released from receiving message notifications, which could lead to crashes.
[0041] For iOS systems, the common practice is to use the built-in notification center for message transmission between interactive pages. In iOS development, Objective-C Categories allow for the flexible addition of methods to existing classes (objects), but not "stored properties." This is because the memory space of a class object is determined during the compilation phase. Therefore, it's impossible to add object properties at runtime by changing the object's memory space. This leads to the inability to monitor the lifecycle of message subscribers (objects) in message subscription events. Instead, manual code must be written to remove the message subscriber from the registration list before it is released (i.e., the `dealloc` function of the message subscriber (object) needs to be called before its lifecycle ends to remove the subscriber's registered messages from the registration list). This prevents released message subscribers from receiving notifications, which could cause a crash.
[0042] Therefore, to achieve automatic removal of message subscribers from the registration list, in some embodiments, in S101, a target message subscriber corresponding to the message subscription event is added to the notification registration list, and an associated object of the target message subscriber is created. The associated object includes target attributes created for the target message subscriber.
[0043] Specifically, in order to monitor the lifecycle of a target message subscriber, it is necessary to add the target message subscriber to the notification registration list, create an associated object for the target message subscriber, and add the target attribute to the created associated object.
[0044] In some embodiments, creating an associated object for the target message subscriber may include:
[0045] Use the runtime mechanism to create associated objects for the target message subscribers;
[0046] Add the target attribute to the associated object.
[0047] The runtime describes the software / instructions executed when a program runs. The runtime mechanism can dynamically add attributes and methods to a class. Furthermore, runtime can be used without intruding into the code, allowing the creation of class-related attributes without breaking the original class encapsulation.
[0048] Therefore, in this embodiment, associated attributes can be dynamically created for the target message subscriber through runtime. First, an associated object is created for the object (target message subscriber), and associated attributes (i.e., target attributes) are added to this associated object, that is, the target attribute is associated with the object (target message subscriber).
[0049] In this embodiment, by using a dynamic runtime mechanism, associated objects are used to add associated attributes (target attributes) to message subscribers. This eliminates the need for intrusive processing of the target message subscriber's dealloc function to monitor the target message subscriber's reference count (lifetime) in the target attribute, making message subscription simpler and improving development efficiency.
[0050] In some embodiments, the reference count of the target message subscriber in the target attribute is monitored in S102.
[0051] In iOS, memory management uses reference counting, meaning an object is released and destroyed (i.e., its lifecycle ends) when it is no longer referenced. Since message subscriber objects cannot monitor their own lifecycle, monitoring the lifecycle of the target property corresponding to the message subscription event can be achieved by monitoring the lifecycle of the message subscriber object. The lifecycle of a message subscriber can be detected by using its reference count to determine whether its lifecycle has ended, i.e., whether it will be destroyed.
[0052] In some embodiments, in S103, if the reference count is detected to be zero, the target message subscriber corresponding to the target attribute is determined.
[0053] Specifically, after creating a target attribute associated with a target message subscriber, the reference count of the target message subscriber in the target attribute can be monitored. When the reference count of the target message subscriber in the target attribute is zero, it indicates that the lifecycle of the target message subscriber has ended. When the lifecycle of a message subscriber ends, the system will release the target message subscriber. To prevent released target message subscribers from still receiving notifications of target messages, the message subscribers need to be removed from the notification registry. Since the target attribute is associated with the target message subscriber, the target message subscribers associated with the target attribute can be determined based on the target attribute, and thus the target message subscribers can be found in the notification registry.
[0054] In some embodiments, in S103, the target message subscriber is removed from the notification registration list associated with the message subscription event.
[0055] Specifically, after identifying the target message subscribers that need to be removed, the corresponding registered messages in the notification registration list associated with the message subscription event can be found based on the messages of the target message subscribers, and the registered messages of the target message subscribers can be deleted.
[0056] The above is a specific implementation of the message subscription event processing method provided in this application embodiment. When a message subscriber needs to subscribe to a message event, a target message subscriber corresponding to the message subscription event is added to the notification registration list, and an associated object of the target message subscriber is created. The reference count of the target message subscriber in the target attribute of the associated object is monitored. If the reference count of the message subscriber in the target attribute is zero, the target message subscriber corresponding to the target attribute is determined. Then, the target message subscriber is removed from the notification registration list associated with the message subscription event. That is, by creating an associated attribute of the target message subscriber, the lifecycle of the target message subscriber is determined by monitoring the reference count of the target message subscriber through the associated attribute. When the reference count of the target message subscriber is zero, the target message subscriber is automatically removed, thereby realizing the automatic removal of message subscriptions and avoiding the crash caused by message subscribers that have already been released still receiving message notifications.
[0057] Furthermore, this application embodiment also adopts a runtime mechanism to dynamically create associated attributes (target attributes) of message subscribers. This enables the monitoring of the release timing (lifecycle) of message subscribers in a non-intrusive manner by monitoring the lifecycle of associated attributes. When the lifecycle of a message subscriber is determined to be over, the corresponding registered message in the notification registration list can be automatically deleted, thus realizing the automatic removal of message subscriptions.
[0058] In some embodiments, message subscription and delivery in iOS systems can be performed through the NSNotification mechanism. Notifications are managed through NSNotificationCenter, where observers (i.e., message subscribers) are registered in the NSNotificationCenter's notification dispatch table (notification registration list). When a notification is sent, the observers in the dispatch table are identified using the identifiers name and object. Then, when a message arrives, the corresponding observer's method is called, i.e., the message is delivered.
[0059] In some embodiments, message subscribers can add observers using selectors when subscribing to messages. The selector is a method pointer in the observer; when the notification center receives the target message, this method is executed, passing the relevant content of the target message as a parameter to the observer. However, with the selector approach, the message subscription and message processing methods are physically separated in the code, and it's impossible to specify which thread the message processing method runs on. Special handling is required to specify the thread in which the message processing method runs.
[0060] In some embodiments, message subscribers can add observers based on blocks when subscribing to messages. A block is an object that encapsulates a unit of work and is a code segment that can be executed at any time. Essentially, it is a portable anonymous function that can be passed as an argument to methods and functions and can be returned from methods and functions. After adding observers based on blocks, when the notification center receives the target message, it calls the observer's block and executes the code within the block (i.e., the method for handling the message notification). However, on the one hand, the use of `self` in the observer's block can easily cause circular references, leading to persistent memory usage. This is because iOS uses reference counting for memory management; an object is released and destroyed if it is no longer referenced. Also, blocks typically hold references to objects within them. If the block is a property of `self`, then `self` holds the block, and the use of `self` in the block causes the block to hold `self`, thus creating a circular reference count. This prevents the reference counts of `self` and the block from becoming zero and thus prevents them from being automatically released and reclaimed by the system. On the other hand, observers added using the block method employ strong references. Block methods typically use strong references to objects, incrementing the object's reference count by 1. An object with a reference count greater than or equal to 1 will not be released or destroyed. If the object has already been destroyed during the message notification receiving process, but the block maintains a strong reference to the object during the message processing process, the object may not be removed from the registration list, resulting in a crash because the already released object still receives the notification. Therefore, for strongly referenced objects, it is necessary to manually remove the object from the registration list before the object (observer) is released to avoid crashes caused by already released objects still receiving notifications.
[0061] Therefore, in order to avoid circular references and the need to manually remove observers, as another implementation of this application, this application also provides another implementation of the message subscription event processing method, as detailed in the following embodiments.
[0062] In some embodiments, adding the target message subscriber corresponding to the message subscription event to the notification registration list in S101 may include:
[0063] Receive a message subscription registration request sent by a target message subscriber, wherein the message subscription registration request corresponds to the message subscription event;
[0064] In response to the message subscription registration request, the subscription information of the target message subscriber is added to the notification registration list, and the subscription information includes at least the block method corresponding to the target message.
[0065] Specifically, when a message subscriber needs to subscribe to a target message event, it sends a corresponding message subscription registration request to the message notification center. In response to the message subscription registration request, the subscription information of the target message subscriber is added to the notification registration list. The subscription information may include the block method corresponding to the target message, that is, the method for processing the target message after receiving it. When the notification center receives the target message, it calls the block method corresponding to the target message subscription event, processes the received target message by executing the block method, and then sends it to the message subscriber, thus completing the message subscription and notification.
[0066] In some embodiments, after adding the target message subscriber corresponding to the message subscription event to the notification registration list and creating an associated object of the target message subscriber, the process may further include:
[0067] Upon receiving the target message, the block method is invoked. The parameters of the target message subscriber are passed into the block method through a weak reference. Inside the block method, the block method is executed by using a strong reference to the weakly referenced target message subscriber.
[0068] The process of calling and executing the block method includes: passing the parameters of the target message subscriber into the block method via a weak reference, and then executing the block method by using a strong reference to the weakly referenced target message subscriber. Therefore, in the method of adding message subscribers based on blocks, after receiving a target message notification, the block is called to process the notification. By passing the parameters of the target message subscriber into the block method via a weak reference, the block will not forcibly reference the object (or `self`), and the system will not increment the reference count of the block. This avoids system crashes caused by the failure to release objects outside the block due to strong references within the block. For example, a new variable replacing `self` can be declared using `__weak`, and `weakSelf` can be used to remove the forced reference to `self` within the block, thus preventing circular references. However, if only a weak reference is used to reference an object, it may result in the object being released before it is even used. Therefore, it is necessary to use a strong reference to the weak reference object inside the block. Using a strong reference to the weak reference object inside the block will not affect the release of the object outside, and at the same time, it will prevent the object from being released prematurely inside the block.
[0069] In this embodiment of the application, by adding a block method to the target message subscriber, the parameter of the target message subscriber is first passed in using a weak reference, and then a strong reference is made to the weak reference target message subscriber inside the block method. This can avoid the step of manually handling circular references when using notification center to subscribe to messages, and also avoid the target message subscriber being released prematurely inside the block.
[0070] In some embodiments, the method for handling message subscription events described above may further include:
[0071] Retrieve multiple message notifications from the message notification list;
[0072] Multiple message notifications are matched to determine N target message notifications that match, where N is an integer greater than 1;
[0073] The N target message notifications are merged to obtain the merged message notification.
[0074] Specifically, when a target message subscriber registers multiple times as a subscriber to the same target message, the subscriber may receive multiple identical message notifications. First, multiple message notifications are retrieved from the message notification list, the message notifications are matched, and the N identical message notifications are merged to obtain a merged message notification. The merged message notification is then updated and displayed in the notification center status bar.
[0075] In this embodiment, identical notification messages can be merged to obtain a merged message notification, which is then sent to the target message subscriber, thus improving message delivery efficiency. Displaying the merged message in the notification center's status bar enables quick viewing of message notifications, improves the space utilization of the notification center's status bar, and enhances the user experience.
[0076] In some embodiments, multiple identical notifications can be merged using NSNotificationQueue, meaning multiple identical message notifications can be combined into a single message notification and sent to the message subscribers. NSNotificationQueue is a buffer pool for NSNotificationCenter. Using NSNotificationQueue, notifications are not sent directly to NotificationCenter; instead, they are first sent to NSNotificationQueue, which then decides whether to forward them to NotificationCenter when the current runloop ends or when it is idle. Finally, the notification forwards the notification to the registered observers. NSNotificationQueue allows duplicate notifications to be merged so that only one notification is sent. It implements the function of merging duplicate messages, and this function is flexibly optional for users through configuration.
[0077] The above is a specific implementation of another message subscription event processing method provided in this application embodiment. When calling the processing method for the target message, it can first perform weak reference processing and then strong reference processing. Through weak reference, the operation of incrementing the reference count of the block is avoided, which solves the problem that memory may not be properly released due to circular references. At the same time, the strong reference processing after the weak reference effectively prevents the block from being released prematurely during the processing of the target message, causing access errors. The optimized message subscription event processing method, through the weak reference processing mechanism, eliminates the step of manually handling circular references when message subscribers use the message subscription event processing method, thereby realizing the automatic removal of message subscriptions to the notification center, avoiding the crash caused by message subscribers that have already been released receiving message notifications, and also avoiding memory leaks caused by circular references.
[0078] Based on the message subscription event processing method provided in the above embodiments, this application also provides specific implementations of a message subscription event processing apparatus. Please refer to the following embodiments.
[0079] First see Figure 2 The message subscription event processing apparatus 200 provided in this application embodiment includes the following units:
[0080] The addition module 201 is used to add a target message subscriber corresponding to the message subscription event to the notification registration list, and to create an associated object for the target message subscriber, wherein the associated object includes a target attribute created for the target message subscriber.
[0081] Monitoring module 202 is used to monitor the reference count of the target message subscriber in the target attribute;
[0082] The determination module 203 is used to determine the target message subscriber corresponding to the target attribute when the reference count is detected to be zero.
[0083] The removal module 204 is used to remove the target message subscriber from the notification registration list associated with the message subscription event.
[0084] The message subscription event processing apparatus 200 provided in this application adds a target message subscriber corresponding to the message subscription event to the notification registration list when a message subscriber needs to subscribe to a message event, creates an associated object of the target message subscriber, monitors the reference count of the target message subscriber in the target attribute of the associated object, and determines the target message subscriber corresponding to the target attribute when the reference count of the message subscriber in the target attribute is zero; then, the target message subscriber is removed from the notification registration list associated with the message subscription event. That is, by creating an associated attribute of the target message subscriber and monitoring the lifecycle of the target message subscriber through the associated attribute, the target message subscriber is automatically removed when its lifecycle ends, thereby achieving automatic removal of message subscriptions and preventing crashes caused by released message subscribers still receiving message notifications.
[0085] As one implementation of this application, in order to monitor the lifecycle of the target message subscriber, the aforementioned add module 201 may include:
[0086] The receiving submodule is used to receive a message subscription registration request sent by the target message subscriber, wherein the message subscription registration request corresponds to the message subscription event;
[0087] The registration submodule is used to add the subscription information of the target message subscriber to the notification registration list in response to the message subscription registration request. The subscription information includes at least the block method corresponding to the target message.
[0088] As another implementation of this application, in order to further monitor the reference count of the target message subscriber, the aforementioned added module 201 can also be used for:
[0089] Use the runtime mechanism to create associated objects for the target message subscribers;
[0090] Add the target attribute to the associated object.
[0091] As one implementation of this application, to avoid circular references that could lead to memory leaks, the aforementioned added module 201 may further include:
[0092] The execution submodule is used to call the block method upon receiving a target message. It passes the target message subscriber parameter to the block method via a weak reference, and then executes the block method by creating a strong reference to the weakly referenced target message subscriber.
[0093] As one implementation of this application, in order to achieve the merging of identical message notifications, the above-mentioned apparatus may further include:
[0094] The retrieval module is used to retrieve multiple message notifications from the message notification list;
[0095] The matching module is used to match multiple message notifications to determine the N target message notifications that match, where N is an integer greater than 1;
[0096] The merging module is used to merge N target message notifications to obtain a merged message notification.
[0097] Figure 3 A schematic diagram of the hardware structure of the message subscription event processing device provided in an embodiment of this application is shown.
[0098] The device for processing message subscription events may include a processor 301 and a memory 302 storing computer program instructions.
[0099] Specifically, the processor 301 may include a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits that can be configured to implement the embodiments of this application.
[0100] Memory 302 may include mass storage for data or instructions. For example, and not limitingly, memory 302 may include a hard disk drive (HDD), floppy disk drive, flash memory, optical disk, magneto-optical disk, magnetic tape, or Universal Serial Bus (USB) drive, or a combination of two or more of these. Where appropriate, memory 302 may include removable or non-removable (or fixed) media. Where appropriate, memory 302 may be internal or external to the integrated gateway disaster recovery device. In a particular embodiment, memory 302 is non-volatile solid-state memory.
[0101] Memory may include read-only memory (ROM), random access memory (RAM), disk storage media devices, optical storage media devices, flash memory devices, and electrical, optical, or other physical / tangible memory storage devices. Therefore, typically, memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the message subscription event processing method according to any embodiment of this disclosure.
[0102] The processor 301 reads and executes computer program instructions stored in the memory 302 to implement any of the message subscription event processing methods in the above embodiments.
[0103] In one example, the device for processing message subscription events may further include a communication interface 303 and a bus 310. Wherein, as Figure 3 As shown, the processor 301, memory 302, and communication interface 303 are connected through bus 310 and complete communication with each other.
[0104] The communication interface 303 is mainly used to realize communication between various modules, devices, units and / or equipment in the embodiments of this application.
[0105] Bus 310 includes hardware, software, or both, that couples components of an online data traffic metering device together. For example, and not limitingly, the bus may include an Accelerated Graphics Port (AGP) or other graphics bus, an Enhanced Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), HyperTransport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an Infinite Bandwidth Interconnect, a Low Pin Count (LPC) bus, a memory bus, a Microchannel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local (VLB) bus, or other suitable buses, or combinations of two or more of these. Where appropriate, bus 310 may include one or more buses. Although specific buses are described and illustrated in embodiments of this application, any suitable bus or interconnect is contemplated herein.
[0106] Furthermore, in conjunction with the message subscription event processing methods in the above embodiments, this application embodiment can provide a computer storage medium for implementation. The computer storage medium stores computer program instructions; when these computer program instructions are executed by a processor, they implement any of the message subscription event processing methods in the above embodiments.
[0107] It should be clarified that this application is not limited to the specific configurations and processes described above and shown in the figures. For the sake of brevity, detailed descriptions of known methods are omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of this application is not limited to the specific steps described and shown. Those skilled in the art can make various changes, modifications, and additions, or change the order of steps, after understanding the spirit of this application.
[0108] The functional blocks shown in the above-described structural diagram can be implemented as hardware, software, firmware, or a combination thereof. When implemented in hardware, they can be, for example, electronic circuits, application-specific integrated circuits (ASICs), appropriate firmware, plug-ins, function cards, etc. When implemented in software, the elements of this application are programs or code segments used to perform the required tasks. Programs or code segments can be stored on a machine-readable medium or transmitted over a transmission medium or communication link via data signals carried on a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, fiber optic media, radio frequency (RF) links, etc. Code segments can be downloaded via computer networks such as the Internet, intranets, etc.
[0109] It should also be noted that the exemplary embodiments mentioned in this application describe methods or systems based on a series of steps or apparatus. However, this application is not limited to the order of the above steps; that is, the steps can be performed in the order mentioned in the embodiments, or in a different order, or several steps can be performed simultaneously.
[0110] The aspects of this disclosure have been described above with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It should be understood that each block in the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that these instructions, executable via the processor of the computer or other programmable data processing apparatus, enable the implementation of the functions / actions specified in one or more blocks of the flowchart illustrations and / or block diagrams. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field-programmable logic circuit. It is also understood that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can also be implemented by special-purpose hardware performing the specified functions or actions, or can be implemented by a combination of special-purpose hardware and computer instructions.
[0111] The above description is merely a specific implementation of this application. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, modules, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. It should be understood that the protection scope of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the protection scope of this application.
Claims
1. A method for processing message subscription events, characterized in that, include: Add the target message subscriber corresponding to the message subscription event to the notification registration list, and create an associated object for the target message subscriber, the associated object including the target attribute created for the target message subscriber; Monitor the reference count of the target message subscriber in the target attributes; If the reference count is zero, the target message subscriber corresponding to the target attribute is determined; Remove the target message subscriber from the notification registration list associated with the message subscription event; The creation of the associated object for the target message subscriber includes: Use the runtime mechanism to create associated objects for the target message subscribers; Add the target attribute to the associated object; Adding the target message subscriber corresponding to the message subscription event to the notification registration list includes: Receive a message subscription registration request sent by a target message subscriber, wherein the message subscription registration request corresponds to the message subscription event; In response to the message subscription registration request, the subscription information of the target message subscriber is added to the notification registration list, and the subscription information includes at least the block method corresponding to the target message.
2. The method according to claim 1, characterized in that, After adding the target message subscriber corresponding to the message subscription event to the notification registration list and creating the associated object of the target message subscriber, the method further includes: Upon receiving the target message, the block method is invoked, passing the parameter of the target message subscriber into the block method via a weak reference. Inside the block method, the block method is executed by creating a strong reference to the weakly referenced target message subscriber.
3. The method according to claim 1, characterized in that, The method further includes: Retrieve multiple message notifications from the message notification list; The plurality of message notifications are matched to determine N target message notifications that match, where N is an integer greater than 1; The N target message notifications are merged to obtain a merged message notification.
4. A device for processing message subscription events, characterized in that, The device includes: The add module is used to add a target message subscriber corresponding to the message subscription event to the notification registration list, and create an associated object of the target message subscriber, wherein the associated object includes a target attribute created for the target message subscriber; The monitoring module is used to monitor the reference count of the target message subscriber in the target attribute; The determination module is used to determine the target message subscriber corresponding to the target attribute when the reference count is detected to be zero. A removal module is used to remove the target message subscriber from the notification registration list associated with the message subscription event; The added module is also used for: Use the runtime mechanism to create associated objects for the target message subscribers; Add the target attribute to the associated object; The device further includes: The receiving module is used to receive a message subscription registration request sent by a target message subscriber, wherein the message subscription registration request corresponds to the message subscription event; The registration module is used to add the subscription information of the target message subscriber to the notification registration list in response to the message subscription registration request. The subscription information includes at least the block method corresponding to the target message.
5. A device for processing message subscription events, characterized in that, The device includes: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, it implements the message subscription event processing method as described in any one of claims 1-3.
6. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer program instructions, which, when executed by a processor, implement the message subscription event processing method as described in any one of claims 1-3.
7. A computer program product, characterized in that, When the instructions in the computer program product are executed by the processor of the electronic device, the electronic device performs the message subscription event processing method as described in any one of claims 1-3.