Disclosure of Invention
In view of the above, the present invention provides a method, a system, a device, and a storage medium for supporting dynamic management of a timing task, which can implement dynamic management of the timing task during operation through zero configuration, and also can reduce development cost and improve development efficiency, thereby solving the problems that at the present stage, dynamic management such as executing start and stop on a worker and triggering trigger once during the operation of a system cannot be performed, development efficiency is low, and maintenance cost in a later stage is high.
To achieve the above object, according to one aspect of the present invention, there is provided a method of supporting dynamic management of a timing task.
The method of the invention comprises the following steps: obtaining annotations through a reflection mechanism; analyzing the annotation to obtain annotation information; creating unique identifiers of the instances and the setting instances according to the annotation information; the instance and the unique identifier are stored in a corresponding container.
Optionally, the method of the present invention further comprises: the instance ID is encapsulated in the annotation, which is then set as the unique identification of the instance.
Optionally, the instance ID includes a schedule instance ID, a trigger instance ID, and a jobinstance ID, and the schedule instance ID, the trigger instance ID, and the jobinstance ID are set as unique identifiers of the schedule instance, the trigger instance, and the jobinstance, respectively.
Optionally, creating unique identifiers of the instances and the setting instances according to the annotation information includes: creating a jobinstance according to the annotation information, and setting a unique identifier of the jobinstance; creating a trigger instance according to the annotation information and the jobinstance, and setting a unique identifier of the trigger instance; creating a schedule instance according to the annotation information and the trigger instance, and setting a unique identifier of the schedule instance.
Optionally, the method of the present invention further comprises: creating a jobinstance container, a trigger instance container and a schedule instance container; storing the jobinstance and the unique identification of the jobinstance in a jobinstance container; storing the unique identifiers of the trigger instance and the trigger instance in a trigger instance container; and storing the schedule instance and the unique identification of the schedule instance in a schedule instance container.
According to another aspect of the present invention, a system is provided for supporting dynamic management of timed tasks.
The system of the present invention comprises: an acquisition module for acquiring annotations by a reflection mechanism; the analysis module is used for analyzing the annotation to obtain annotation information; the creating module is used for creating an example and setting a unique identifier of the example according to the annotation information; and the storage module is used for storing the examples and the unique identification in corresponding containers.
Optionally, the system of the present invention further includes an encapsulation module, configured to encapsulate the instance ID in the annotation, and the creation module sets the instance ID as a unique identifier of the instance.
Optionally, the instance ID includes a schedule instance ID, a trigger instance ID, and a jobinstance ID, and the creation module sets the schedule instance ID, the trigger instance ID, and the jobinstance ID as unique identifiers of the schedule instance, the trigger instance, and the jobinstance, respectively.
Optionally, the creating module includes: a job instance creating unit, configured to create a job instance according to the annotation information, and set a unique identifier of the job instance; creating a trigger instance unit, creating a trigger instance according to the annotation information and the jobinstance, and setting a unique identifier of the trigger instance; and the creating schedule instance unit is used for creating a schedule instance according to the annotation information and the trigger instance and setting a unique identifier of the schedule instance.
Optionally, the creating module is further configured to create a jobinstance container, a trigger instance container, and a schedule instance container;
the storage module stores the jobinstance and the unique identification of the jobinstance in a jobinstance container; storing the unique identifiers of the trigger instance and the trigger instance in a trigger instance container; and storing the schedule instance and the unique identification of the schedule instance in a schedule instance container.
According to another aspect of the present invention, an electronic device supporting dynamic management of timed tasks is provided.
The electronic device of the present invention includes one or more processors; a storage device for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to implement any of the above-described methods of supporting dynamically managed timed tasks.
According to another aspect of the present invention, there is provided a computer readable medium having stored thereon a computer program, characterized in that said program, when executed by a processor, implements any of the above-described methods of supporting dynamically managed timed tasks.
The non-transitory computer readable storage medium of the present invention stores computer instructions for causing the computer to perform any one of the above-described methods of supporting dynamically managed timed tasks.
According to the technical scheme of the invention, annotation information is obtained by analyzing the annotation in the runtime, and the unique identifier of the instance is set when the instance is created according to the annotation information, and the instance and the unique identifier are stored in the corresponding container. Furthermore, in the system operation process, when one operation needs to be executed on the schedule, the stop and the Trigger, the specific dynamic management operation can be executed on the schedule instance, the Trigger instance and the Job instance by respectively inquiring the unique identifier of the schedule instance, the unique identifier of the Trigger instance and the unique identifier of the Job instance in the schedule container, the Trigger container and the Job container, namely, the dynamic management of the timing task during the operation is supported.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Fig. 1 is a schematic diagram of the main steps of a method for supporting dynamic management of timed tasks according to an embodiment of the present invention. As shown in fig. 1, a method for supporting dynamic management of a timing task according to an embodiment of the present invention includes the following main steps:
s11: the annotation is obtained by a reflection mechanism.
Each worker must have a schedule class, Trigger class and Job class, wherein the schedule class is responsible for performing start and stop management operations on the worker, the Trigger triggers corresponding actions according to a set Trigger time expression, and only the Job class executes specific service logic. Based on the principle of focus separation, both the schedule instance and trigger instance can be created through reflection, and developers only need to develop logic related to services.
In the process of writing the annotation, the instance ID is packaged in the annotation, and then the instance ID can be set as the unique identifier of the instance after the instance is created, and certainly, other identifiers such as a name and the like can also be set as the unique identifier. Moreover, an annotation parameter auto start parameter value can be set, the annotation parameter auto start value is set to false or true, and whether a timing task automatically started exists or not is determined according to the annotation parameter auto start parameter value. The instance ID comprises a schedule instance ID, a trigger instance ID and a jobinstance ID, and the schedule instance ID, the trigger instance ID and the jobinstance ID are set as unique identifications of the schedule instance, the trigger instance and the jobinstance respectively. For example, attributes such as trigger execution time expression, schedule instance ID, trigger instance ID, Job instance ID and the like required by the trigger instance are all packaged through a comment type Worker schedule, and when a developer uses the method, the developer only needs to set the comment Worker schedule on a Job type of business logic and set corresponding parameters. The class attributes of an annotation class are as follows:
s12: and analyzing the annotation to obtain annotation information.
S13: unique identifications of the instances and the set instances are created from the annotation information. Creating unique identifiers for instances and setting instances from annotation information includes: creating a jobinstance according to the annotation information, and setting a unique identifier of the jobinstance; creating a trigger instance according to the annotation information and the jobinstance, and setting a unique identifier of the trigger instance; and creating a schedule instance according to the annotation information and the trigger instance, and setting a unique identifier of the schedule instance.
S14: the instance and the unique identifier are stored in a corresponding container. Creating a jobinstance container, a trigger instance container and a schedule instance container; storing the jobinstance and the unique identification of the jobinstance in a jobinstance container; storing the trigger instance and the unique identifier of the trigger instance in a trigger instance container; and storing the schedule instance and the unique identification of the schedule instance in a schedule instance container.
Fig. 2 is a schematic diagram of creating a jobinstance according to an embodiment of the present invention. As shown in FIG. 2, when the system initializes the class, the annotation information set on the class is obtained through the reflection mechanism of Java, and if the annotation is set and the type of the annotation is WorkerScheduled, the type is a Job class. And then analyzing the annotation information to obtain a jobInstanceId value set in the annotation parameter. Creating an instance of the Job, setting a unique identification of the Job instance, namely setting an instance ID as a Job instanceId value in the annotation parameter, and storing the instance ID into a Job instance container in the form of a key-value pair, wherein key is the Job instanceId value (unique identification Job instance ID), and value is the Job instance.
Fig. 3 is a schematic diagram of creating a trigger instance according to an embodiment of the present invention. the trigger instance has the function of regularly triggering execution of the jobinstance, and triggering the execution time expression is set through the comment class WorkerScheduled attribute and is irrelevant to specific service implementation. As shown in fig. 3, when the system initializes the class, the annotation class information set on the Job class is parsed by the Java reflection mechanism, and the values of the annotation retrieval attributes cronExpression, triggerInstanceId, and jobInstanceId are parsed. And creating a trigger instance based on a Java reflection mechanism, wherein the trigger execution time expression of the instance is an annotation attribute cronExpression value, and the instance ID is an annotation attribute triggerInstanceId value. And taking the Job instance from the Job container through the Job instanceId value, and setting the Job instance to the Job attribute parameter of the trigger instance. Up to this point, the creation of the trigger instance is completed, and the trigger instance is stored in the trigger instance container in the form of a key-value key value pair, wherein the key is a trigger instanceid value (uniquely identifying the trigger instance ID), and the value is the trigger instance.
FIG. 4 is a diagram illustrating an example of creating a schedule according to an embodiment of the present invention. The role of the schedule instance is to manage the start and stop operations of the worker, and is irrelevant to the logic implementation of specific services. The schedule instance is created by reflection, again based on the point of interest separation principle. As shown in fig. 4, when the system initializes the class, the annotation information on the Job class is acquired through a Java reflection mechanism, and the annotation attributes scheduleinsatceid and triggerInstanceId are parsed. And taking out the corresponding Trigger instance from the Trigger container according to the Trigger instanceid, and setting the Trigger instance to the schedule instance. And after the creation is completed, saving the key-value key value into the schedule container.
Through the steps, the schedule instance, the trigger instance and the jobinstance are created and stored in the respective containers, and the instance IDs and the trigger execution time expression parameters of the schedule instance, the trigger instance and the jobinstance are set through the annotation attribute so as to be analyzed at runtime, and further unique identifications of the corresponding instance and the set instance are created. When a worker manager needs to dynamically manage the worker during running, unique schedule instances, trigger instances and job instances can be taken out from corresponding containers according to the attribute schedule entry Id, trigger instance Id and job instance Id values when a user sets annotations, and then messages are sent to the instances, so that dynamic management can be performed during running of the system.
Fig. 5 is a schematic diagram of the main modules of a system supporting dynamic management of timed tasks according to an embodiment of the present invention. As shown in fig. 5, a system for supporting dynamic management of a timing task according to an embodiment of the present invention includes: the system comprises an acquisition module, an analysis module, a creation module and a storage module, wherein the acquisition module is used for acquiring the annotation through a reflection mechanism, the analysis module is used for analyzing the annotation to acquire annotation information, the creation module is used for creating an example and setting a unique identifier of the example according to the annotation information, and the storage module is used for storing the example and the unique identifier in a corresponding container. The creating module comprises: a job instance creating unit used for creating a job instance according to the annotation information and setting a unique identifier of the job instance; creating a trigger instance unit, creating a trigger instance according to the annotation information and the jobinstance, and setting a unique identifier of the trigger instance; and the creating schedule instance unit is used for creating a schedule instance according to the annotation information and the trigger instance and setting the unique identifier of the schedule instance. The creating module is also used for creating a jobinstance container, a trigger instance container and a schedule instance container; the storage module stores the jobinstance and the unique identifier of the jobinstance in a jobinstance container; storing the trigger instance and the unique identifier of the trigger instance in a trigger instance container; and storing the schedule instance and the unique identification of the schedule instance in a schedule instance container.
The system supporting dynamic management of the timing task further comprises a packaging module, wherein the packaging module is used for packaging the instance ID into the annotation, and then the creating module sets the instance ID as the unique identifier of the instance. The instance ID comprises a schedule instance ID, a trigger instance ID and a jobinstance ID, and the creation module respectively sets the schedule instance ID, the trigger instance ID and the jobinstance ID as unique identifications of the schedule instance, the trigger instance and the jobinstance. The system supporting dynamic management of the timing task, provided by the embodiment of the invention, can also set an annotation parameter auto start parameter value, set the annotation parameter auto start parameter value as false or true, and determine whether the automatically started timing task exists according to the annotation parameter auto start parameter value.
The system for supporting dynamic management of the timing task sets parameters such as schedule instance ID, trigger instance ID, jobinstance ID and jobexecution time expression to attribute parameters of annotations, automatically creates the schedule instance, trigger instance and jobinstance by reflection when the system initializes the class, stores the schedule instance, trigger instance and jobinstance in corresponding containers, and replaces the configuration through configuration files. The schedule instance ID uniquely identifies a schedule instance in the schedule container. Similarly, the trigger instance ID uniquely identifies one trigger instance in the trigger instance container, and the jobinstance ID uniquely identifies one jobinstance in the jobinstance container. In the operation process of the system, when one operation of starting and stop on the schedule and trigger on the trigger needs to be executed, the specific schedule instance, trigger instance and jobinstance can be inquired in the schedule instance container, trigger instance container and jobinstance container through the schedule instance ID, trigger instance ID and jobinstance ID, and the corresponding dynamic management operation is executed. Thus, development efficiency is improved, development cost is reduced, and maintainability of the system is improved.
FIG. 6 is a schematic diagram of an electronic device supporting dynamic management of timed tasks according to an embodiment of the present invention. As shown in fig. 6, anapparatus 6 for supporting dynamic management of timing tasks according to an embodiment of the present invention includes amemory 61 and at least oneprocessor 62, where thememory 61 is connected to the at least oneprocessor 62 via a bus, and thememory 61 stores instructions executable by the at least one processor, and when the apparatus of the present embodiment is operated, the instructions are executed by the at least one processor, so that the at least one processor can execute the method flows shown in fig. 1 to 4.
Fig. 7 is a schematic diagram of a hardware structure of an electronic device supporting dynamic management of timed tasks according to an embodiment of the present invention. As shown in fig. 7 (taking a processor as an example), the electronic apparatus of the present embodiment further includes aninput device 73 and anoutput device 74. Thememory 71, theprocessor 72, theinput device 73 and theoutput device 74 may be connected by a bus or other means, and fig. 7 illustrates the connection by a bus as an example. Thememory 71 is a non-transitory computer readable storage medium, and can be used for storing non-transitory software programs, non-transitory computer executable programs, and modules, such as program instructions/modules corresponding to the method for supporting dynamic management timing task in the embodiment of the present application (for example, the acquiring module, the parsing module, the creating module, and the storing module shown in fig. 5). Theprocessor 72 executes various functional applications of the server and data processing by running non-transitory software programs, instructions and modules stored in thememory 71, that is, implements the processing method supporting the dynamic management timing task in the above method embodiment.
Thememory 71 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created from use of the electronic device supporting the dynamic management timing task, and the like. Further, thememory 71 may include high speed random access memory, and may also include non-transitory memory, such as at least one magnetic disk storage device, flash memory device, or other non-transitory solid state storage device. In some embodiments, thememory 71 optionally includes memory remotely located from theprocessor 72, and these remote memories may be connected over a network to an electronic device that supports dynamically managing timing tasks. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
Theinput device 73 may receive input numeric or character information and generate key signal inputs related to user settings and function control of the electronic apparatus supporting the dynamic management of the timing task. Theoutput device 74 may include a display device such as a display screen.
One or more modules are stored in thememory 71 and, when executed by the one ormore processors 72, perform the processing method of any of the above-described method embodiments that supports dynamically managing timed tasks.
The product can execute the method provided by the embodiment of the application, and has the corresponding functional modules and beneficial effects of the execution method. For technical details that are not described in detail in this embodiment, reference may be made to the methods provided in the embodiments of the present application.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a non-transitory computer-readable storage medium, and can include the processes of the embodiments of the methods described above when the computer program is executed. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), or the like.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.