Configuration updating method and device based on Groupy just-in-time compiling drive, medium and equipment

Through the configuration update method driven by Groovy just-in-time compilation, Groovy ClassLoader and Spring container are used to manage Bean objects, which solves the security and response speed issues of Java dynamic execution code publishing changes in the production environment, achieving fast response and efficient configuration updates, and improving Improve code maintainability and system security.

CN118585239APending Publication Date: 2024-09-03天创信用服务有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410827924.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-25
Publication Date
2024-09-03

AI Technical Summary

Technical Problem

It is difficult for existing Java dynamic code execution solutions to safely and quickly release changes to data product requirements and functions in a production environment. Especially in the case of frequent updates, there are security risks and insufficient response speed.

Method used

It adopts a configuration update method based on Groovy just-in-time compilation driver, dynamically compiles Groovy source code through GroovyClassLoader, uses Spring container to manage Bean objects, and combines double verification lock mode matching with target Bean objects to realize the execution of developers' dynamic configuration code blocks to ensure security and Efficiency.

Benefits of technology

It achieves rapid response to changing requirements without modifying the core service code, reduces hard-coded dependencies, improves code maintainability and reusability, ensures system security and high performance, supports dynamic execution in multiple languages, and provides flexibility Configuration update plan.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118585239A
    Figure CN118585239A
Patent Text Reader

Abstract

The invention provides a configuration updating method and device based on a Grouping just-in-time compiling driver, a medium and equipment, and the method comprises the steps: creating a manufacturer interface, executing corresponding parameter configuration, and generating a corresponding version number; when a preset condition for dynamically executing the task is triggered, dynamically compiling the Groovy source code by utilizing a GroovyClassLoader, so as to obtain a compiled Class object; a Bean object is created based on the Class object, and Bean management based on the version number is carried out through a Spring container; and executing a core logic program of the code block dynamically configured by the developer based on the target Bean object, and finishing final calling. According to the method and the device, a Java ScriptEngine framework is introduced, and under the condition that a core service code is not modified, a developer can be allowed to dynamically configure execution logic of a code block according to actual requirements, quickly respond to change requirements, dynamically execute script logic, reduce hard coding dependence and improve maintainability and reusability of the code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of dynamic compilation technology, and in particular to a configuration update method, device, medium and equipment based on Groovy just-in-time compilation drive. Background Art

[0002] With the rapid iteration of data product functions and the growing demand, the current release process has been unable to cope with frequent change requirements, especially when the production environment needs to be updated multiple times a day. Therefore, a flexible and efficient dynamic release solution is urgently needed to ensure that production changes of data product demand functions can be released to the production environment at any time and quickly, improving response speed and system stability.

[0003] At present, the existing Java dynamic execution code solutions include the following two: 1. Using JEXL dynamic expressions: Java Expression Language (JEXL) is an expression language engine that can be used in applications or frameworks. Advantages: Can dynamically execute Java code and call Java Function; Disadvantages: Can only execute an "expression" instead of a Function, so there are many grammatical limitations, and it is not a true execution of a Function. 2. Java dynamic compilation: Advantages: Powerful, can truly realize complete dynamic execution functions, can dynamically call all system functions and IO operations; Disadvantages: Although powerful, it is still difficult to replace framework-level class files at runtime, and it is not isolated from the general code environment, which will become a very serious security risk in the project. Summary of the invention

[0004] To this end, the present invention provides a configuration update method and device, medium, and equipment based on Groovy real-time compilation drive, aiming to solve the technical problem in the prior art that production changes of data product demand functions cannot be safely, anytime, and quickly released to the production environment.

[0005] To achieve the above objectives, the present invention adopts the following technical solutions:

[0006] According to a first aspect of the present invention, the present invention provides a configuration update method based on Groovy just-in-time compilation driver, the method comprising:

[0007] Create a manufacturer interface and execute corresponding parameter configuration to generate the corresponding version number;

[0008] When the preset conditions of the dynamic execution task are triggered, the Groovy source code is dynamically compiled using GroovyClassLoader to obtain the compiled Class object;

[0009] Create a Bean object based on the Class object, and manage the Bean based on the version number through the Spring container;

[0010] Execute the core logic program of the code block dynamically configured by the developer based on the target Bean object and complete the final call.

[0011] Optionally, the version number-based Bean management through the Spring container includes:

[0012] Associating the Bean object with the version number, and using the associated version number as the latest version number;

[0013] When the configuration is started, check whether the local version number previously maintained by the system is consistent with the latest version number;

[0014] If the local version number does not exist or is inconsistent with the latest version number, the Bean object of the historical version is cancelled, a new Bean instance is created according to the configuration of the latest version number, and dependency injection is performed.

[0015] Optionally, before executing the core logic program of the code block dynamically configured by the developer based on the Bean object, the method further includes:

[0016] Obtain a data source identifier; the data source identifier includes a manufacturer ID and a latest version number;

[0017] When the core link is called, based on the data source identifier, a double-check lock mode is used to match the required target Bean object.

[0018] Optionally, the step of matching the required target Bean object using a double check lock mode based on the data source identifier includes:

[0019] Based on the data source identifier, first check whether the target Bean object exists;

[0020] If the target Bean object does not exist, add a local lock to the data source identifier to ensure that a single thread enters the code block for creating the Bean;

[0021] Check again whether the target Bean object exists. If the target Bean object still does not exist, perform the Bean object creation operation.

[0022] Optionally, the preset conditions for triggering the dynamic execution of the task include:

[0023] Initial loading when the service starts; or, loading during operation after the Java version is changed.

[0024] Optionally, the method of dynamically compiling the Groovy source code using GroovyClassLoader to obtain the compiled Class object includes:

[0025] Dynamically compile Groovy source code through the parseClass method and load the generated class;

[0026] Returns the Class object of the compiled class.

[0027] Optionally, the execution of corresponding parameter configuration includes defining at least one of basic information, input parameters, request headers, processing classes and methods, and encoding implementation configuration.

[0028] According to a second aspect of the present invention, the present invention provides a configuration update device based on Groovy just-in-time compilation driver, the device comprising:

[0029] The parameter configuration module is used to create the manufacturer interface and perform the corresponding parameter configuration and generate the corresponding version number;

[0030] The dynamic compilation module is used to dynamically compile the Groovy source code using the GroovyClass Loader to obtain the compiled Class object when the preset conditions of the dynamic execution task are triggered;

[0031] An object management module, used to create a Bean object based on the Class object, and perform Bean management based on the version number through a Spring container;

[0032] The logic call module is used to execute the core logic program of the code block dynamically configured by the developer based on the target Bean object and complete the final call.

[0033] According to a third aspect of the present invention, the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor executes the configuration update method based on Groovy just-in-time compilation drive as described in any one of the first aspect of the present invention.

[0034] According to a fourth aspect of the present invention, the present invention provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the configuration update method based on Groovy just-in-time compilation driver as described in any one of the first aspect of the present invention is implemented.

[0035] Through the scheme of the present invention, a manufacturer interface is created and corresponding parameter configuration is performed to generate a corresponding version number; when the preset conditions of the dynamic execution task are triggered, the Groovy source code is dynamically compiled using GroovyClassLoader to obtain the compiled Class object; a Bean object is created based on the Class object, and Bean management based on the version number is performed through the Spring container; the core logic program of the code block dynamically configured by the developer is executed based on the target Bean object, and the final call is completed. Therefore, by introducing the Java ScriptEngine framework, the present invention can dynamically execute script logic without modifying the core service code, quickly respond to change requirements, reduce hard-coded dependencies, and improve the maintainability and reusability of the code.

[0036] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0038] Figure 1 A schematic diagram of a process flow of a configuration update method based on Groovy just-in-time compilation driver provided by an embodiment of the present invention is shown;

[0039] Figure 2 A schematic diagram of a process flow of a configuration update method based on Groovy just-in-time compilation driver provided by another embodiment of the present invention is shown;

[0040] Figure 3 A schematic diagram of the structure of a configuration update device based on Groovy just-in-time compilation driver provided in one embodiment of the present invention is shown;

[0041] Figure 4 A schematic diagram of a configuration update based on Groovy just-in-time compilation driver provided in another embodiment of the present invention is shown;

[0042] Figure 5 A schematic diagram of the physical structure of a computer device provided by an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0043] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.

[0044] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0045] The embodiment of the present invention provides a configuration update method based on Groovy instant compilation driver, such as Figure 1 As shown, at least the following steps S101 to S104 may be included:

[0046] Step S101, create a manufacturer interface and execute corresponding parameter configuration to generate a corresponding version number.

[0047] First, the embodiment of the present invention creates a manufacturer interface and performs corresponding parameter configuration. The parameter configuration may include defining basic information, input parameters, request headers, processing classes and methods, and coding implementation configuration. Specifically, the basic information includes the data manufacturer name, interface name, purchasing manager, interface category, data classification, interface timeout, and function description; the request header includes HTTP request headers such as GET and POST; the processing class and method name definition: for example, DUBBO service provider; coding implementation configuration: specific executable Java code class configuration.

[0048] It should be noted that, in the embodiment of the present invention, after the manufacturer interface is created, the version number is automatically generated; after the corresponding parameter configuration is updated, the version number is synchronously updated.

[0049] Step S102, when the preset condition of the dynamic execution task is triggered, the Groovy source code is dynamically compiled using GroovyClassLoader to obtain a compiled Class object.

[0050] In the embodiment of the present invention, the triggering scenario of dynamic compilation may be: initialization loading when the service is started or loading during operation after the Java version is changed.

[0051] When performing dynamic compilation, first obtain the latest executable Groovy source code, complete the code package path information, and use GroovyClassLoader to dynamically compile the Groovy source code. Specifically, the parseClass method can be used to dynamically compile the Groovy source code, load the generated class, and return a Class object of the compiled class. At this time, GroovyClassLoader loads the Class information.

[0052] Step S103, creating a Bean object based on the Class object, and performing Bean management based on the version number through the Spring container.

[0053] Create a Bean based on the Class object generated in step S102. In the embodiment of the present invention, the Spring container is used to manage beans with multiple versions, such as Figure 2 As shown. Specifically, the Bean object can be associated with the version number generated in step S101, and the associated version number can be used as the latest version number. It should be noted that, generally, the system maintains a local version number (local cache) and the latest version number (redis). When the configuration is started or required, check whether the local version number previously maintained by the system is consistent with the latest version number; if the local version number does not exist or is inconsistent with the latest version number, the historical version of the Bean object is automatically deregistered, and a new Bean instance is created according to the configuration of the latest version number, and dependency injection is performed. In this way, the Spring container update layout management Map is implemented.

[0054] Step S104, executing the core logic program of the code block dynamically configured by the developer based on the target Bean object, and completing the final call.

[0055] The target Bean object in the embodiment of the present invention refers to the Bean object required when the core link is called. In order to accurately match the required target Bean object, before executing the core logic program, the data source identifier can be obtained first; based on the data source identifier, the double check lock mode is used to match the required target Bean object.

[0056] In order to ensure the unique identification of the target Bean object, the data source identification can be set to the manufacturer ID + the latest version number. Furthermore, in order to avoid repeated creation of Bean objects, the embodiment of the present invention can adopt a double-check lock mode to ensure the singleton and thread safety of the Bean. Figure 2As shown, a double-check lock mode is used to match the required target Bean object, which may specifically include: based on the data source identifier, first checking whether the target Bean object exists; if the target Bean object does not exist, adding a local lock for the data source identifier to ensure that a single thread enters the code block for creating the Bean; secondly checking whether the target Bean object exists, if the target Bean object still does not exist, executing the Bean object creation operation.

[0057] It should be noted that the creation operation of the Bean object can refer to the corresponding description in step S103. After the creation operation of the Bean object is completed, the result can be cached for subsequent use. Thus, the uniqueness of the Bean object is guaranteed and the performance of concurrent access is improved.

[0058] After matching the target Bean object, the core logic of the dynamic code block is executed based on the target Bean object to implement a configurable code block mechanism. In other words, it allows developers to dynamically configure the execution logic of the code block according to actual needs, ensuring that the dynamic code block executes its core logic smoothly and completes the final call correctly.

[0059] The embodiment of the present invention provides a configuration update method based on Groovy instant compilation drive, including creating a manufacturer interface and executing corresponding parameter configuration to generate a corresponding version number; when the preset condition of the dynamic execution task is triggered, the Groovy source code is dynamically compiled using GroovyClassLoader to obtain the compiled Class object; based on the Class object, a Bean object is created, and the Bean management based on the version number is performed through the Spring container; based on the target Bean object, the core logic program of the code block dynamically configured by the developer is executed, and the final call is completed. Through the present invention, the Java ScriptEngine framework is introduced, which can allow developers to dynamically configure the execution logic of the code block according to actual needs without modifying the core service code, quickly respond to change requirements, dynamically execute script logic, reduce hard-coded dependencies, and improve the maintainability and reusability of the code.

[0060] In addition, the present invention also has beneficial effects in the following aspects:

[0061] 1. Dynamic execution: The present invention can directly execute the complete JavaScript (JS) solution and obtain the return value, thereby quickly responding to changes in business needs.

[0062] 2. Security: The present invention can execute scripts in a virtual context, strictly restricting access to system operations and IO operations, thereby ensuring the security of the system.

[0063] 3. High efficiency: The present invention supports multiple optimization methods, such as pre-compilation. The compiled scripts can be reused, and the execution efficiency is close to that of native Java code, thus ensuring the high performance of the system.

[0064] 4. Flexibility: The configuration update distribution provided by the present invention is not limited to JavaScript. All languages ​​that implement the ScriptEngine interface (such as Groovy, Ruby, etc.) can be dynamically executed, providing developers with more choices and flexibility.

[0065] 5. Configurable and parameterized design: By decoupling business logic from configuration and parameters, the present invention can easily modify and adjust functions without frequent code modifications and re-releases.

[0066] 6. Version management: The present invention incorporates version management, allowing developers to easily track and manage script versions, ensuring that each change is clearly recorded and can be easily rolled back to the previous version.

[0067] 7. Core service release: Since the business logic of the present invention is extracted into the script for execution, the code changes of the core service will be greatly reduced, thereby reducing the frequency and risk of release.

[0068] Further, as Figure 1 The specific implementation of the present invention provides a configuration update device based on Groovy instant compilation driver, such as Figure 3 As shown, the apparatus may include: a parameter configuration module 310 , a dynamic compilation module 320 , an object management module 330 and a logic calling module 340 .

[0069] The parameter configuration module 310 can be used to create a manufacturer interface and perform corresponding parameter configuration and generate a corresponding version number;

[0070] The dynamic compilation module 320 can be used to dynamically compile the Groovy source code using GroovyClassLoader to obtain the compiled Class object when the preset conditions of the dynamic execution task are triggered;

[0071] The object management module 330 can be used to create Bean objects based on Class objects and perform Bean management based on version numbers through the Spring container;

[0072] The logic calling module 340 can be used to execute the core logic program of the code block dynamically configured by the developer based on the target Bean object and complete the final call.

[0073] Alternatively, if Figure 4As shown, another embodiment of the present invention provides a configuration update device based on Groovy just-in-time compilation driver, which also includes: an object matching module 350.

[0074] The object matching module 350 can be used to obtain the data source identifier before executing the core logic program of the code block dynamically configured by the developer based on the Bean object; the data source identifier includes the manufacturer ID and the latest version number; when the core link is called, based on the data source identifier, a double check lock mode is used to match the required target Bean object.

[0075] Optionally, the parameter configuration module 310 may also be used to define at least one of basic information, input parameters, request headers, processing classes and methods, and encoding implementation configurations.

[0076] Optionally, the dynamic compilation module 320 can also be used for initialization loading when the service is started; or, when loading during operation after the Java version is changed, dynamically compile the Groovy source code through the parseClass method and load the generated class; return the Class object of the compiled class.

[0077] Optionally, the object management module 330 can also be used to associate the Bean object with the version number, and use the associated version number as the latest version number; when the configuration is started, check whether the local version number previously maintained by the system is consistent with the latest version number; if the local version number does not exist or is inconsistent with the latest version number, cancel the historical version of the Bean object, create a new Bean instance according to the configuration of the latest version number, and perform dependency injection.

[0078] Optionally, the object matching module 350 can also be used to first check whether the target Bean object exists based on the data source identifier; if the target Bean object does not exist, add a local lock for the data source identifier to ensure that a single thread enters the code block for creating the Bean; and secondly check whether the target Bean object exists. If the target Bean object still does not exist, execute the Bean object creation operation.

[0079] It should be noted that for other corresponding descriptions of the functional modules involved in the configuration update device based on Groovy instant compilation driver provided in the embodiment of the present invention, please refer to Figure 1 The corresponding description of the method shown will not be repeated here.

[0080] Based on the above Figure 1 The method shown, accordingly, an embodiment of the present invention also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the configuration update method based on Groovy just-in-time compilation drive described in any of the above embodiments are implemented.

[0081] Based on the above Figure 1 The method shown and Figure 4 The embodiment of the device shown in the figure, the embodiment of the present invention also provides a physical structure diagram of a computer device, such as Figure 5 As shown, the computer device may include a communication bus, a processor, a memory and a communication interface, and may also include an input / output interface and a display device, wherein each functional unit may communicate with each other through the bus. The memory stores a computer program, and the processor is used to execute the program stored in the memory and execute the steps of the configuration update method based on Groovy instant compilation drive described in the above embodiment.

[0082] Those skilled in the art can clearly understand that the specific working processes of the systems, devices, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and for the sake of brevity, they are not further described here.

[0083] In addition, the functional units in various embodiments of the present invention may be physically independent of each other, or two or more functional units may be integrated together, or all functional units may be integrated into one processing unit. The above integrated functional units may be implemented in the form of hardware, or in the form of software or firmware.

[0084] Those skilled in the art can understand that if the integrated functional unit is implemented in the form of software and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention can essentially or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, which includes a number of instructions to enable a computing device (such as a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present invention when running the instructions. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), magnetic disk or optical disk and other media that can store program codes.

[0085] Alternatively, all or part of the steps of implementing the aforementioned method embodiments may be accomplished by hardware associated with program instructions (such as a computing device such as a personal computer, a server, or a network device), and the program instructions may be stored in a computer-readable storage medium. When the program instructions are executed by a processor of a computing device, the computing device executes all or part of the steps of the methods described in the embodiments of the present invention.

[0086] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that within the spirit and principles of the present invention, the technical solutions described in the aforementioned embodiments can still be modified, or some or all of the technical features therein can be replaced by equivalents. However, these modifications or replacements do not deviate from the protection scope of the present invention.

Claims

1. A configuration update method based on Groovy instant compilation driver, characterized in that: The method comprises: Create a manufacturer interface and execute corresponding parameter configuration to generate the corresponding version number; When the preset conditions of the dynamic execution task are triggered, the Groovy source code is dynamically compiled using GroovyClassLoader to obtain the compiled Class object; Create a Bean object based on the Class object, and manage the Bean based on the version number through the Spring container; Execute the core logic program of the code block dynamically configured by the developer based on the target Bean object and complete the final call.

2. The method according to claim 1, characterized in that The Bean management based on version number through Spring container includes: Associating the Bean object with the version number, and using the associated version number as the latest version number; When the configuration is started, check whether the local version number previously maintained by the system is consistent with the latest version number; If the local version number does not exist or is inconsistent with the latest version number, the Bean object of the historical version is cancelled, a new Bean instance is created according to the configuration of the latest version number, and dependency injection is performed.

3. The method according to claim 2, characterized in that Before executing the core logic program of the code block dynamically configured by the developer based on the Bean object, the method further includes: Obtain a data source identifier; the data source identifier includes a manufacturer ID and a latest version number; When the core link is called, based on the data source identifier, a double-check lock mode is used to match the required target Bean object.

4. The method according to claim 3, characterized in that The method of matching the required target Bean object using a double check lock mode based on the data source identifier includes: Based on the data source identifier, first check whether the target Bean object exists; If the target Bean object does not exist, add a local lock to the data source identifier to ensure that a single thread enters the code block for creating the Bean; Check again whether the target Bean object exists. If the target Bean object still does not exist, perform the Bean object creation operation.

5. The method according to claim 1, characterized in that The preset conditions for triggering the dynamic execution of tasks include: Initial loading when the service starts; or, loading during operation after the Java version is changed.

6. The method according to claim 1, characterized in that The Groovy source code is dynamically compiled using GroovyClassLoader to obtain the compiled Class object, including: Dynamically compile Groovy source code through the parseClass method and load the generated class; Returns the Class object of the compiled class.

7. The method according to any one of claims 1 to 6, characterized in that: The execution corresponding parameter configuration includes defining at least one of basic information, input parameters, request headers, processing classes and methods, and encoding implementation configuration.

8. A configuration update device based on Groovy instant compilation driver, characterized in that: The device comprises: The parameter configuration module is used to create the manufacturer interface and perform the corresponding parameter configuration and generate the corresponding version number; The dynamic compilation module is used to dynamically compile the Groovy source code using the GroovyClass Loader to obtain the compiled Class object when the preset conditions of the dynamic execution task are triggered; An object management module, used to create a Bean object based on the Class object, and perform Bean management based on the version number through a Spring container; The logic call module is used to execute the core logic program of the code block dynamically configured by the developer based on the target Bean object and complete the final call.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor executes the configuration update method based on Groovy just-in-time compilation drive according to any one of claims 1 to 7.

10. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the configuration update method based on Groovy just-in-time compilation drive according to any one of claims 1 to 7 is implemented.