Disclosure of Invention
The embodiment of the application provides a data processing method, and the problem of low efficiency caused by numerous entry codes when the life cycle of an application program is realized is solved.
The method comprises the following steps:
monitoring the life cycle nodes of the application program;
responding to the monitored life cycle nodes, and executing decoupling configuration on at least one task to be operated of the application program according to a life cycle protocol corresponding to the currently monitored life cycle nodes;
inquiring a protocol identifier of the life cycle protocol corresponding to the currently monitored life cycle node in at least one task to be operated after the decoupling configuration is completed;
when the query of any one task to be operated fails, triggering the application program to operate the task to be operated with the failed query by using the life cycle protocol corresponding to the life cycle node, and adding the currently monitored protocol identifier of the life cycle protocol corresponding to the life cycle node.
Optionally, traversing at least one task to be run completing the decoupling configuration;
inquiring the protocol identification of the life cycle protocol corresponding to the currently monitored life cycle node in the traversed task to be run;
and if the protocol identification of the life cycle protocol corresponding to the currently monitored life cycle node is successfully inquired, skipping the currently traversed task to be run.
Optionally, calling a sharing parameter adapted to the lifecycle protocol corresponding to the currently monitored lifecycle node;
and configuring task parameters of at least one task to be run by using the called shared parameters.
Optionally, when the task to be executed runs to the lifecycle node corresponding to the application program to be started, a task dispatcher is instantiated, and the acquired task to be executed is added to the task dispatcher.
In another embodiment of the present invention, there is provided an apparatus for data processing, the apparatus including:
the monitoring module is used for monitoring the life cycle nodes of the application program;
the decoupling module is used for responding to the monitored life cycle node and executing decoupling configuration on at least one task to be operated of the application program according to the currently monitored life cycle protocol corresponding to the life cycle node;
the query module is used for querying a currently monitored protocol identifier of the life cycle protocol corresponding to the life cycle node in at least one task to be operated after the decoupling configuration is completed;
and the execution module is used for triggering the application program to operate the task to be operated with failed query by utilizing the life cycle protocol corresponding to the life cycle node when the query of any one task to be operated fails, and adding the currently monitored protocol identifier of the life cycle protocol corresponding to the life cycle node.
Optionally, the query module includes:
the traversing unit is used for traversing at least one task to be operated for completing the decoupling configuration;
the query unit is used for querying the protocol identifier of the life cycle protocol corresponding to the currently monitored life cycle node in the traversed task to be operated;
and the execution unit is used for skipping the currently traversed task to be operated if the protocol identifier of the life cycle protocol corresponding to the currently monitored life cycle node is successfully inquired.
Optionally, the decoupling module comprises:
the calling unit is used for calling the sharing parameters matched with the life cycle protocol corresponding to the currently monitored life cycle node;
and the configuration unit is used for configuring at least one task parameter of the task to be operated by using the called sharing parameter.
Optionally, the apparatus further comprises:
and the instantiation module is used for instantiating a task dispatcher when the lifecycle node corresponding to the application program to be started is operated, and adding the acquired task to be operated to the task dispatcher.
In another embodiment of the invention, a non-transitory computer readable storage medium is provided, storing instructions that, when executed by a processor, cause the processor to perform the steps of one of the above-described methods of data processing.
In another embodiment of the present invention, a terminal device is provided, which includes a processor configured to execute the steps of a data processing method as described above.
Based on the embodiment, firstly, the lifecycle nodes of the application program are monitored, secondly, in response to the monitored lifecycle nodes, decoupling configuration is executed on at least one task to be executed of the application program according to the lifecycle protocol corresponding to the currently monitored lifecycle nodes, then, in the at least one task to be executed which completes the decoupling configuration, the protocol identifier of the lifecycle protocol corresponding to the currently monitored lifecycle nodes is inquired, and finally, when the inquiry on any task to be executed fails, the application program is triggered to execute the task to be executed which fails to be inquired by using the lifecycle protocol corresponding to the lifecycle nodes, and the protocol identifier of the lifecycle protocol corresponding to the currently monitored lifecycle nodes is added. According to the method and the device, decoupling configuration is carried out on the tasks to be operated, whether the life cycle protocol corresponding to the currently monitored life cycle node runs and finishes the tasks to be operated or not is inquired, so that each task to be operated is executed on the life cycle node to be executed respectively, decoupling among the tasks to be operated is achieved, code logic of an application program starting inlet is reduced, and operation efficiency is improved.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The terms "first," "second," "third," "fourth," and the like in the description and in the claims, and in the drawings described above, if any, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are, for example, capable of operation in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprise" and "have," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements explicitly listed, but may include other steps or elements not explicitly listed or inherent to such process, method, article, or apparatus.
Based on the problems in the prior art, the embodiment of the application provides a data processing method, which is mainly applicable to the technical field of the internet. By adding the executed life cycle protocol in the task array of each task to be operated, the task array of the task to be operated is traversed in the subsequent task distribution, and whether the life cycle protocol is executed for the task to be operated at the current life cycle node is judged according to the traversal result. By the method, the number of the entry codes of the application program is reduced, and decoupling of the tasks to be operated is realized. The technical solution of the present invention is described in detail below with specific embodiments to implement a data processing method. Several of the following embodiments may be combined with each other, and details of the same or similar concepts or processes may not be repeated in some embodiments. Fig. 1 is a schematic flow chart of a data processing method according to an embodiment 100 of the present application. The detailed steps are as follows:
and S11, monitoring the life cycle nodes of the application program.
In this step, in the running process of the application program, the task to be run is generally executed based on the life cycle node. Therefore, to execute each task to be executed, it is usually necessary to monitor the lifecycle node of the application program, so that the task to be executed can implement corresponding code logic in the lifecycle node of the application program according to business needs. Optionally, a listening function and a receiving function may be added to listen to the lifecycle nodes of the application. Through the registration monitoring and the notification of the receiving function receiving system, whether the lifecycle node is monitored currently or not and the specific type of the monitored current lifecycle node are judged.
And S12, responding to the monitored life cycle node, and executing decoupling configuration on at least one task to be run of the application program according to the life cycle protocol corresponding to the currently monitored life cycle node. Wherein, for example, tasks such as upgrade prompt, screen-on advertisement, etc., there is a coupling relation between some tasks to be run.
In this step, in each lifecycle node of the application, in order to implement different service requirements, at least one task to be run may need to be dispatched. The acquired at least one task to be run is generally run at the life cycle node of the application program. Therefore, the lifecycle node of the application program is monitored, and when the lifecycle node is monitored, the task to be run which needs to be executed in the lifecycle node is executed. Optionally, the lifecycle of the application generally includes a plurality of lifecycle nodes, each lifecycle node corresponds to a lifecycle protocol, for example, the lifecycle protocol corresponding to the lifecycle node to be started of the application is willfinishlaunchwithoptions, the lifecycle protocol corresponding to the lifecycle node being started of the application is didfinishlaunchwithoptions, the lifecycle protocol corresponding to the lifecycle node to be added to the background of the application is applicationwillenergfreground, and so on. Further, there may be a coupling relationship between the acquired multiple tasks to be executed in the execution process, and the tasks to be executed generally need to be executed after being packaged in the execution process. And when the life cycle node is monitored, calling a pre-configured shared parameter adaptive to the life cycle protocol corresponding to the currently monitored life cycle node to realize the decoupling configuration of the task to be operated.
And S13, in at least one task to be operated after the decoupling configuration is completed, inquiring the protocol identification of the life cycle protocol corresponding to the currently monitored life cycle node.
In this step, in the task to be executed after the decoupling configuration is completed, the task array of the task to be executed is traversed. The task array of the task to be executed is used for storing the protocol identifier of the lifecycle protocol which is executed and completed by the task to be executed. And when traversing the task array of the running task, inquiring whether a protocol identifier corresponding to the life cycle protocol corresponding to the currently monitored life cycle node exists in the task array.
And S14, when the query of any task to be operated fails, triggering the application program to operate the task to be operated with failed query by using the life cycle protocol corresponding to the life cycle node, and adding the protocol identifier of the life cycle protocol corresponding to the currently monitored life cycle node.
In this step, traversing the task array of the task to be run at the currently monitored life cycle node, querying whether a protocol identifier of the life cycle protocol corresponding to the current life cycle node exists in the task array, implementing the life cycle protocol for the task to be run when the current life cycle protocol is not queried, and recording the protocol identifier of the life cycle protocol in the task array of the task to be run.
As described above, based on the above embodiment, the lifecycle nodes of the application program are monitored first, then, in response to the monitored lifecycle nodes, decoupling configuration is performed on at least one to-be-executed task of the application program according to the lifecycle protocol corresponding to the currently monitored lifecycle nodes, then, in the at least one to-be-executed task that completes the decoupling configuration, the protocol identifier of the lifecycle protocol corresponding to the currently monitored lifecycle nodes is queried, and finally, when query of any to-be-executed task fails, the application program is triggered to execute the to-be-executed task that fails to query by using the lifecycle protocol corresponding to the lifecycle nodes, and the protocol identifier of the lifecycle protocol corresponding to the currently monitored lifecycle nodes is added. According to the method and the device, decoupling configuration is carried out on the tasks to be operated, whether the life cycle protocol corresponding to the currently monitored life cycle node runs and finishes the tasks to be operated or not is inquired, so that each task to be operated is executed on the life cycle node to be executed respectively, decoupling among the tasks to be operated is achieved, code logic of an application program starting inlet is reduced, and operation efficiency is improved.
Fig. 2 is a schematic diagram illustrating a specific flow of a data processing method according to an embodiment 200 of the present application. Wherein, the detailed process of the specific flow is as follows:
s201, at least one task to be operated is obtained.
S202, instantiating the task dispatcher.
Here, in the lifecycle node when the application is about to be started, the task dispatcher is instantiated, and the acquired task to be run is added to the task dispatcher. Optionally, the task dispatcher ljappldeleegate dispatcher is instantiated when the lifecycle node will live with the application program. The task dispatcher is in a singleton mode, that is, only one instance is generally run in the whole lifecycle of the application, and a plurality of instances are not run. And the task dispatcher is used for carrying out centralized management on a plurality of tasks to be operated. Further, the task dispatcher dispatches the task to be operated according to the specific life cycle protocol corresponding to the current life cycle node.
S203, monitoring the life cycle nodes of the application program.
Here, generally, it is possible to call a main function at the time of application startup, call UIApplicationMain through the main function, create a uiapplicationobject by the UIApplicationMain, and execute a loop. Wherein, Uiapplication represents an application program, each application program has a UIapplication global object (singleton), and the object can be obtained through UIapplication shared application, and some application level operations are carried out. Further, the Ulapplication is responsible for listening to received events, and how the application responds to these events (lifecycle events: program start and shut down, system events: incoming calls, note alerts), etc. is determined by the Ulapplication Delegate.
S204, when at least one life cycle node contained in the life cycle is monitored, a life cycle protocol corresponding to the life cycle node is obtained.
Here, when the UIApplication monitors at least one lifecycle node, the UIApplication delete intercepts the lifecycle node and calls an instantiated task dispatcher to dispatch the task to be executed that needs to be executed at the lifecycle node.
S205, according to the life cycle protocol corresponding to the monitored life cycle node, calling the task configuration protocol to configure task parameters for at least one task to be operated.
Here, the tasks to be run can only be run based on the life cycle nodes, and in order to achieve decoupling between the tasks to be run, a protocol agent mode can be set, and some protocols can be declared. For example, a task configuration protocol ljapplicationdelete may be set, and shared parameters used for executing a task to be run, such as a broker number ucid, an application identifier, and a Bundle identifier (Bundle identifier), may be stored in the task configuration protocol. And when the life cycle node is monitored, calling a sharing parameter adaptive to the life cycle protocol corresponding to the currently monitored life cycle node, and configuring at least one task parameter of the task to be operated by using the called sharing parameter. And the difference between the life cycle protocol and the task configuration protocol is smoothed, so that the tasks are conveniently realized, and the decoupling among the tasks to be operated is realized.
S206, inquiring whether the life cycle protocol corresponding to the currently monitored life cycle node exists in the task array.
Here, after the execution of the task to be executed is completed in the monitored lifecycle node, the protocol identifier of the lifecycle protocol that is completed in the execution is recorded in the task array of the current task to be executed. Whether the protocol name of the life cycle protocol corresponding to the currently monitored life cycle node exists or not is inquired in the task array, and whether the task to be operated needs to be executed at the current life cycle node or not is judged.
And S207, when the life cycle protocol is not inquired, executing the life cycle protocol corresponding to the life cycle node for the task to be operated.
In this step, when the query of any one task to be executed fails, the application program is triggered to execute the task to be executed with the failed query by using the life cycle protocol corresponding to the life cycle node, and the protocol identifier of the life cycle protocol corresponding to the currently monitored life cycle node is added. And implementing a life cycle protocol by executing the business tasks to be shipped, and executing each business logic code at the corresponding life cycle node. And when the life cycle node of the application program arrives, calling the service logic of the life cycle node corresponding to the task to be operated, which realizes the life cycle protocol.
And S208, when the life cycle protocol is inquired, skipping the current task to be operated and traversing the task to be operated in the task dispatcher.
And if the protocol identification of the life cycle protocol corresponding to the currently monitored life cycle node is successfully inquired, skipping the currently traversed task to be operated. That is, the lifecycle protocol of the lifecycle node is not implemented, which indicates that the task to be executed has no code logic to be executed in the lifecycle, and skips over and continues to traverse and execute the next task to be executed.
The application realizes the data processing method based on the steps. The task configuration protocol is arranged between the protocol layer of the lifecycle protocol of the application program and the implementation layer of each task to be run, so that decoupling between the tasks to be run is achieved. Further, each task to be run manages the realized task array, and if a life cycle protocol is realized, the protocol identifier of the life cycle protocol is added in the task array. When the subsequent tasks are distributed, if the corresponding life cycle nodes are obtained again, the tasks to be run are traversed, the protocol identifications of the life cycle protocols corresponding to the current life cycle nodes exist in the task array, the class objects are obtained by utilizing the inversion mechanism of the iOS, and then the method for realizing the corresponding tasks to be run of the life cycle protocols is called according to the message forwarding mechanism. According to the method, the adapter mode (the difference between the life cycle protocol and the task configuration protocol is flattened, so that the task is conveniently realized), the simple mode (only one task management and dispatching device is ensured in the whole APP period) and the agent mode are introduced to complete the theme framework of dispatching. And a hook mechanism is introduced, so that the interception of the life cycle nodes and the task dispatching are realized, the code is non-invasive, and an efficient access mode is provided for the use of cross-application programs of some SDKs. And an iOS reflection mechanism, a message forwarding mechanism and other mechanisms are introduced, so that the problem that the framework completes the distribution of tasks while not depending on upper-layer services is solved. The problem of expansibility is solved, the efficiency of cross-department cooperative research and development is improved, the starting tasks are correspondingly added and deleted, the context codes are not influenced, and the readability and the frame usability of the codes are improved.
Based on the same inventive concept, the embodiment 300 of the present application further provides an apparatus for data processing, wherein as shown in fig. 3, the apparatus includes:
the monitoring module 31 is used for monitoring the life cycle nodes of the application program;
the decoupling module 32 is configured to respond to the monitored lifecycle nodes, and execute decoupling configuration on at least one task to be run of the application program according to a lifecycle protocol corresponding to the currently monitored lifecycle node;
the query module 33 is configured to query, in at least one task to be run that completes the decoupling configuration, a protocol identifier of a lifecycle protocol corresponding to a currently monitored lifecycle node;
and the execution module 34 is configured to, when the query on any one task to be executed fails, trigger the application program to execute the task to be executed, which is failed in query, by using the lifecycle protocol corresponding to the lifecycle node, and add the protocol identifier of the lifecycle protocol corresponding to the currently monitored lifecycle node.
In this embodiment, specific functions and interaction modes of the monitoring module 31, the decoupling module 32, the querying module 33, and the executing module 34 may refer to the record of the embodiment corresponding to fig. 1, and are not described herein again.
Optionally, the query module 33 includes:
the traversing unit is used for traversing at least one task to be operated for completing decoupling configuration;
the query unit is used for querying a protocol identifier of a life cycle protocol corresponding to a currently monitored life cycle node in the traversed task to be operated;
and the execution unit is used for skipping the currently traversed task to be run if the protocol identifier of the life cycle protocol corresponding to the currently monitored life cycle node is successfully inquired.
Optionally, the decoupling module 32 comprises:
the calling unit is used for calling the sharing parameters matched with the life cycle protocol corresponding to the currently monitored life cycle node;
and the configuration unit is used for configuring at least one task parameter of the task to be operated by using the called sharing parameter.
Optionally, the apparatus further comprises:
the instantiation module 35 is configured to instantiate a task dispatcher when the lifecycle node corresponding to the application program to be started is run to indicate that the application program is to be started, and add the acquired task to be run to the task dispatcher.
As shown in fig. 4, another embodiment 400 of the present application further provides a terminal device, which includes a processor 401, wherein the processor 401 is configured to execute the steps of the data processing method. As can also be seen from fig. 4, the terminal device provided by the above embodiment further includes a non-transitory computer readable storage medium 402, the non-transitory computer readable storage medium 402 has a computer program stored thereon, and the computer program is executed by the processor 401 to perform the steps of the above-mentioned data processing method. In practice, the terminal device may be one or more computers, as long as the computer-readable medium and the processor are included.
In particular, the storage medium can be a general-purpose storage medium, such as a removable disk, a hard disk, a FLASH, and the like, and when the computer program on the storage medium is executed, the computer program can execute the steps of the data processing method. In practical applications, the computer readable medium may be included in the apparatus/device/system described in the above embodiments, or may exist alone without being assembled into the apparatus/device/system. The computer-readable storage medium carries one or more programs which, when executed, enable performance of the steps of a method of data processing as described above.
According to embodiments disclosed herein, the computer-readable storage medium may be a non-volatile computer-readable storage medium, which may include, for example and without limitation: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing, without limiting the scope of the present disclosure. In the embodiments disclosed herein, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The flowchart and block diagrams in the figures of the present application illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments disclosed herein. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
Those skilled in the art will appreciate that various combinations and/or combinations of features recited in the various embodiments and/or claims of the present disclosure can be made, even if such combinations or combinations are not explicitly recited in the present application. In particular, the features recited in the various embodiments and/or claims of the present application may be combined and/or coupled in various ways, all of which fall within the scope of the present disclosure, without departing from the spirit and teachings of the present application.
Finally, it should be noted that: the above-mentioned embodiments are only specific embodiments of the present application, and are used for illustrating the technical solutions of the present application, but not limiting the same, and the scope of the present application is not limited thereto, and although the present application is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: any person skilled in the art can still change or easily conceive of the technical solutions described in the foregoing embodiments or equivalent replacement of some technical features thereof within the technical scope disclosed in the present application; such changes, variations and substitutions do not depart from the spirit and scope of the exemplary embodiments of the present application and are intended to be covered by the appended claims. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.