A method and system for implementing hot update dynamic adaptation based on JavaSPI

Implementing dynamic adaptation for hot updates through JavaSPI solves the complex issues of on-site debugging and communication for manufacturers in customized development, enables customers to develop and hot update on their own, and improves development efficiency and dynamic processing capabilities.

CN114880169BActive Publication Date: 2025-09-26杭州比智科技有限公司
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202210648631.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-09
Publication Date
2025-09-26
Estimated Expiration
2042-06-09

AI Technical Summary

Technical Problem

In customized development, when partial modifications or docking of new modules are required after delivery, existing technologies require on-site debugging and communication with manufacturers, resulting in high costs and complex communication problems.

Method used

JavaSPI is used to implement the hot update dynamic adaptation method. By planning standardized interfaces and interface annotations, customers can complete development on their own without understanding the business logic. JavaSPI is used to rewrite the ClassLoader and SPI mechanism, dynamically load the functional module implementation class, and realize hot update and dynamic adaptation.

Benefits of technology

It reduces the manufacturer's on-site debugging and communication costs, improves development efficiency, supports online debugging and hot update repairs, enriches the program's dynamic processing capabilities, and reduces the difficulty of later expansion and transformation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114880169B_ABST
    Figure CN114880169B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and system for implementing dynamic adaptation of hot updates based on Java SPI. The method comprises the following steps: Step S110, planning and designing the required functions and generating a standardized interface; Step S120, implementing the target interface according to the required functions and uploading it to the server; Step S130, determining whether an implementation class is available when the server is started; if so, proceeding to Step S140, rewriting Java SPI and ClassLoader to dynamically load the target implementation class. This method and system can solve the problem of custom development scenarios, helping clients to add and improve functions by reading the manufacturer's instructions without having to understand the entire business logic.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer and data processing technology, and in particular to a method and system for implementing hot update dynamic adaptation based on JavaSPI. Background Art

[0002] Custom development is an inevitable issue for products targeting multiple customers, especially after delivery, when partial modifications or integration with new modules are necessary. However, since software is typically delivered as obfuscated packages, without source code, iterating on the required content often requires contacting the software vendor for customized development. The vendor, in turn, needs to understand the customer's scenario, and customized development may require on-site debugging and development, which invisibly increases communication and development costs.

[0003] Due to delivery restrictions or complex code business logic, customers need to contact manufacturers to develop new module docking. However, handing over the development to manufacturers will lead to a series of personnel communication and cost issues, and may also require on-site support. Summary of the Invention

[0004] In response to the problems existing in the prior art, the purpose of the present invention is to provide a method and system for implementing hot update dynamic adaptation based on JavaSPI, which can solve the problem of customized development scenarios and help customers complete the development by reading the instructions provided by the manufacturer without having to understand all the business logic.

[0005] To achieve the above object, the present invention provides a method for implementing dynamic adaptation of hot updates based on JavaSPI, the method comprising the following steps:

[0006] Step S110: planning and designing the functions to be provided and generating a standardized interface;

[0007] Step S120, implement the target interface according to the required functions and upload it to the server;

[0008] Step S130, judging whether there is a function module implementation class that needs to be loaded according to the data configured in the database;

[0009] If the answer is yes, the process proceeds to step S140 to rewrite JavaSPI and ClassLoader to load the target implementation class dynamically.

[0010] Furthermore, in step 110, the following sub-steps are included:

[0011] Step S210 , during the project development phase, planning functions that can serve as scalable output capabilities;

[0012] Step S220: Define the interface and the methods to be implemented based on the above functions, and annotate the interface calling process, the functions of the methods in the interface, the description and source of the input and output parameters of the methods, and mark the demo. The client inherits the defined interface and completes the implementation of the methods in the interface according to the instructions on the interface annotations.

[0013] Step S230: register the function implementation class to a service center that can be used for iterative updates to provide it for development use.

[0014] Furthermore, in step 120, the following sub-steps are included:

[0015] Step S310, selecting the functional modules that need to be expanded and implemented;

[0016] Step 320: Based on the description of the functional module, understand the demo of the functional module interface, the description of the interface calling process and the input and output parameters of the method, and refer to the demo to develop additional functional modules;

[0017] In step S330, the function implementation class is compiled into a class file and uploaded to the service center for distribution. The distributed function can also be stopped to ensure the normal operation of the system iteration.

[0018] In step S340, the service center needs to check whether there are any effective functional modules. When the system starts, it first checks whether there are additional functional module implementation classes. If they exist, they are read and loaded and added to the adapter. The system completes the application of the newly implemented functions through the adapted content. It can also dynamically read the implemented functions and complete the hot update of functions by issuing execution during service operation.

[0019] Furthermore, in step 130, the following sub-steps are included:

[0020] Step S410, rewriting SPI based on JavaSPI concept;

[0021] Step S420, change the reading path and process, and rewrite the findClass method of ClassLoader;

[0022] Step S430: Read the bytecode in the database and load it into the JVM, and instantiate it through reflection. After encoding the bytecode in the database with base64, call defineClass. The JVM loads the bytecode into the virtual machine as an instantiable class by calling the method of the native class. Then, the aspect is called to find the type through Class.forName, and the function implementation class is instantiated through the Class.newInstance method.

[0023] Step S440: After the adaptation mapping is generated, the system assigns a mapping identifier as the mapping between the function module implementation class and the call. The system call interface passes through the aspect. The aspect is associated with the function module implementation class according to the mapping identifier effective in the system, and performs dynamic adaptation calling.

[0024] Furthermore, in step 420, all Java classes must be loaded by the JVM before they can run, and the ClassLoader reads the classes under the system startup path by default. It is necessary to add processing of other external classes in the findClass method. When the class name is obtained, it is first handed over to the top-level class loader in the JVM class loader, which is the boot class loader, extension class loader, or system class loader. The system class loader is the default class loader. If the corresponding function implementation class cannot be found, the rewritten findClass needs to be used. After the rewrite, findClass can use the class name of the function implementation class to go to the database or the specified file directory to find out whether the function implementation class exists.

[0025] On the other hand, the present invention further provides a system for implementing dynamic adaptation of hot updates based on JavaSPI, which can implement the method for implementing dynamic adaptation of hot updates based on JavaSPI according to the present invention.

[0026] Furthermore, the system includes a standardized interface, pluggable and extensible plug-ins and a plug-in support module, and the system can automatically read and apply the development results to the system.

[0027] The system uses JavaSPI as the plug-in basic support module to check whether there are additional function module implementation classes in the service center. If the function module implementation class is found, it will be read and loaded into the system for use.

[0028] The technical advantage of the present invention is that it is constructed into a plug-in support module through JavaSPI. The system that realizes hot update dynamic adaptation based on JavaSPI can automatically read and apply according to the development results. It only needs to plan the system in advance. The more perfect the planning is, the more comprehensive the functions provided are, the more it can help reduce the communication between multiple parties, and improve development efficiency. It can also perform hot update to repair problems when some faults occur during system operation. At the same time, it can enrich the dynamic processing capabilities of the program, realize online debugging, and realize complex and convenient functions. In the customized development scenario, it helps the client to realize the addition and improvement of functions by reading the instructions provided by the manufacturer without having to understand all the business logic. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] Figure 1 A flowchart of a method for implementing dynamic adaptation of hot updates based on JavaSPI according to an embodiment of the present invention is shown;

[0030] Figure 2 It shows a specific flow chart of the planning and design stage according to an embodiment of the present invention;

[0031] Figure 3 It shows a specific flow chart of late stage customized development according to an embodiment of the present invention;

[0032] Figure 4 A specific flow chart for implementing adaptation and dynamic loading according to an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0033] The following will clearly and completely describe the technical solution of the present invention in conjunction with the accompanying drawings. Obviously, the embodiments described are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.

[0034] In the description of the present invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicating orientations or positional relationships, are based on the orientations or positional relationships shown in the accompanying drawings and are intended solely to facilitate and simplify the description of the present invention. They are not intended to indicate or imply that the devices or components referred to must have, be constructed, or operate in a specific orientation, and therefore should not be construed as limitations on the present invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.

[0035] In the description of the present invention, it should be noted that, unless otherwise expressly specified or limited, the terms "mounted," "connected," and "connected" should be understood in a broad sense. For example, they may refer to fixed, detachable, or integral connections; mechanical or electrical connections; direct or indirect connections through an intermediate medium; and internal communication between two components. Those skilled in the art will understand the specific meanings of the above terms in the present invention based on specific circumstances.

[0036] The following is combined with Figure 1-4 The specific embodiments of the present invention are described in detail. It should be understood that the specific embodiments described herein are only used to illustrate and explain the present invention and are not used to limit the present invention.

[0037] The basic concept of this invention is to plan the expandable functions during the project design phase, implement template processing, build a standardized interface, and label the functions and uses of each method in the standardized interface, as well as the interface logic processing process. This is then organized into a reference development document with detailed instructions for each method and a demo for reference. Later development can be completed by simply referring to the demo's guidance. After the project is launched, the system uses JavaSPI as the basic plug-in support module to check whether the service center has additional functional module implementation classes. If so, the class is read and loaded into the system for use.

[0038] SPI (Service Provider Interface) is a service provider discovery mechanism built into the JDK. Many frameworks currently use it for extended service discovery. Simply put, it is a dynamic replacement discovery mechanism.

[0039] like Figure 1 As shown, the method for implementing hot update dynamic adaptation based on JavaSPI according to the present invention includes the following steps:

[0040] Step S110 , planning modules in the system that can serve as open capabilities, and designing and developing additional extended standardized interfaces based on the processing procedures of the modules;

[0041] Step S120: Implement the interface corresponding to the open capability module planned by the system according to functional requirements and upload it to the service center;

[0042] Step S130: After the service is started, it is determined whether there is a function module implementation class that needs to be loaded based on the data configured in the database;

[0043] If the answer is yes, that is, there is an additional functional module implementation class, then the process goes to step S140 , and reads the discovered implementation class based on JavaSPI and ClassLoader, and loads the target implementation class into the system for use.

[0044] The system development and design phase, in step 110, includes the following sub-steps:

[0045] Step S210: During the project development phase, plan which functions can be used as scalable output capabilities; for example, the system supports single sign-on from other sources, or a function or statistical filtering process;

[0046] In step S220, define the interface and methods to be implemented based on the above functions. Annotate the interface calling process, the functions of the methods in the interface, the description and source of the input and output parameters, and mark the demo for reference. The client inherits the defined interface and implements the methods in the interface according to the instructions in the interface annotations.

[0047] Step S230: register the function implementation class to a service center that can be used for iterative updates, so as to provide it to others for development and use.

[0048] The later development stage, in step 120, includes the following sub-steps:

[0049] Step S310: Select the functional modules that need to be expanded or implemented. Generally, for later development, you do not need to care about the overall functions of the business system, but only the functional modules that you need to expand.

[0050] Step 320: Based on the description of the functional module, understand the demo of the functional module interface, the description of the interface calling process and the input and output parameters of the method, and refer to the demo to develop additional functional modules;

[0051] In step S330, the function implementation class is compiled into a class file and uploaded to the service center for distribution. The distributed function can also be stopped to ensure the normal operation of the system iteration.

[0052] In step S340, the service center needs to check whether there are any effective functional modules. When the system starts, it first checks whether there are additional functional module implementation classes. If they exist, they are read and loaded and added to the adapter. The system completes the application of the newly implemented functions through the adapted content. It can also dynamically read the implemented functions and complete the hot update of functions by issuing execution during service operation.

[0053] The technical implementation process, in step 130, includes the following sub-steps:

[0054] Step S410: Rewrite the SPI based on the JavaSPI concept. The JavaSPI concept is a dynamic loading mechanism implemented through a combination of interface-based "programming + strategy pattern + configuration file," which separates the logic for controlling the assembly of functional modules from the system's business code. Customers can enable framework extensions or replacement functions based on actual business needs. However, since JavaSPI loads all implementation classes and only supports reading implementation classes from a specified path, the SPI needs to be rewritten to adjust the path for reading implementation classes and allow loading functional module implementation classes from other paths or databases.

[0055] Step S420, change the reading path and process, and rewrite the findClass method of ClassLoader; Java classes must be loaded by the JVM before they can run, and ClassLoader reads the classes under the system startup path by default. It is necessary to add processing of other external classes in the findClass method. When the class name is obtained, the top-level JVM class loader is first handed over to the Bootstrap ClassLoader (boot class loader), Extension ClassLoader (extension class loader), and App ClassLoader (system class loader). AppClassLoader is the default class loader. If the corresponding function implementation class cannot be found, the rewritten findClass needs to be used. After the rewrite, findClass can use the class name of the function implementation class to search the database or the specified file directory to find out whether the function implementation class exists.

[0056] Step S430, read the bytecode in the database and load it into the jvm, and instantiate it through reflection; after the bytecode in the database is base64-encoded, call defineClass, and the jvm loads the bytecode into the virtual machine as an instantiable class by calling the method of the native class, and then calls the aspect to find the type through Class.forName, and instantiates the function implementation class through the Class.newInstance method.

[0057] Step S440: After the adaptation mapping is generated, the system will assign a mapping identifier as the mapping between the function module implementation class and the call. The system call interface will pass through the aspect. The aspect will be associated with the function module implementation class according to the mapping identifier effective in the system, and perform dynamic adaptation calling.

[0058] In addition, the present invention also provides a system for implementing dynamic adaptation of hot updates based on JavaSPI. The system can implement the method provided by the present invention. During the design phase of the system, the functions that can be used for expansion are planned, template processing is performed, standardized interfaces are constructed, pluggable and extensible plug-ins are formed, and development documents are compiled for reference. The instructions for using each method are described in detail, and a demo is provided for reference. Later development can be completed by referring to the instructions of the demo. The system for implementing dynamic adaptation of hot updates based on JavaSPI is constructed as a plug-in support module through JavaSPI. The system for implementing dynamic adaptation of hot updates based on JavaSPI can automatically read and apply the development results to the system.

[0059] The technical concept of the present invention is to plan the system in advance. The more complete the planning and the more comprehensive the functions provided, the more it can help reduce communication among multiple parties and improve development efficiency. It can also perform hot updates to repair problems when partial failures occur during system operation. At the same time, it can enrich the dynamic processing capabilities of the program, realize online debugging, and realize complex and convenient functions.

[0060] The main advantage of the present invention is that it uses pluggable plug-ins to reduce continuous personnel investment after delivery, reduce the difficulty of subsequent expansion and transformation, facilitate transformation and expansion, do not require understanding the overall business logic of the system, reduce business communication with customers after delivery, and provide in the form of capabilities to help customers self-transform.

[0061] Throughout this specification, reference to terms such as "embodiment" and "example" indicates that a specific feature, structure, material, or characteristic described in conjunction with that embodiment or example is included in at least one embodiment or example of the present invention. In this specification, the schematic representations of these terms do not necessarily refer to the same embodiment or example. Furthermore, those skilled in the art may combine or integrate different embodiments or examples described in this specification, as well as features therein, without creating any inconsistency.

[0062] Although the above content has shown and described the embodiments of the present invention, it can be understood that the above embodiments are exemplary and cannot be understood as limitations of the present invention. Ordinary technicians in this field can perform update operations such as changes, modifications, replacements and variations on the above embodiments within the scope of the present invention.

Claims

1. A method for implementing dynamic adaptation of hot updates based on JavaSPI, characterized in that: The method comprises the following steps: Step S110: planning and designing the functions to be provided and generating a standardized interface; Step S120: Implement the target interface according to the required functions and upload it to the service center; Step S130, judging whether there is a function module implementation class that needs to be loaded according to the data configured in the database; If the answer is yes, the process proceeds to step S140, where JavaSPI and ClassLoader are rewritten to load the target implementation class dynamically; JavaSPI is a dynamic loading mechanism implemented based on the combination of "programming + strategy pattern + configuration file" based on the interface, which separates the logic of assembly control of functional modules from the business code of the system; customers enable framework extension or replacement functions based on actual business conditions; rewrite SPI to adjust the path for reading implementation classes, allowing functional module implementation classes to be loaded from other paths or databases.

2. The method for implementing hot update dynamic adaptation based on JavaSPI according to claim 1, characterized in that: In step 110, the following sub-steps are included: Step S210 , during the project development phase, planning functions that can serve as scalable output capabilities; Step S220: Define the interface and the methods to be implemented based on the above functions, and annotate the interface calling process, the functions of the methods in the interface, the description and source of the input and output parameters of the methods, and mark the demo. The client inherits the defined interface and completes the implementation of the methods in the interface according to the instructions on the interface annotations. Step S230: register the function implementation class to a service center that can be used for iterative updates to provide it for development use.

3. The method for implementing hot update dynamic adaptation based on JavaSPI according to claim 1 or 2, characterized in that: In step 120, the following sub-steps are included: Step S310, selecting the functional modules that need to be expanded and implemented; Step 320: Based on the description of the functional module, understand the demo of the functional module interface, the description of the interface calling process and the input and output parameters of the method, and refer to the demo to develop additional functional modules; Step S330: The function implementation class is then compiled into a class file and uploaded to the service center for distribution. The distributed function can also be stopped to ensure the normal operation of the system iteration. In step S340, the service center needs to check whether there are any effective functional modules. When the system starts, it first checks whether there are additional functional module implementation classes. If they exist, they are read and loaded and added to the adapter. The system completes the application of the newly implemented functions through the adapted content. It can also dynamically read the implemented functions and complete the hot update of functions by issuing execution during service operation.

4. The method for implementing hot update dynamic adaptation based on JavaSPI according to claim 3, characterized in that: In step 130, the following sub-steps are included: Step S410, rewriting SPI based on JavaSPI concept; Step S420, change the reading path and process, and rewrite the findClass method of ClassLoader; Step S430: Read the bytecode in the database and load it into the JVM, and instantiate it through reflection. After encoding the bytecode in the database with base64, call defineClass. The JVM loads the bytecode into the virtual machine as an instantiable class by calling the method of the native class. Then, the aspect is called to find the type through Class.forName, and the function implementation class is instantiated through the Class.newInstance method. Step S440: After the adaptation mapping is generated, the system assigns a mapping identifier as the mapping between the function module implementation class and the call. The system call interface passes through the aspect. The aspect is associated with the function module implementation class according to the mapping identifier effective in the system, and performs dynamic adaptation calling.

5. The method for implementing hot update dynamic adaptation based on JavaSPI according to claim 4, characterized in that: In step 420, all Java classes must be loaded by the JVM before they can run, and the ClassLoader reads the classes under the system startup path by default. It is necessary to add processing of other external classes in the findClass method. When the class name is obtained, it is first handed over to the top-level class loader in the JVM class loader, which is the boot class loader, extension class loader, or system class loader. The system class loader is the default class loader. If the corresponding function implementation class cannot be found, the rewritten findClass needs to be used. After the rewrite, findClass can use the class name of the function implementation class to go to the database or the specified file directory to find out whether the function implementation class exists.

6. A system for implementing dynamic adaptation of hot updates based on Java SPI, wherein the system can implement the method for implementing dynamic adaptation of hot updates based on Java SPI according to any one of claims 1 to 5.

7. The system for implementing hot update dynamic adaptation based on JavaSPI according to claim 6, characterized in that: The system includes a standardized interface, a pluggable and extensible plug-in and a plug-in support module, and the system can automatically read and apply the development results to the system.

8. The system for implementing hot update dynamic adaptation based on JavaSPI according to claim 7, characterized in that: The system uses JavaSPI as the plug-in basic support module to check whether there are additional function module implementation classes in the service center. If the function module implementation class is found, it will be read and loaded into the system for use.

Citation Information

Patent Citations

  • System and method for realizing Java class on-line hot updating in cloud computing environment

    CN105068852A

  • Remote agent type hot replacement method and device

    CN109933356A

  • Method and device for dynamically creating service interface, electronic equipment and storage medium

    CN112685020A