BRIEF SUMMARY OF THE PRESENT DISCLOSURE
The present disclosure aims to provide a method, an apparatus, a medium and a device for dynamic library heat update, which can solve at least one technical problem mentioned above. The specific scheme is as follows:
according to a specific embodiment of the present disclosure, in a first aspect, the present disclosure provides a dynamic library heat updating method, including:
creating a folder path named with the current time;
traversing all files under the compiling catalogue, and judging whether the files are files of a specified type;
when the file is the specified type file, modifying the import packet path of the specified type file;
adding the modified specified type file into the first position of the folder path;
receiving a compiling instruction for a dynamic library file at the first position;
and loading the updated dynamic library to a specified main program to realize the updating of the dynamic library file.
Optionally, when the file is the specified type file, modifying the import packet path of the specified type file includes:
and when the file is the specified type file, modifying the import packet path of the specified type file into the folder path named with the current time.
Optionally, the traversing compiles all files under the directory, and determining whether the files are files of a specified type includes:
when the file is a file of a non-specified type, the file content is directly copied to a second location of the folder path.
Optionally, the specified type file is a go file in a golang language.
According to a second aspect of the present disclosure, there is provided a dynamic library heat updating apparatus comprising:
a creation unit configured to create a folder path named at a current time;
the judging unit is configured to traverse all files under the compiling catalogue and judge whether the files are files of a specified type or not;
a modifying unit configured to modify an import packet path of the specified type file when the file is the specified type file;
an adding unit configured to add the modified specified type file to the first location of the folder path;
the receiving unit is configured to receive a compiling instruction for the dynamic library file at the first position;
and the loading unit is configured to load the updated dynamic library to the appointed main program to realize the updating of the dynamic library file.
Optionally, the modifying unit is further configured to:
and when the file is the specified type file, modifying the import packet path of the specified type file into the folder path named with the current time.
Optionally, the method further comprises:
and the copying unit is configured to directly copy the file content to a second position of the folder path when the file is a file of a non-specified type.
Optionally, the specified type file is a go file in a golang language.
According to a third aspect of the present disclosure, there is provided a computer readable storage medium having stored thereon a computer program which when executed by a processor implements a method as claimed in any one of the above.
According to a fourth aspect of the present disclosure, there is provided an electronic device comprising: one or more processors; storage means for storing one or more programs that, when executed by the one or more processors, cause the one or more processors to implement the method of any of the preceding claims.
Compared with the prior art, the scheme of the embodiment of the disclosure has at least the following beneficial effects: the method realizes the hot update of the golang dynamic library by modifying the compiling mode. After the dynamic library file is updated by the method, the main program does not need to make corresponding modification, and the updated dynamic library file can be executed by directly calling the modified dynamic library file, so that the hot update of the golang dynamic library is changed into a file which can be conveniently called, the problem that the program must be restarted for updating the dynamic library is solved, the convenience of upgrading the program is improved, and the program development efficiency is improved.
Detailed Description
For the purpose of promoting an understanding of the principles and advantages of the disclosure, reference will now be made in detail to the drawings, in which it is apparent that the embodiments described are only some, but not all embodiments of the disclosure. Based on the embodiments in this disclosure, all other embodiments that a person of ordinary skill in the art would obtain without making any inventive effort are within the scope of protection of this disclosure.
The terminology used in the embodiments of the disclosure is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. As used in this disclosure of embodiments and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise, the "plurality" generally includes at least two.
It should be understood that the term "and/or" as used herein is merely one relationship describing the association of the associated objects, meaning that there may be three relationships, e.g., a and/or B, may represent: a exists alone, A and B exist together, and B exists alone. In addition, the character "/" herein generally indicates that the front and rear associated objects are an "or" relationship.
It should be understood that although the terms first, second, third, etc. may be used to describe … … in the presently disclosed embodiments, these … … should not be limited to these terms. These terms are only used to distinguish … …. For example, the first … … may also be referred to as the second … …, and similarly the second … … may also be referred to as the first … …, without departing from the scope of the disclosed embodiments.
The words "if", as used herein, may be interpreted as "at … …" or "at … …" or "in response to a determination" or "in response to a detection", depending on the context. Similarly, the phrase "if determined" or "if detected (stated condition or event)" may be interpreted as "when determined" or "in response to determination" or "when detected (stated condition or event)" or "in response to detection (stated condition or event), depending on the context.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a product or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such product or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a commodity or device comprising such element.
Alternative embodiments of the present disclosure are described in detail below with reference to the drawings.
As shown in fig. 1, fig. 1 illustrates a flow chart of a dynamic library hot update method according to an embodiment of the present disclosure. According to a specific embodiment of the present disclosure, the present disclosure provides a dynamic library heat updating method, which specifically includes the following method steps:
step S102: creating a folder path named at the current time.
A folder named { tmp-current time } is created before compiling, such as PluginA/tmp-20190606, pluginA/tmp-20190606/sub1, pluginA/tmp-20190606/sub2, etc.
After naming the latest tmp file path with the current time, the main program identifies the file under the latest time node when the updated plug-in is updated every time, so that the hash value table is updated simultaneously.
The time may be a specific time of day or a specific time of second, and is not particularly limited, and examples thereof are exemplified by a day.
Step S104: and traversing all files under the compiling directory, and judging whether the files are files of the specified type. The determination process is shown with reference to fig. 2.
Traversing refers to sequentially accessing each node in a tree (or graph) along a search route. The operations performed by the access node depend on the particular application problem, which may be checking the value of the node, updating the value of the node, etc. The order of access nodes is different in different traversal modes.
The traversing refers to checking file types line by line from front to back under the directory, and judging whether the checked types belong to file types needing special processing.
Wherein the specified type file is a. Go file in the golang language. And judging whether the file types are the. Go files line by line, and respectively performing different treatments according to whether the file types are the. Go files, as described below.
Wherein the file with extension of. Go is a go language source file. The golang language is a static strong type, compiled, concurrent programming language developed by Google and has garbage collection function.
Step S106: and when the file is the specified type file, modifying the import packet path of the specified type file.
Specifically, when the file is the specified type file, modifying the import packet path of the specified type file includes:
when the file is a. Go file, modifying an import package (import package) part in the code, and adding the constructed folder path into the import package path (package path). I.e. modifying the lead-in package path of the specified type of file to the folder path named at the current time, as shown in fig. 3.
Step S108: and adding the modified specified type file into the first position of the folder path.
The first location is a location where the. Go file is stored under the folder named tmp-current time, where the. Go file has been modified, including modification of the import package path, and then when the main program invokes the update dynamic library, the package file under the new path is invoked.
Step S110: and receiving a compiling instruction for the dynamic library file at the first position.
A dynamic library (DLL, dynamic Link Library), which is a library containing code and data that can be used by multiple programs simultaneously, is not an executable file. Dynamic linking provides a way for a process to call a function that does not belong to its executable code. The executable code of the functions is located in a DLL that contains one or more functions that have been compiled, linked, and stored separately from the process in which they are used. DLLs also help to share data and resources. Multiple applications can access the contents of a single DLL copy in memory at the same time. A DLL is a library that contains code and data that can be used by multiple programs simultaneously. The dynamic library is the dll suffix and the so suffix under linux.
In this step, the developer may compile the corresponding code program to be changed at the first location, where the compiled specific program is not limited, and may be any dynamic library file that needs to be dynamically loaded into the main program for execution, and compiled according to the requirements of the plug-in function.
Step S112: and loading the updated dynamic library to a specified main program to realize the updating of the dynamic library file.
And putting the compiled dynamic library into a machine operated by the program, triggering a program hot loading command, and loading a new dynamic library into the program to realize the function of updating codes under the condition that the program is not restarted.
As shown in FIG. 3, after the plug-in compilation is completed, the plug-in may be loaded into a designated calling main program, and the loading process may take the path or command that the main program called the plug-in before. When the main program needs to call the plug-in the execution process, the updated plug-in is directly called, and at the moment, the updated dynamic library file can be directly loaded without error due to the fact that the go file path of the dynamic library file is updated.
As shown in fig. 3, when the package file name is called, the package file name loads the current update time, so that the main program can confirm that the called dynamic library file is the update file at the latest time, and the hash value is updated at the same time, and the original package file and the hash value are not executed any more, so that the whole dynamic library file cannot be in error.
The hash value is a hash function, and the message or the data is compressed into a digest, so that the data quantity is reduced and fixed in the data format. And updating the dynamic library file and simultaneously updating the hash value in the dynamic library file.
Optionally, the traversing compiles all files under the directory, and determining whether the files are files of a specified type includes:
when the file is a file of a non-specified type, the file content is directly copied to a second location of the folder path.
When traversing the file directory from top to bottom, the contents under the non-goo file are directly copied to the folder directory named { tmp-current time }, for the non-goo file.
The method realizes the hot update of the golang dynamic library by modifying the compiling mode. After the dynamic library file is updated by the method, the main program does not need to make corresponding modification, and the updated dynamic library file can be executed by directly calling the modified dynamic library file, so that the hot update of the golang dynamic library is changed into a file which can be conveniently called, the problem that the program must be restarted for updating the dynamic library is solved, the convenience of upgrading the program is improved, and the program development efficiency is improved.
As shown in fig. 4, the present embodiment is a device for implementing the foregoing embodiment, and the steps of the method in the present embodiment have the same technical effects and are not described herein.
According to a specific embodiment of the present disclosure, the present disclosure provides a dynamic library heat updating apparatus, including: the creation unit 402, the judgment unit 404, the modification unit 406, the joining unit 408, the receiving unit 410, and the loading unit 412 are specifically as follows:
a creating unit 402 configured to create a folder path named at the current time.
A folder named { tmp-current time } is created by the compiler, such as, for example, pluginA/tmp-20190606, pluginA/tmp-20190606/sub1, pluginA/tmp-20190606/sub2, etc.
After naming the latest tmp file path with the current time, the main program identifies the file under the latest time node when the updated plug-in is updated every time, so that the hash value table is updated simultaneously.
And the judging unit 404 is configured to traverse all files under the compiled directory and judge whether the files are files of a specified type.
Optionally, the specified type file is a go file in a golang language.
The traversing refers to checking file types line by line from front to back under the directory, and judging whether the checked types belong to file types needing special processing.
Wherein the specified type file is a. Go file in the golang language. And judging whether the file types are the. Go files line by line, and respectively performing different treatments according to whether the file types are the. Go files, as described below.
Wherein the file with extension of. Go is a go language source file. The golang language is a static strong type, compiled, concurrent programming language developed by Google and has garbage collection function.
And a modifying unit 406 configured to modify the import packet path of the specified type file when the file is the specified type file.
Optionally, the modifying unit is further configured to:
and when the file is the specified type file, modifying the import packet path of the specified type file into the folder path named with the current time.
And a joining unit 408 configured to join the modified specified type file to the first location of the folder path.
The first location is a location where the. Go file is stored under the folder named tmp-current time, where the. Go file has been modified, including modification of the import package path, and then when the main program invokes the update dynamic library, the package file under the new path is invoked.
The receiving unit 410 is configured to receive, at the first location, a compiling instruction for a dynamic library file.
The developer may compile the corresponding code program to be changed at the first location, where the compiled specific program is not limited, and may be any dynamic library file that needs to be dynamically loaded into the main program for execution, and compiled according to the requirements of the plug-in function.
And the loading unit 412 is configured to load the updated dynamic library to the designated main program to realize the update of the dynamic library file.
As shown in fig. 3, when the package file name is called, the package file name loads the current update time, so that the main program can confirm that the called dynamic library file is the update file at the latest time, and the hash value is updated at the same time, and the original package file and the hash value are not executed any more, so that the whole dynamic library file cannot be in error.
Optionally, the method further comprises:
a copying unit (not shown) configured to directly copy the file content to the second location of the folder path when the file is a non-specified type of file.
The device realizes the hot update of the golang dynamic library by modifying the compiling mode. After the dynamic library file is updated, the main program does not need to make corresponding modification, and the updated dynamic library file can be executed by directly calling the modified dynamic library file, so that the hot update of the golang dynamic library is changed into a file which can be conveniently called, the problem that the program must be restarted when the dynamic library is updated is solved, the convenience of upgrading the program is improved, and the program development efficiency is improved.
As shown in fig. 5, the present embodiment provides an electronic device, including: at least one processor; and a memory communicatively coupled to the at least one processor; wherein, the liquid crystal display device comprises a liquid crystal display device,
the memory stores instructions executable by the one processor to enable the at least one processor to perform the method steps described in the embodiments above.
The disclosed embodiments provide a non-transitory computer storage medium storing computer executable instructions that perform the method steps described in the embodiments above.
Referring now to fig. 5, a schematic diagram of an electronic device suitable for use in implementing embodiments of the present disclosure is shown. The terminal devices in the embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and the like, and stationary terminals such as digital TVs, desktop computers, and the like. The electronic device shown in fig. 5 is merely an example and should not be construed to limit the functionality and scope of use of the disclosed embodiments.
As shown in fig. 5, the electronic device may include a processing means (e.g., a central processing unit, a graphics processor, etc.) 501, which may perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 502 or a program loaded from a storage means 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the electronic device are also stored. The processing device 501, the ROM 502, and the RAM 503 are connected to each other via a bus 505. An input/output (I/O) interface 505 is also connected to bus 505.
In general, the following devices may be connected to the I/O interface 505: input devices 506 including, for example, a touch screen, touchpad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; an output device 505 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage 508 including, for example, magnetic tape, hard disk, etc.; a communication device 505. The communication means 505 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. While fig. 5 shows an electronic device having various means, it is to be understood that not all of the illustrated means are required to be implemented or provided. More or fewer devices may be implemented or provided instead.
In particular, according to embodiments of the present disclosure, the processes described above with reference to flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the flowcharts. In such an embodiment, the computer program may be downloaded and installed from a network via communication means 505, or installed from storage means 508, or installed from ROM 502. The above-described functions defined in the methods of the embodiments of the present disclosure are performed when the computer program is executed by the processing device 501.
It should be noted that the computer readable medium described in the present disclosure may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having 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. In the context of this disclosure, a computer-readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present disclosure, however, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, fiber optic cables, RF (radio frequency), and the like, or any suitable combination of the foregoing.
The computer readable medium may be contained in the electronic device; or may exist alone without being incorporated into the electronic device.
Computer program code for carrying out operations of the present disclosure may be written in one or more programming languages, including an object oriented programming language such as Java, smalltalk, C ++ and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computer (for example, through the Internet using an Internet service provider).
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units involved in the embodiments of the present disclosure may be implemented by means of software, or may be implemented by means of hardware. Wherein the names of the units do not constitute a limitation of the units themselves in some cases.