CN117632286A - OpenApi implementation method and device based on dynamic class loading - Google Patents
OpenApi implementation method and device based on dynamic class loading Download PDFInfo
- Publication number
- CN117632286A CN117632286A CN202311587321.1A CN202311587321A CN117632286A CN 117632286 A CN117632286 A CN 117632286A CN 202311587321 A CN202311587321 A CN 202311587321A CN 117632286 A CN117632286 A CN 117632286A
- Authority
- CN
- China
- Prior art keywords
- class file
- openapi
- class
- target
- virtual machine
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 67
- 238000013507 mapping Methods 0.000 claims abstract description 33
- 230000006870 function Effects 0.000 claims description 41
- 238000012986 modification Methods 0.000 claims description 16
- 230000004048 modification Effects 0.000 claims description 16
- 230000008569 process Effects 0.000 claims description 14
- 238000004590 computer program Methods 0.000 claims description 12
- 230000000007 visual effect Effects 0.000 claims description 8
- 238000011084 recovery Methods 0.000 claims description 3
- 238000012544 monitoring process Methods 0.000 claims 2
- 238000010586 diagram Methods 0.000 description 17
- 238000004891 communication Methods 0.000 description 9
- 239000000306 component Substances 0.000 description 8
- 238000012545 processing Methods 0.000 description 7
- 238000011161 development Methods 0.000 description 5
- 238000013461 design Methods 0.000 description 3
- 230000003287 optical effect Effects 0.000 description 3
- 230000006399 behavior Effects 0.000 description 2
- 230000005540 biological transmission Effects 0.000 description 2
- 230000003993 interaction Effects 0.000 description 2
- 238000004458 analytical method Methods 0.000 description 1
- 238000013459 approach Methods 0.000 description 1
- 238000003491 array Methods 0.000 description 1
- 238000013473 artificial intelligence Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000004422 calculation algorithm Methods 0.000 description 1
- 230000015556 catabolic process Effects 0.000 description 1
- 230000001413 cellular effect Effects 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 239000008358 core component Substances 0.000 description 1
- 238000006731 degradation reaction Methods 0.000 description 1
- 238000005538 encapsulation Methods 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 238000010801 machine learning Methods 0.000 description 1
- 230000007246 mechanism Effects 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 230000004044 response Effects 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
- 230000001953 sensory effect Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
- 238000012360 testing method Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/445—Program loading or initiating
- G06F9/44521—Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/455—Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
- G06F9/45533—Hypervisors; Virtual machine monitors
- G06F9/45558—Hypervisor-specific management and integration aspects
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Stored Programmes (AREA)
Abstract
The disclosure provides an OpenApi implementation method and device based on dynamic class loading, relates to the technical field of computers, and particularly relates to the field of program development. The specific implementation scheme is as follows: compiling Java classes into Class files, and generating mapping relations between the Java classes and the Class files; generating an OpenApi file based on the mapping relation, wherein the OpenApi file comprises an access path definition, a request parameter definition and a return parameter definition; receiving a call request sent by a user terminal, and determining a target Class file based on access path parameters carried by the call request; and pulling the target Class file to a Java virtual machine to run and obtaining a returned result of OpenApi by calling a parameter entering function.
Description
Technical Field
The disclosure relates to the technical field of computers, in particular to the field of program development, and specifically relates to an OpenApi implementation method and device based on dynamic class loading.
Background
OpenAPI refers to an open application program interface (Open Application Programming Interface), which is a set of interfaces that define the communication specifications between different software components. Through the OpenAPI, different software systems can interact and integrate with each other, and the operations such as data transmission, function sharing and service calling are realized. The design goal of OpenAPI is to provide a standardized interface specification that enables developers to build, test, and maintain more conveniently. In the related art, the platform encapsulates the code with the granularity of the function, so that the development amount is large.
Disclosure of Invention
The disclosure provides an OpenApi implementation method and device based on dynamic class loading.
According to an aspect of the present disclosure, there is provided an OpenApi implementation method based on dynamic class loading, including: compiling Java classes into Class files, and generating mapping relations between the Java classes and the Class files; generating an OpenApi file based on the mapping relation, wherein the OpenApi file comprises an access path definition, a request parameter definition and a return parameter definition; receiving a call request sent by a user terminal, and determining a target Class file based on access path parameters carried by the call request; and pulling the target Class file to a Java virtual machine to run and obtaining a returned result of OpenApi by calling a parameter entering function.
According to one embodiment of the present application, after compiling the Java Class into the Class file, the method further comprises: storing the Class file on a content delivery network CDN; pulling the target Class file to a Java virtual machine for operation, wherein the method comprises the following steps of: and pulling the target Class file from the CDN to the Java virtual machine for running.
According to one embodiment of the present application, determining a target Class file based on an access path parameter carried by a call request includes: determining a class name based on the access path parameter carried by the call request; according to the Class names, combining the mapping relation to obtain Class file addresses; the target Class file is determined from the CDN based on the Class file address.
According to one embodiment of the application, pulling the target Class file to the Java virtual machine for operation and obtaining the returned result of OpenApi by calling the parameter entering function includes: pulling the target Class file to a Java virtual machine for operation; analyzing the parameter entering function into json format, and calling the analyzed parameter entering function to a Java virtual machine to enter the function; and obtaining a return result of OpenApi.
According to one embodiment of the application, pulling the target Class file to Java virtual machine operation includes: determining a target instance from a plurality of instances included in the Java virtual machine based on a load balancing policy; and pulling the target Class file to the target instance to run.
According to one embodiment of the present application, determining a target instance from a plurality of instances included in a Java virtual machine based on a load balancing policy includes: acquiring the resource utilization rate of each instance in the Java virtual machine at the current moment; and comparing the used rates of each resource, and taking the instance with the lowest used rate of the resource as a target instance.
According to one embodiment of the present application, after obtaining the returned result of OpenApi, the method further includes: judging whether the target Class file needs to be reused in the subsequent process or not; and if the target Class file is not used in the subsequent process, controlling the Java virtual machine to recover the target Class file.
According to one embodiment of the present application, the OpenApi implementation method based on dynamic class loading further includes: after each time of the modification operation on the Java Class is monitored, the Class file corresponding to the Java Class is synchronously modified.
According to one embodiment of the present application, the OpenApi implementation method based on dynamic class loading further includes: and displaying related data of the OpenApi on a visual interface, wherein the related data comprises access data, view data and modification data.
According to another aspect of the present disclosure, there is provided an OpenApi implementation apparatus based on dynamic class loading, including: the compiling module is used for compiling the Java Class into a Class file and generating a mapping relation between the Java Class and the Class file; the generating module is used for generating an OpenApi file based on the mapping relation, wherein the OpenApi file comprises access path definition, request parameter definition and return parameter definition; the receiving module is used for receiving a calling request sent by the user terminal and determining a target Class file based on an access path parameter carried by the calling request; and the acquisition module is used for pulling the target Class file to the Java virtual machine to run and acquiring a return result of the OpenApi by calling the parameter entering function.
According to one embodiment of the application, the compiling module is further configured to store the Class file on the content delivery network CDN; and the acquisition module is also used for pulling the target Class file from the CDN to the Java virtual machine for operation.
According to one embodiment of the present application, the receiving module is further configured to: determining a class name based on the access path parameter carried by the call request; according to the Class names, combining the mapping relation to obtain Class file addresses; the target Class file is determined from the CDN based on the Class file address.
According to one embodiment of the present application, the acquisition module is further configured to: pulling the target Class file to a Java virtual machine for operation; analyzing the parameter entering function into json format, and calling the analyzed parameter entering function to a Java virtual machine to enter the function; and obtaining a return result of OpenApi.
According to one embodiment of the present application, the acquisition module is further configured to: determining a target instance from a plurality of instances included in the Java virtual machine based on a load balancing policy; and pulling the target Class file to the target instance to run.
According to one embodiment of the present application, the acquisition module is further configured to: acquiring the resource utilization rate of each instance in the Java virtual machine at the current moment; and comparing the used rates of each resource, and taking the instance with the lowest used rate of the resource as a target instance.
According to one embodiment of the present application, the OpenApi implementation device based on dynamic class loading further includes: and the recovery module is used for judging whether the target Class file needs to be reused in the subsequent process, and controlling the Java virtual machine to recover the target Class file if the target Class file does not need to be used in the subsequent process.
According to one embodiment of the present application, the compiling module is further configured to: after each time of the modification operation on the Java Class is monitored, the Class file corresponding to the Java Class is synchronously modified.
According to one embodiment of the present application, the OpenApi implementation device based on dynamic class loading further includes: and the display module is used for displaying related data of the OpenApi on the visual interface, wherein the related data comprises access data, view data and modification data.
According to another aspect of the present disclosure, there is provided an electronic device including: at least one processor; and a memory communicatively coupled to the at least one processor; the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor, so that the at least one processor can execute the OpenApi implementation method based on dynamic class loading.
According to another aspect of the present disclosure, there is provided a non-transitory computer-readable storage medium storing computer instructions for causing the computer to perform the above-described OpenApi implementation method based on dynamic class loading.
According to another aspect of the present disclosure, there is provided a computer program product comprising a computer program which, when executed by a processor, implements the above-described OpenApi implementation method based on dynamic class loading.
The application at least realizes the following beneficial effects: the method and the device can realize automatic document generation of the API, improve development efficiency, reduce workload of manually writing the API document, realize dynamic calling of different Java classes, have flexibility and expandability, and can adapt to diversified business requirements.
It should be understood that the description in this section is not intended to identify key or critical features of the embodiments of the disclosure, nor is it intended to be used to limit the scope of the disclosure. Other features of the present disclosure will become apparent from the following specification.
Drawings
The drawings are for a better understanding of the present solution and are not to be construed as limiting the present disclosure. Wherein:
FIG. 1 is a schematic diagram of an exemplary implementation of an OpenApi implementation method based on dynamic class loading in accordance with an exemplary embodiment of the present disclosure.
FIG. 2 is a schematic diagram of an exemplary implementation of an OpenApi implementation method based on dynamic class loading in accordance with an exemplary embodiment of the present disclosure.
Fig. 3 is an exemplary diagram of Java class script content according to an exemplary embodiment of the present disclosure.
Fig. 4 is an exemplary schematic diagram of a generated OpenApi in accordance with an exemplary embodiment of the present disclosure.
Fig. 5 is a diagram of a json file according to an exemplary embodiment of the present disclosure.
Fig. 6 is a frame diagram of an OpenApi implementation method based on dynamic class loading according to an exemplary embodiment of the present disclosure.
Fig. 7 is a schematic diagram of an OpenApi implementation device based on dynamic class loading according to an exemplary embodiment of the present disclosure.
Fig. 8 is a schematic diagram of an electronic device according to an exemplary embodiment of the present disclosure.
Detailed Description
Exemplary embodiments of the present disclosure are described below in conjunction with the accompanying drawings, which include various details of the embodiments of the present disclosure to facilitate understanding, and should be considered as merely exemplary. Accordingly, one of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the present disclosure. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
The content delivery network (Content Delivery Network, CDN) is a distributed architecture of network services aimed at improving the speed and performance of the transmission of content over the internet. Its main goal is to deliver content to end users quickly and reliably, reducing network congestion and delay.
Java classes are basic organizational units in the Java programming language, which define the properties and behavior of objects, and are one of the core concepts of object-oriented programming. In Java, all code must be contained in a class. Java class is a basic building block of object-oriented programming, and has the characteristics of encapsulation, inheritance, polymorphism and the like. By defining classes, objects can be created and properties and behaviors of the objects utilized to accomplish specific tasks. In Java, classes are key to code reuse and modular design.
The Class file is a bytecode file into which a Java compiler compiles Java source code. It is stored in binary form and can be executed on a Java Virtual Machine (JVM). Class files are intermediate representations of the Java platform that contain executable instructions that are converted by Java source code.
A Java Virtual Machine (JVM) refers to a virtual machine that interprets or compiles Java bytecodes into machine code, which is one of the core components of the Java platform. The main function of the JVM is to be responsible for executing Java programs and to provide various support required by the Java programs when running.
Fig. 1 is a schematic diagram of an exemplary embodiment of an OpenApi implementation method based on dynamic class loading, as shown in fig. 1, where the OpenApi implementation method based on dynamic class loading includes the following steps:
s101, compiling the Java Class into a Class file, and generating a mapping relation between the Java Class and the Class file.
Java source code (Java Class) is compiled using a Java compiler, converted into an executable Class file, and the Class file is stored.
After the Class file is generated, the Java Class and the corresponding Class file are stored in a mapping relation.
S102, generating an OpenApi file based on the mapping relation, wherein the OpenApi file comprises an access path definition, a request parameter definition and a return parameter definition.
The uniform resource locator (Uniform Resource Locator, URL) of OpenApi has the format/{ className }/{ functionName }.
S103, receiving a call request sent by a user terminal, and determining a target Class file based on access path parameters carried by the call request.
And receiving a call request sent by the user terminal, wherein the call request carries an access path parameter, namely a URL, and the format is/{ className }/{ functionName }.
In the application, a corresponding Class file address is found according to the className, and a target Class file is determined according to the Class file address.
S104, pulling the target Class file to a Java virtual machine to run and obtaining a return result of OpenApi by calling a parameter entering function.
After the target Class file is loaded into the Java virtual machine, a reflection mechanism is used for calling a method in the target Class file, corresponding parameters are transmitted, and a return result of the OpenAPI is obtained.
The embodiment of the application provides an OpenApi implementation method for dynamic Class loading, which comprises the steps of compiling Java classes into Class files and generating mapping relations between the Java classes and the Class files; generating an OpenApi file based on the mapping relation, wherein the OpenApi file comprises an access path definition, a request parameter definition and a return parameter definition; receiving a call request sent by a user terminal, and determining a target Class file based on access path parameters carried by the call request; and pulling the target Class file to a Java virtual machine to run and obtaining a returned result of OpenApi by calling a parameter entering function. According to the method and the device, the OpenAPI file is generated through the mapping relation, so that automatic document generation of the API can be realized, the development efficiency is improved, and the workload of manually writing the API file is reduced; according to the access path parameters carried by the call request sent by the user terminal, the target Class file is determined and loaded to the Java virtual machine for operation, so that different Java classes can be dynamically called, the flexibility and the expandability are improved, and the method can adapt to diversified service requirements.
Fig. 2 is a schematic diagram of an exemplary embodiment of an OpenApi implementation method based on dynamic class loading, as shown in fig. 2, where the OpenApi implementation method based on dynamic class loading includes the following steps:
s201, compiling the Java Class into a Class file, storing the Class file on a content delivery network CDN, and generating a mapping relation between the Java Class and the Class file.
S202, generating an OpenApi file based on the mapping relation, wherein the OpenApi file comprises an access path definition, a request parameter definition and a return parameter definition.
Fig. 3 is an exemplary schematic diagram of Java script content as illustrated herein. Fig. 4 is an exemplary schematic diagram of a generated OpenApi shown in the present application.
As shown in fig. 3 and fig. 4, the OpenApi file is generated based on the mapping relationship, which refers to mapping the classname. Here, the access path is: the Main. Add function can be mapped to/Main/add; request parameters: the request parameter of main. Add is { "a":2, "b":3}; return parameters: the return type of the className.FunctionName function is the main.add return type is the int.
S203, receiving a call request sent by a user terminal, and determining a class name based on an access path parameter carried by the call request.
S204, according to the Class names, combining the mapping relation to obtain the Class file addresses.
S205, determining the target Class file from the CDN according to the Class file address.
S206, pulling the target Class file to the Java virtual machine for operation.
In the application, when a target Class file is pulled to a Java virtual machine to run, a target instance is firstly required to be determined from a plurality of instances included in the Java virtual machine based on a load balancing strategy; and pulling the target Class file to the target instance for operation.
Among them, as one way that can be implemented, the load balancing policy may be: acquiring the resource utilization rate of each instance in the Java virtual machine at the current moment; and comparing the used rates of each resource, and taking the instance with the lowest used rate of the resource as a target instance.
Among other things, as another achievable approach, the load balancing policy may be: each instance included in the Java virtual machine is polled to determine a target instance.
In the method, the target instance is determined from a plurality of instances included in the Java virtual machine based on the load balancing strategy, so that the request can be uniformly distributed to the plurality of Java virtual machine instances, performance degradation caused by overload of a certain instance is avoided, the performance of the whole system can be improved by effectively utilizing resources, and the system can be easily expanded when needed.
S207, analyzing the parameter entering function into json format, and calling the analyzed parameter entering function to the Java virtual machine to carry out function parameter entering.
For example, in the class of fig. 4, the parameters of the function main. Add function are (int a, int b), fig. 5 is a json file schematic diagram shown in the application, and as shown in fig. 5, the reference of OpenApi is a character string in josn format: { "a":2, "b":3}, key in json is the name of the parameter, value is the specific value of the parameter; after the analysis is completed, the main.add is loaded into the JVM to be called, and the parameter of the function is 'a' 2 and 'b' 3.
S208, obtaining a return result of OpenApi.
According to the embodiment of the application, the OpenAPI file is generated through the mapping relation, so that automatic document generation of the API can be realized, the development efficiency is improved, and the workload of manually writing the API file is reduced; storing the class in the CDN to realize quick pulling of the file; according to the access path parameters carried by the call request sent by the user terminal, the target Class file is determined and loaded to the Java virtual machine for operation, so that different Java classes can be dynamically called, the flexibility and the expandability are improved, and the method can adapt to diversified service requirements.
Further, after obtaining the returned result of OpenApi, the method further includes: judging whether the target Class file needs to be reused in the subsequent process or not; if the target Class file is not used in the subsequent process, the Java virtual machine is controlled to recover the target Class file, and the occupied memory resources are released back to the system, so that the memory occupation is reduced, the utilization efficiency of the system to the memory resources is improved, the system can better cope with other tasks needing more memory, the overhead of the system is reduced, and the overall performance and response speed of the system are improved.
Further, after the modification operation of the Java Class is monitored each time, the Class file corresponding to the Java Class is synchronously modified, so that the instantaneity and the reliability of the system are improved, and a developer only needs to pay attention to the modification of the Java Class without manually processing the corresponding Class file, so that the possibility of errors is reduced, and the complexity of deployment is also reduced.
Further, in the use process of the OpenApi, related data of the OpenApi is displayed on the visual interface, and the related data comprises access data, view data and modification data, so that the data is displayed to a user in a visual mode, the user can more conveniently know and master data information, and user experience is improved.
Fig. 6 is a frame diagram of an OpenApi implementation method based on dynamic Class loading, where, as shown in fig. 6, when implementing OpenApi based on dynamic Class loading, a Java Class is compiled into a Class file, the Class file is stored on a content delivery network CDN, a mapping relationship between the Java Class and the Class file is generated, and an OpenApi file is generated based on the mapping relationship. And receiving a calling request sent by the user terminal, and determining the class name based on the access path parameters carried by the calling request. According to Class names and the mapping relation, a Class file address is obtained, a target Class file is determined from the CDN according to the Class file address, the target Class file is pulled to a Java virtual machine to operate, a parameter entering function is analyzed into json format, the analyzed parameter entering function is called to the Java virtual machine to enter the function, and a return result of OpenApi is obtained.
Fig. 7 is a schematic diagram of an OpenApi implementation device based on dynamic class loading, as shown in fig. 7, where the OpenApi implementation device 700 based on dynamic class loading includes a compiling module 701, a generating module 702, a receiving module 703, and an obtaining module 704, where:
the compiling module 701 is configured to compile the Java Class into a Class file, and generate a mapping relationship between the Java Class and the Class file.
The generating module 702 is configured to generate an OpenApi file based on the mapping relationship, where the OpenApi file includes an access path definition, a request parameter definition, and a return parameter definition.
The receiving module 703 is configured to receive a call request sent by the user side, and determine a target Class file based on an access path parameter carried by the call request.
And the obtaining module 704 is configured to pull the target Class file to the Java virtual machine for running and obtain a return result of OpenApi by calling the parameter entering function.
The device generates the OpenAPI file through the mapping relation, can realize automatic document generation of the API, improves the development efficiency, and reduces the workload of manually writing the API document; according to the access path parameters carried by the call request sent by the user terminal, the target Class file is determined and loaded to the Java virtual machine for operation, so that different Java classes can be dynamically called, the flexibility and the expandability are improved, and the method can adapt to diversified service requirements.
Further, the compiling module 701 is further configured to store the Class file on the content delivery network CDN; the obtaining module 704 is further configured to pull the target Class file from the CDN to the Java virtual machine for running.
Further, the receiving module 703 is further configured to: determining a class name based on the access path parameter carried by the call request; according to the Class names, combining the mapping relation to obtain Class file addresses; the target Class file is determined from the CDN based on the Class file address.
Further, the acquiring module 704 is further configured to: pulling the target Class file to a Java virtual machine for operation; analyzing the parameter entering function into json format, and calling the analyzed parameter entering function to a Java virtual machine to enter the function; and obtaining a return result of OpenApi.
Further, the acquiring module 704 is further configured to: determining a target instance from a plurality of instances included in the Java virtual machine based on a load balancing policy; and pulling the target Class file to the target instance to run.
Further, the acquiring module 704 is further configured to: acquiring the resource utilization rate of each instance in the Java virtual machine at the current moment; and comparing the used rates of each resource, and taking the instance with the lowest used rate of the resource as a target instance.
Further, the OpenApi implementation apparatus 700 based on dynamic class loading further includes: and the recovery module is used for judging whether the target Class file needs to be reused in the subsequent process, and controlling the Java virtual machine to recover the target Class file if the target Class file does not need to be used in the subsequent process.
Further, the compiling module 701 is further configured to: after each time of the modification operation on the Java Class is monitored, the Class file corresponding to the Java Class is synchronously modified.
Further, the OpenApi implementation apparatus 700 based on dynamic class loading further includes: and the display module is used for displaying related data of the OpenApi on the visual interface, wherein the related data comprises access data, view data and modification data.
In the technical scheme of the disclosure, the acquisition, storage, application and the like of the related user personal information all conform to the regulations of related laws and regulations, and the public sequence is not violated.
According to embodiments of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
Fig. 8 illustrates a schematic block diagram of an example electronic device 800 that may be used to implement embodiments of the present disclosure. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular telephones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be exemplary only, and are not meant to limit implementations of the disclosure described and/or claimed herein.
As shown in fig. 8, the apparatus 800 includes a computing unit 801 that can perform various appropriate actions and processes according to a computer program stored in a Read Only Memory (ROM) 802 or a computer program loaded from a storage unit 808 into a Random Access Memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the device 800 can also be stored. The computing unit 801, the ROM 802, and the RAM 803 are connected to each other by a bus 804. An input/output (I/O) interface 805 is also connected to the bus 804.
Various components in device 800 are connected to I/O interface 805, including: an input unit 806 such as a keyboard, mouse, etc.; an output unit 807 such as various types of displays, speakers, and the like; a storage unit 808, such as a magnetic disk, optical disk, etc.; and a communication unit 809, such as a network card, modem, wireless communication transceiver, or the like. The communication unit 809 allows the device 800 to exchange information/data with other devices via a computer network such as the internet and/or various telecommunication networks.
The computing unit 801 may be a variety of general and/or special purpose processing components having processing and computing capabilities. Some examples of computing unit 801 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various specialized Artificial Intelligence (AI) computing chips, various computing units running machine learning model algorithms, a Digital Signal Processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 801 performs the various methods and processes described above, such as the OpenApi implementation method based on dynamic class loading. For example, in some embodiments, the OpenApi implementation based on dynamic class loading may be implemented as a computer software program tangibly embodied on a machine-readable medium, such as the storage unit 808. In some embodiments, part or all of the computer program may be loaded and/or installed onto device 800 via ROM 802 and/or communication unit 809. When a computer program is loaded into RAM 803 and executed by computing unit 801, one or more steps of the dynamic class loading based OpenApi implementation method described above may be performed. Alternatively, in other embodiments, the computing unit 801 may be configured to perform the OpenApi implementation based on dynamic class loading by any other suitable means (e.g., by means of firmware).
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuit systems, field Programmable Gate Arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Products (ASSPs), systems On Chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs, the one or more computer programs may be executed and/or interpreted on a programmable system including at least one programmable processor, which may be a special purpose or general-purpose programmable processor, that may receive data and instructions from, and transmit data and instructions to, a storage system, at least one input device, and at least one output device.
Program code for carrying out methods of the present disclosure may be written in any combination of one or more programming languages. These program code may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus such that the program code, when executed by the processor or controller, causes the functions/operations specified in the flowchart and/or block diagram to be implemented. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package, partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and pointing device (e.g., a mouse or trackball) by which a user can provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic input, speech input, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a background component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such background, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), wide Area Networks (WANs), and the internet.
The computer system may include a client and a server. The client and server are typically remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server may be a cloud server, a server of a distributed system, or a server incorporating a blockchain.
It should be appreciated that various forms of the flows shown above may be used to reorder, add, or delete steps. For example, the steps recited in the present disclosure may be performed in parallel or sequentially or in a different order, provided that the desired results of the technical solutions of the present disclosure are achieved, and are not limited herein.
The above detailed description should not be taken as limiting the scope of the present disclosure. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives are possible, depending on design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present disclosure are intended to be included within the scope of the present disclosure.
Claims (21)
1. An OpenApi implementation method based on dynamic class loading comprises the following steps:
compiling Java classes into Class files, and generating mapping relations between the Java classes and the Class files;
generating an OpenApi file based on the mapping relation, wherein the OpenApi file comprises an access path definition, a request parameter definition and a return parameter definition;
receiving a call request sent by a user terminal, and determining a target Class file based on an access path parameter carried by the call request;
and pulling the target Class file to a Java virtual machine to run and obtaining a returned result of OpenApi by calling a parameter entering function.
2. The method of claim 1, wherein after compiling the Java Class into a Class file, further comprising:
storing the Class file to a content delivery network CDN;
the pulling the target Class file to a Java virtual machine for operation comprises the following steps:
and pulling the target Class file from the CDN to the Java virtual machine for running.
3. The method of claim 2, wherein the determining the target Class file based on the access path parameters carried by the call request comprises:
determining a class name based on the access path parameter carried by the call request;
according to the Class names, combining the mapping relation to obtain Class file addresses;
and determining the target Class file from the CDN according to the Class file address.
4. The method of claim 3, wherein the pulling the target Class file to a Java virtual machine for running and obtaining the returned result of OpenApi by calling a parameterisation function comprises:
pulling the target Class file to a Java virtual machine for operation;
analyzing the parameter entering function into json format, and calling the analyzed parameter entering function to a Java virtual machine to carry out function parameter entering;
and acquiring a return result of the OpenApi.
5. The method of claim 4, wherein the pulling the target Class file to Java virtual machine operation comprises:
determining a target instance from a plurality of instances included in the Java virtual machine based on a load balancing policy;
and pulling the target Class file to the target instance for operation.
6. The method of claim 5, wherein the determining a target instance from a plurality of instances included in the Java virtual machine based on a load balancing policy comprises:
acquiring the resource utilization rate of each instance included in the Java virtual machine at the current moment;
and comparing the utilization rate of each resource, and taking the instance with the lowest utilization rate of the resource as the target instance.
7. The method of any one of claims 1-6, wherein after the obtaining the returned result of OpenApi, further comprising:
judging whether the target Class file needs to be reused in a subsequent process or not;
and if the target Class file is not used in the subsequent process, controlling the Java virtual machine to recover the target Class file.
8. The method of any of claims 1-6, wherein the method further comprises:
and after each time of monitoring the modification operation on the Java Class, synchronously modifying the Class file corresponding to the Java Class.
9. The method of any of claims 1-6, wherein the method further comprises:
and displaying the related data of the OpenApi on a visual interface, wherein the related data comprises access data, view data and modification data.
10. An OpenApi implementation device based on dynamic class loading, comprising:
the compiling module is used for compiling the Java Class into a Class file and generating a mapping relation between the Java Class and the Class file;
the generating module is used for generating an OpenApi file based on the mapping relation, wherein the OpenApi file comprises an access path definition, a request parameter definition and a return parameter definition;
the receiving module is used for receiving a call request sent by a user terminal and determining a target Class file based on an access path parameter carried by the call request;
and the acquisition module is used for pulling the target Class file to a Java virtual machine for operation and acquiring a return result of OpenApi by calling a parameter entering function.
11. The apparatus of claim 10, wherein the compiling module is further configured to store the Class file on a content delivery network CDN; and the acquisition module is also used for pulling the target Class file from the CDN to the Java virtual machine for operation.
12. The apparatus of claim 11, wherein the receiving module is further configured to:
determining a class name based on the access path parameter carried by the call request;
according to the Class names, combining the mapping relation to obtain Class file addresses;
and determining the target Class file from the CDN according to the Class file address.
13. The apparatus of claim 12, wherein the acquisition module is further configured to:
pulling the target Class file to a Java virtual machine for operation;
analyzing the parameter entering function into json format, and calling the analyzed parameter entering function to a Java virtual machine to carry out function parameter entering;
and acquiring a return result of the OpenApi.
14. The apparatus of claim 13, wherein the acquisition module is further configured to:
determining a target instance from a plurality of instances included in the Java virtual machine based on a load balancing policy;
and pulling the target Class file to the target instance for operation.
15. The apparatus of claim 14, wherein the acquisition module is further configured to:
acquiring the resource utilization rate of each instance included in the Java virtual machine at the current moment;
and comparing the utilization rate of each resource, and taking the instance with the lowest utilization rate of the resource as the target instance.
16. The apparatus of any of claims 10-15, wherein the apparatus further comprises:
and the recovery module is used for judging whether the target Class file needs to be reused in the subsequent process, and controlling the Java virtual machine to recover the target Class file if the target Class file does not need to be reused in the subsequent process.
17. The apparatus of any of claims 10-15, wherein the compiling module is further to:
and after each time of monitoring the modification operation on the Java Class, synchronously modifying the Class file corresponding to the Java Class.
18. The apparatus of any of claims 10-15, wherein the apparatus further comprises:
and the display module is used for displaying the related data of the OpenApi on a visual interface, wherein the related data comprises access data, view data and modification data.
19. An electronic device, comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-9.
20. A non-transitory computer readable storage medium storing computer instructions for causing the computer to perform the method of any one of claims 1-9.
21. A computer program product comprising a computer program which, when executed by a processor, implements the steps of the method according to any one of claims 1-9.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311587321.1A CN117632286A (en) | 2023-11-24 | 2023-11-24 | OpenApi implementation method and device based on dynamic class loading |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311587321.1A CN117632286A (en) | 2023-11-24 | 2023-11-24 | OpenApi implementation method and device based on dynamic class loading |
Publications (1)
Publication Number | Publication Date |
---|---|
CN117632286A true CN117632286A (en) | 2024-03-01 |
Family
ID=90028058
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202311587321.1A Pending CN117632286A (en) | 2023-11-24 | 2023-11-24 | OpenApi implementation method and device based on dynamic class loading |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN117632286A (en) |
-
2023
- 2023-11-24 CN CN202311587321.1A patent/CN117632286A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111414154A (en) | Method and device for front-end development, electronic equipment and storage medium | |
CN113050940A (en) | Method for previewing small program, related device and computer program product | |
CN112835615A (en) | Plug-in processing method and device for software development kit and electronic equipment | |
EP3872630A2 (en) | Request processing method and apparatus, electronic device, and computer storage medium | |
CN117707503A (en) | Method, apparatus, device, storage medium and program product for generating code | |
CN117632286A (en) | OpenApi implementation method and device based on dynamic class loading | |
US20230110520A1 (en) | Ui service package generation and registration method and apparatus, and ui service loading method and apparatus | |
CN116932147A (en) | Streaming job processing method and device, electronic equipment and medium | |
CN116594621A (en) | Real-time stream processing system, method and device, electronic equipment and computer medium | |
CN112860235B (en) | Method, device, equipment and storage medium for processing text | |
CN114168151B (en) | Container-based program compiling method and device, electronic equipment and storage medium | |
CN113141407B (en) | Page resource loading method and device and electronic equipment | |
CN112882711B (en) | Rendering method, device, equipment and storage medium | |
CN116244703A (en) | Fuzzy test method and device | |
CN114510334A (en) | Class instance calling method and device, electronic equipment and automatic driving vehicle | |
CN114968200A (en) | Software development kit assembly method, related device and computer program product | |
CN114115854A (en) | SDK file generation method, device, equipment and storage medium | |
CN116431108B (en) | Object type processing method and device, electronic equipment and storage medium | |
CN114416215A (en) | Function calling method and device | |
CN114661402A (en) | Interface rendering method and device, electronic equipment and computer readable medium | |
CN114785864A (en) | Data interaction method, system, electronic equipment and storage medium | |
CN116561075B (en) | Method for generating dynamic link library file, method and device for calling operator | |
CN113361235B (en) | HTML file generation method and device, electronic equipment and readable storage medium | |
CN113535187B (en) | Service online method, service updating method and service providing method | |
CN114428646B (en) | Data processing method and device, electronic equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |