Multi-language component management method, computer equipment and computer program product
Through the multilingual component management method, the loading method is determined based on the component's writing language, and the life cycle and communication of the component are managed by the loader, the communication problem of application components in different scenarios is solved, and the high performance and cross-platform compatibility of distributed systems are achieved.
Patent Information
- Application Number
- CN202411693143.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-22
- Publication Date
- 2025-03-18
AI Technical Summary
The existing distributed system technology is difficult to realize the communication of application components in different scenarios, resulting in insufficient systems in terms of high performance and cross-platform compatibility.
By providing a multilingual component management method, the loading method is determined according to the component's writing language, and the life cycle of the component and communication between components are managed through the loader to ensure that the components can communicate in different scenarios.
It realizes communication between application components in different scenarios, ensures high performance and cross-platform compatibility of distributed systems, and can dynamically load and unload components without restarting.
Smart Images

Figure CN119645516A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of program management, and in particular to a multi-language component management method, a computer device, and a computer program product. Background Art
[0002] In the context of modern distributed systems, unifying and simplifying development processes, supporting multiple languages, dynamically managing components, and efficient cross-language communication mechanisms are the core requirements of system design. Currently, similar technologies include: Service Mesh's SideCar and Dapr. The core of these technologies is to be responsible for component communication, but they do not provide a component development framework, and the communication methods must be placed in the components, which leads to the inability of application components to communicate in different scenarios. Summary of the invention
[0003] The purpose of this application is to provide a multi-language component management method, computer device and computer program product, which can enable application components to communicate in different scenarios and ensure high performance and cross-platform compatibility of distributed systems.
[0004] To achieve the above objectives, this application provides the following solutions:
[0005] In a first aspect, the present application provides a multi-language component management method, comprising:
[0006] For any component, determining a loading method of the component according to a programming language of the component;
[0007] Based on the loading method of the component, the component is loaded into a loading program, and communication between the component and the loading program is established during the loading process;
[0008] The loader manages the life cycle of components and the communication between components.
[0009] Furthermore, the loading mode of the component is determined according to the programming language of the component, specifically including:
[0010] Determining whether the component is a dynamic library component according to the programming language of the component;
[0011] If the component is a dynamic library component, the component is loaded into the memory;
[0012] If the component is a non-dynamic library component, the loading method of the component is to start it in an independent process.
[0013] Further, based on the loading method of the component, the component is loaded into a loading program, specifically including:
[0014] If the component is loaded into a memory, the component is loaded into the process of the loading program, and during the loading process, a memory-based application programming interface is injected into the component to establish communication between the component and the loading program;
[0015] If the component is loaded by starting an independent process, a new process is started through the loader to start the virtual machine corresponding to the component, and the component is loaded by the virtual machine. During the loading and running of the component, the development framework is used to provide an application interface to establish communication between the component and the loader.
[0016] Further, loading the component into the process of the loader specifically includes:
[0017] Invoking a compiler through the loader to compile the code of the component into a component of a dynamic library;
[0018] The component is loaded into the process of the loader through the application programming interface of the operating system loading the dynamic library.
[0019] Further, starting a new process through the loader to start a virtual machine corresponding to the component, and loading the component by the virtual machine, specifically includes:
[0020] Compiling the component code into an executable code of a virtual machine by calling a compiler through the loader;
[0021] Starting a new process through the loader to start the virtual machine corresponding to the component;
[0022] The executable code is executed by the virtual machine to load the component.
[0023] Furthermore, the development framework is used to provide an application program interface, specifically including: providing an application program interface based on named pipes under Windows system, and providing an application program interface based on Unix Socket under Linux system.
[0024] Furthermore, the loader manages the component lifecycle and the communication between components, including
[0025] Call the component's initialization function when the component is loaded, and call the component's end function when the component is unloaded to manage the component's entire life cycle;
[0026] When components call each other, the calling component sends a request message to the loader, and the loader parses the received request message, determines the target component, and sends the request message to the target component to enable the calling component to call the data in the target component.
[0027] Furthermore, the loader uses Protobuf as a message serialization protocol.
[0028] In a second aspect, the present application provides a computer device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the above-mentioned multi-language component management method.
[0029] In a third aspect, the present application provides a computer program product, including a loader for multi-language components, which, when executed by a processor, is used to load components written in different languages, establish communication with the components, and manage the life cycle of the components and communication between components.
[0030] According to the specific embodiments provided in this application, this application has the following technical effects:
[0031] The present application provides a multi-language component management method, computer equipment and computer program product, which determines the loading mode of the component according to the writing language of the component, and loads the component into the loader based on the loading mode of the component, establishes communication between the component and the loader during the loading process, and manages the life cycle of the component and the communication between components through the loader. The loader is applied to all components, manages the life cycle of the component and the communication between components, can uniformly manage components written in different languages, and can dynamically load and unload all components without restarting the component, thereby realizing the communication of application components in different scenarios, ensuring the high performance and cross-platform compatibility of the distributed system. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0033] Figure 1 A flowchart of a multi-language component management method in one embodiment of the present application;
[0034] Figure 2 This is a schematic diagram of the way in which two components are operated after being loaded by a loading program in an embodiment of the present application;
[0035] Figure 3 A schematic diagram of the structure of a computer device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0036] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0037] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0038] In an exemplary embodiment, Figure 1 As shown, a multi-language component management method is provided. The method is executed by a computer device, and can be specifically executed by a computer device such as a terminal or a server alone, or can be executed by a terminal and a server together. The multi-language component management method includes steps 101 to 103.
[0039] in:
[0040] Step 101: for any component, determine the loading mode of the component according to the programming language of the component.
[0041] In an exemplary embodiment, whether a component is a dynamic library component is determined based on the programming language of the component. Figure 2 As shown, two ways of running components after being loaded by the loader are demonstrated. If the component is a dynamic library component, the loading method of the component is to load the component into the memory. If the component is a non-dynamic library component, the loading method of the component is to start it in an independent process.
[0042] When the loader packages the compiled code into a component, it additionally writes the language in which the component is written in the component information. When the loader subsequently loads the component, it can determine the loading method based on the language in which the component is written.
[0043] Step 102: based on the loading method of the component, load the component into a loading program, and establish communication between the component and the loading program during the loading process.
[0044] The loader in this application not only supports unified management and communication of components written in multiple languages, but also allows dynamic loading and unloading of components without restarting the program.
[0045] (1) If the component is loaded into memory, the component is loaded into the process of the loader, and during the loading process, a memory-based application programming interface (Application Programming Interface, API) is injected into the component to establish communication between the component and the loader.
[0046] The loader program calls a compiler to compile the code of the component into a component of a dynamic library, and the component is loaded into the process of the loader program by loading an application programming interface of the dynamic library through an operating system.
[0047] For components written in C++ or Rust, the loader calls the C++ or Rust compiler to compile the code into dynamic library components, and uses the operating system's API for loading dynamic libraries to load the components into the loader's process. During the loading process, the loader injects the memory-based API into the component, allowing the component to communicate with the loader through the memory-based API.
[0048] Among them, the C++ or Rust compiler has the function of compiling the code into a dynamic library, which is a dll file in Windows system and a so file in Linux system.
[0049] Each compiled component exports the corresponding injection binary interface. After using LoadLibrary to load the component in Windows, use GetProcAddress to obtain the addresses of all exported functions. After using dlopen to load the component in Linux, use dlsym to obtain the addresses of all exported functions. After obtaining the address of the exported function, the loader injects the memory address of the API to be injected into the component through the exported function.
[0050] (2) If the component is loaded by starting as an independent process, a new process is started by the loader to start the virtual machine corresponding to the component, and the component is loaded by the virtual machine. During the loading and running of the component, an application program interface is provided by the development framework to establish communication between the component and the loader.
[0051] The loader program calls a compiler to compile the component code into an executable code of a virtual machine. The loader program starts a new process to start the virtual machine corresponding to the component. The virtual machine executes the executable code to load the component.
[0052] The development framework is used to provide an application program interface, specifically including: providing an application program interface based on a named pipe (NamedPipe) under a Windows system, and providing an application program interface based on a Unix Socket under a Linux system.
[0053] The loader provides a development framework for each development language. The development framework mainly specifies the initialization interface when loading a component, the end interface when unloading, the interface for the loader to distribute information to the component, and the interface for the component to pass messages to the loader. In order to support multiple languages at the same time, the loader uses Protobuf as the message serialization protocol.
[0054] For components written in Java or Python, the loader calls the Java or Python compiler to compile the code into executable code for the virtual machine used by these languages. When loading a component, the loader starts a new process to start the virtual machine corresponding to the component, and then the virtual machine loads the component. During the component loading and running process, the loader uses the NamedPipe or Socket-based API provided by the development framework to establish communication between the component and the loader.
[0055] In addition, the loader provides a set of management interfaces based on Hypertext Transfer Protocol (HTTP) to dynamically load and unload components. The management interfaces include: LoadComponent and UnLoadComponent. The LoadComponent interface loader will run the code by starting the Java or Python executor, and the UnLoadComponent interface loader will close the component by closing the process.
[0056] Step 103: managing the component lifecycle and the communication between components through the loader.
[0057] In an exemplary embodiment, the initialization function (on_init) of the component is called when the component is loaded, and the finalization function (on_finalize) of the component is called when the component is unloaded, so as to manage the entire life cycle of the component.
[0058] When components call each other, the calling component sends a request message to the loader, and the loader parses the received request message, determines the target component, and sends the request message to the target component to enable the calling component to call the data in the target component.
[0059] The loader provides a development framework based on the Protobuf protocol for each language. When components call each other, the calling component first serializes the information using Protofbuf, and then uses the API that interacts with the loader to send the information to the loader. After receiving the request message, the loader parses the request message, obtains the target component of the request, and then sends the request message to the target component through the interactive API.
[0060] The components in this application are applications. For example, component A provides data a and an interface aa for obtaining data a. Component B needs to obtain data a of component A to perform an action. Then component B will call component A and provide interface aa for obtaining data a. Component B generates a request message based on the parameters required by interface aa and sends it to the loader to obtain data a.
[0061] In an exemplary embodiment, a computer device is provided. The computer device may be a server or a terminal. The internal structure diagram thereof may be as follows: Figure 3 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store component codes and load programs. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a multi-language component management method is implemented.
[0062] Those skilled in the art will understand that Figure 3 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0063] In an exemplary embodiment, a computer program product is provided, including a loader for multi-language components, which, when executed by a processor, is used to load components written in different languages, establish communications with the components, and manage component life cycles and communications between components.
[0064] The loader in this application is mainly used for all components, managing the life cycle of components and the communication between components. The loader provides a component development framework for various programming languages, unifies and simplifies the development process of components, shields the interaction details between components and loaders, and the communication details between components, and can uniformly manage components written in different languages. And all components can be dynamically loaded and unloaded without restarting the components. Different component writing methods are provided in different application scenarios. For example: in scenarios with high requirements for writing performance, components and loaders are in the same process, and components can be written in a memory communication manner; for components of independent processes (mainly used for writing business logic components), based on Named Pipes communication under Windows systems, and based on Unix Socket communication under Linux systems, the efficiency of cross-process communication is improved. In summary, this application provides optimized communication methods for different scenarios to ensure high performance and cross-platform compatibility of distributed systems.
[0065] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0066] In this application, all actions to obtain signals, information or data are carried out in compliance with the relevant data protection laws and policies of the country where they are located and with the authorization given by the owner of the corresponding device.
[0067] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM may be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0068] The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. The non-relational database may include a distributed database based on blockchain, etc., but is not limited thereto. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but is not limited thereto.
[0069] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0070] This article uses specific examples to illustrate the principles and implementation methods of this application. The description of the above embodiments is only used to help understand the method and core ideas of this application. At the same time, for those skilled in the art, according to the ideas of this application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting this application.
Claims
1. A multi-language component management method, characterized in that: The multi-language component management method comprises: For any component, determining a loading method of the component according to a programming language of the component; Based on the loading method of the component, the component is loaded into a loading program, and communication between the component and the loading program is established during the loading process; The loader manages the life cycle of components and the communication between components.
2. The multi-language component management method according to claim 1, characterized in that: Determining a loading method of the component according to the programming language of the component, specifically including: Determining whether the component is a dynamic library component according to the programming language of the component; If the component is a dynamic library component, the component is loaded into the memory; If the component is a non-dynamic library component, the loading method of the component is to start it in an independent process.
3. The multi-language component management method according to claim 2, characterized in that: Based on the loading method of the component, the component is loaded into a loading program, specifically including: If the component is loaded into a memory, the component is loaded into the process of the loading program, and during the loading process, a memory-based application programming interface is injected into the component to establish communication between the component and the loading program; If the component is loaded by starting an independent process, a new process is started through the loader to start the virtual machine corresponding to the component, and the component is loaded by the virtual machine. During the loading and running of the component, the development framework is used to provide an application interface to establish communication between the component and the loader.
4. The multi-language component management method according to claim 3, characterized in that: Loading the component into the process of the loader specifically includes: Invoking a compiler through the loader to compile the code of the component into a component of a dynamic library; The component is loaded into the process of the loader through the application programming interface of the operating system loading the dynamic library.
5. The multi-language component management method according to claim 3, characterized in that: Starting a new process through the loader to start a virtual machine corresponding to the component, and loading the component through the virtual machine specifically includes: Compiling the component code into an executable code of a virtual machine by calling a compiler through the loader; Starting a new process through the loader to start the virtual machine corresponding to the component; The executable code is executed by the virtual machine to load the component.
6. The multi-language component management method according to claim 3, characterized in that: Use the development framework to provide application programming interfaces, including: providing an application programming interface based on named pipes under Windows systems, and providing an application programming interface based on Unix Socket under Linux systems.
7. The multi-language component management method according to claim 1, characterized in that: The loader manages the component lifecycle and communication between components, including Call the component's initialization function when the component is loaded, and call the component's end function when the component is unloaded to manage the component's entire life cycle; When components call each other, the calling component sends a request message to the loader, and the loader parses the received request message, determines the target component, and sends the request message to the target component to enable the calling component to call the data in the target component.
8. The multi-language component management method according to claim 1, characterized in that: The loader uses Protobuf as the message serialization protocol.
9. A computer device comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the multi-language component management method according to any one of claims 1 to 8.
10. A computer program product comprising a loader for a multi-language component, characterized in that When the loader is executed by the processor, it is used to load components written in different languages, establish communication with the components, and manage the life cycle of the components and the communication between the components.