Disclosure of Invention
In a first aspect, an embodiment of the present application provides a program construction method, applied to an electronic device, where the method includes:
Acquiring a configuration file of a target program, wherein the configuration file records identification information of each functional module required by the target program and configuration information of each functional module;
Analyzing the configuration file to obtain identification information of each functional module and configuration information of each functional module;
And generating service examples of the function modules in the memory according to the configuration information of the function modules and the identification information of the function modules for each function module.
In one possible implementation manner, monitoring whether new configuration information is added to the configuration file, wherein the new configuration information corresponds to a new functional module;
If yes, generating a new service instance in the memory according to the new configuration information, wherein the new service instance corresponds to the new functional module.
In one possible implementation manner, the method further includes, before generating the service instance of the function module in the memory according to the identification information of the function module and the configuration information of the function module, the method further includes:
Detecting whether a service instance of the functional module exists in a memory or not;
if yes, the functional module is ignored.
In one possible implementation manner, the generating, in a memory, a service instance of the function module according to the identification information of the function module and configuration information of the function module includes:
determining instruction data of the functional module according to the identification information of the functional module, wherein the instruction data comprises computer executable instructions for realizing service functions corresponding to the functional module;
initializing module attributes corresponding to the configuration information in the instruction data according to the configuration information of the functional module;
and loading the initialized instruction data into a memory to generate a service instance of the functional module.
In one possible implementation manner, the functional modules include a first functional module and a second functional module, where the first functional module belongs to a first level, the second functional module belongs to a second level, and the functional module corresponding to the second level is constructed based on the functional module corresponding to the first level.
In one possible implementation manner, before the obtaining the configuration file of the target program, the method further includes:
Providing a configuration interface;
responding to a first configuration operation of the configuration interface, and obtaining a target industry to which the target program belongs;
Providing module identification of candidate function modules according to the target industry, wherein the candidate function modules belong to the target industry;
and generating the configuration file in response to a second configuration operation of the configuration interface.
In a possible implementation manner, the electronic device is configured with an association relationship between the candidate function modules, and the generating the configuration file in response to the second configuration operation of the configuration interface includes:
determining a selected functional module in response to a module selection operation of the configuration interface;
For the functional module, responding to module configuration operation in the configuration interface, and obtaining configuration information of the functional module;
According to the association relation, determining candidate function modules associated with the function modules;
Displaying module identifiers of candidate function modules associated with the function modules on the configuration interface;
And responding to file generation operation in the configuration interface, and generating the configuration file according to the configuration information and the module identification of all the functional modules.
In a second aspect, an embodiment of the present application provides a program construction device including:
the configuration acquisition module is used for acquiring a configuration file of a target program, wherein the configuration file records identification information of each functional module, architecture information among the functional modules and configuration information of each functional module required by the target program;
the configuration analysis module is used for analyzing the configuration file and acquiring the identification information, the architecture information and the configuration information;
And the instance generating module is used for generating service instances of the function modules in the memory according to the identification information of the function modules and the architecture information of the function modules and the configuration information of the function modules for each function module.
In a third aspect, an embodiment of the present application provides an electronic device, where the electronic device includes a processor and a memory, where the memory stores a computer program, and where the program construction method is implemented when computer executable instructions in the computer program are executed by the processor.
In a fourth aspect, an embodiment of the present application provides a storage medium storing a computer program, where computer executable instructions in the computer program implement the program construction method when executed by a processor.
Compared with the prior art, the application has the following beneficial effects:
in the program construction method, the device, the electronic equipment and the storage medium provided by the embodiment of the application, the electronic equipment generates service examples of all the functional modules in the memory based on the configuration file of the target program according to the configuration information of all the functional modules in the configuration file. Because each functional module can provide independent service functions, the functions of the existing functional modules can be multiplexed through the configuration file, and therefore development efficiency can be improved.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the technical solutions of the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application, and it is apparent that the described embodiments are some embodiments of the present application, but not all embodiments of the present application. The components of the embodiments of the present application generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations.
Thus, the following detailed description of the embodiments of the application, as presented in the figures, is not intended to limit the scope of the application, as claimed, but is merely representative of selected embodiments of the application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
It should be noted that: like reference numerals and letters denote like items in the following figures, and thus once an item is defined in one figure, no further definition or explanation thereof is necessary in the following figures.
In the related art, different designs are required to be made on the software according to different services, however, certain commonalities exist among different services, so that repeated development is performed on the software according to different services, and the development efficiency is poor.
In view of the above, an embodiment of the present application provides a program construction method applied to an electronic device. The electronic equipment configures the existing functional module through the configuration file, and generates a service instance corresponding to the functional module according to the configuration information in the configuration file so as to achieve the purpose of multiplexing the functions of the existing functional module.
The electronic device may be, but is not limited to, a server, a personal computer (Personal Computer, PC), an intelligent terminal, etc.
In addition, referring to fig. 1, fig. 1 is a schematic diagram of a possible structure of the electronic device. The electronic device comprises a memory 120, a processor 130, a communication means 140.
The memory 120, the processor 130, and the communication device 140 are electrically connected directly or indirectly to each other to realize data transmission or interaction. For example, the components may be electrically connected to each other via one or more communication buses or signal lines.
The Memory 120 may be, but is not limited to, random access Memory (Random Access Memory, RAM), read Only Memory (ROM), programmable Read Only Memory (Programmable Read-Only Memory, PROM), erasable Read Only Memory (Erasable Programmable Read-Only Memory, EPROM), electrically erasable Read Only Memory (Electric Erasable Programmable Read-Only Memory, EEPROM), etc. The memory 120 is used for storing a program, and the processor 130 executes the program after receiving an execution instruction. The communication device 140 is used for transmitting and receiving data through a network.
The processor 130 may be an integrated circuit chip with signal processing capabilities. The processor may be a general-purpose processor, including a central processing unit (Central Processing Unit, abbreviated as CPU), a network processor (Network Processor, abbreviated as NP), etc.; but also Digital Signal Processors (DSPs), application Specific Integrated Circuits (ASICs), field Programmable Gate Arrays (FPGAs) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The disclosed methods, steps, and logic blocks in the embodiments of the present application may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
Referring to fig. 2, fig. 2 is a flowchart of a program construction method applied to the electronic device shown in fig. 1, and the method includes steps described in detail below. As shown in fig. 2, the program construction method includes:
step S101, a configuration file of the target program is acquired.
The configuration file records identification information of each functional module and configuration information of each functional module required by the target program.
The number of the functional modules can be one or more, and the functional modules depend on the business complexity of the target program. Each functional module is a program module which is developed in advance by a developer aiming at a specific service function, and the program module can independently run in a thread or process mode. Of course, the functional modules are combined with each other to form a new functional module, and the new functional module is operated in a thread or process mode. Alternatively, the target program may be an application program running on the server side.
Step S102, analyzing the configuration file to obtain the identification information of each functional module and the configuration information of each functional module.
It should be appreciated that in embodiments of the present application, the program architecture is divided into at least five layers. As shown in fig. 3, may include an application interface layer, a business layer, a logic layer, a core layer, and a platform abstraction layer.
The application interface layer is an external function outlet, and the platform abstraction layer is a part related to a specific platform and is used for isolating specific platform differences (for example, a linux operating system platform and a windows operating system platform). The application interface layer and the platform abstract layer comprise a business layer, a logic layer and a core layer, wherein the core layer is used for realizing a part of specific functions.
The core layer is used to provide the lowest level of functionality, encapsulate the most basic network communications, log printing, and some of the functionality to provide the most basic support to the upper layers.
The logic layer is to implement some simple logic by combining part of functional modules of the bottom layer (for example, the core layer), for example, implementing connection under different network protocols to abstract, and to unify network communication modes, etc., where the part is an independent part with similar components and has perfect state management function.
The service layer is an implementation part for combining the logic layer according to the service, and is a high-level representation of the service, that is, the functions required by the end user are combined in the layer, and the functions are issued to the outside through the application interface layer.
In the concept understanding, the middle three layers are the whole subdivision process, can be unified into a service layer, and can more clearly define the relation of each part and independently divide the functions and the specific implementation under the condition of complex codes.
In the embodiment of the application, the configuration file may be an XML (Extensible Markup Language extensible markup language) format configuration file. For example, the configuration file may describe the target program in the following manner:
<product>
<name>ProductA</name>
<parts>
<part name="Partl"type="TypeA">
<version>Version1.0</version>
<connection>ConnectionA</connection>
</part>
</parts>
<connections>
<connection name="ConnectionA"type="TCP">
<ip>192.168.1.125</ip>
<port>6666</port>
<protocol>http</protocot>
</connection>
</connections>
</product>
In the configuration file ProductA indicates the name of the target program, and the tag < parts > </parts > is used for recording the function module required by the target program. The configuration accessory indicates that the target program needs a functional module of connection, and is named ConnectionA, and is specifically used for performing network connection. In the corresponding configuration information, the network address is 192.168.1.125, the port number is 6666, and the communication protocol is http (HyperText Transfer Protocol ) protocol.
Based on the configuration file, when the service instance is generated, the service instance is mapped to the code layer according to the hierarchical relation represented by the configuration file. As shown in fig. 4, a schematic structure of mapping the configuration file to the code layer is shown. Since the above object program is based on the computer language Java, as shown in fig. 4, the function module Connection is a specific implementation of the interface Iconnection in Java, and Part is a specific implementation of the interface IPart in Java.
In the embodiment of the present application, the functional modules of the target program may include a first functional module and a second functional module, where the first functional module belongs to a first level, the second functional module belongs to a second level, and the functional module corresponding to the second level is constructed based on the functional module corresponding to the first level.
Also taking the above configuration file as an example, the Product actually belongs to the service layer, and the Connection belongs to the logic layer, namely the second level; the Product may also include functional modules of the core layer, i.e. the first hierarchy. Therefore, although the logical layer is built based on the core layer, each functional module is not limited to the same hierarchy in building the Product of the business layer.
That is, the configuration file is an abstract representation of the above hierarchical relationship, and the representation is materialized into the memory during the process of generating the service instance, thereby completing the construction of the target program. The service function can be completed by only adding the combined logic codes of the interface layer and the service layer without repeated development. Thus, the program construction method further includes:
step S103, for each functional module, generating service examples of the functional modules in the memory according to the identification information of the functional module and the configuration information of the functional module.
Because each functional module is a program module developed in advance for a developer aiming at a specific service function, namely, each functional module corresponds to a corresponding computer executable instruction, the electronic equipment determines instruction data of the functional module according to the identification information of the functional module.
The electronic equipment initializes module attributes corresponding to the configuration information in the instruction data according to the configuration information of the functional module; and loading the initialized instruction data into a memory to generate a service instance of the functional module.
By the method, the electronic equipment generates service examples of the functional modules in the memory according to the configuration information of the functional modules in the configuration file based on the configuration file of the target program. Because each functional module can provide independent service functions, the functions of the existing functional modules can be multiplexed through the configuration file, and therefore development efficiency can be improved.
In addition, in the embodiment of the application, a new functional module can be dynamically added. The electronic equipment monitors whether the configuration file is changed in real time, and new configuration information is added once the configuration file is monitored; and generating a new service instance in the memory according to the new configuration information, wherein the new configuration information corresponds to the new functional module, and the new service instance corresponds to the new functional module. I.e. the electronic device provides service functions to the outside through the new service instance.
As a possible implementation manner of the above functional module, the above functional module may be implemented based on Java, which is a reflection mechanism of Java when a new functional module is dynamically loaded.
Therefore, in the embodiment of the application, when a new functional module is added, the target program does not need to be stopped, and dynamic addition can be performed.
In addition, in the embodiment of the present application, in consideration of the need to reduce redundancy of the function module as much as possible, in step S103, the electronic device detects whether the service instance of the function module already exists in the memory before generating the service instance of the function module in the memory according to the configuration information of the function module and the identification information of the function module; if yes, the functional module is ignored.
In the embodiment of the application, before the electronic equipment generates the service instance, once the same service instance exists in the memory, the functional module is ignored, and the corresponding service instance is not created.
Because of the same certain difference between the business demands among different industries, the electronic equipment provides a configuration interface in the embodiment of the application for facilitating the screening of the functional modules by users. Wherein, the configuration interface is provided with a text input box for a user to input the industry (such as logistics industry, fresh industry, electronic commerce industry, food industry and the like) to which the target program belongs. Of course, the electronic device may also provide preset industry options for selection by the user.
The electronic equipment responds to a first configuration operation of a configuration interface to obtain a target industry to which a target program belongs; and providing module identification of the candidate functional modules according to the target industry, wherein the candidate functional modules belong to the target industry. Thus, the module identifications of the plurality of candidate function modules are displayed in the configuration interface. The user can browse the configuration interface, select a function module for constructing the target program from the candidate function modules, and configure the selected function module.
Thus, the electronic device generates a configuration file in response to a second configuration operation of the configuration interface.
The second configuration operation specifically includes a module selection operation, a module configuration operation, and a file generation operation.
Based on the configuration interface, the electronic device may also determine a selected functional module in response to a module configuration operation of the configuration interface; because the electronic equipment displays the module identification of the candidate functional modules of the industry to which the target program belongs through the configuration interface, a user can select the functional modules required for constructing the target program from the module identification.
And aiming at the selected functional module, responding to the module configuration operation in the configuration interface to obtain the configuration information of the functional module.
In the embodiment of the application, in order to improve the screening efficiency of the candidate modules by the user, the electronic equipment is configured with the association relation among the candidate modules. The association represents the frequent simultaneous use between different candidate modules. Therefore, the electronic equipment determines candidate function modules associated with the function modules according to the association relation; and module identifiers of candidate function modules associated with the function modules are displayed on a configuration interface.
For example, the log function module is typically used with a file read/write module or a database access module, so that when the user selects the log function module, the electronic device provides an area in the configuration interface that displays the module identification of the file read/write module, the database access module associated with the log function module.
Similarly, the data reporting module is typically used with the chart module, so that, if the user selects the data reporting module, an area is provided in the configuration interface to display the module identifier of the chart module.
And finally, the electronic equipment responds to file generation operation in the configuration interface, and generates configuration files according to the configuration information and the module identifications of all the functional modules.
In addition, it should be noted that, the user may also manually edit the configuration file according to the above grammar rule of the configuration file to generate the configuration file.
Referring to fig. 5, based on the same inventive concept, an embodiment of the present application further provides a program construction device, which includes at least one functional module that may be stored in a memory in a software form. Functionally divided, the program construction means may include:
The configuration obtaining module 1101 is configured to obtain a configuration file of the target program, where the configuration file records identification information of each function module, architecture information between each function module, and configuration information of each function module required by the target program.
In the embodiment of the present application, when the computer executable instructions in the configuration obtaining module 1101 are executed by the processor, the step S101 in fig. 2 is implemented, and for the detailed description of the configuration obtaining module 1101, reference may be made to the detailed description of the step S101.
The configuration parsing module 1102 is configured to parse the configuration file to obtain identification information, architecture information and configuration information.
In the embodiment of the present application, when the computer executable instructions in the configuration parsing module 1102 are executed by the processor, the step S102 in fig. 2 is implemented, and for the detailed description of the configuration parsing module 1102, reference may be made to the detailed description of the step S102.
The instance generating module 1103 is configured to generate, for each function module, a service instance of the function module in the memory according to the identification information of the function module and the architecture information of the function module and the configuration information of the function module.
In the embodiment of the present application, when the computer executable instructions in the instance generating module 1103 are executed by the processor, the step S103 in fig. 2 is implemented, and for the detailed description of the instance generating module 1103, reference may be made to the detailed description of the step S103.
The embodiment of the application also provides electronic equipment, which comprises a processor and a memory, wherein the memory stores a computer program, and a program construction method is realized when computer executable instructions in the computer program are executed by the processor.
The embodiment of the application also provides a storage medium, and the storage medium stores a computer program, and when computer executable instructions in the computer program are executed by a processor, a program construction method is realized.
In summary, in the program construction method, apparatus, electronic device and storage medium provided in the embodiments of the present application, the electronic device generates service instances of each functional module in a memory according to configuration information of each functional module in a configuration file of a target program. Because each functional module can provide independent service functions, the functions of the existing functional modules can be multiplexed through the configuration file, and therefore development efficiency can be improved.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other manners. The apparatus embodiments described above are merely illustrative, for example, of the flowcharts and block diagrams in the figures that illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present application. 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.
In addition, functional modules in the embodiments of the present application may be integrated together to form a single part, or each module may exist alone, or two or more modules may be integrated to form a single part.
The functions, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a usb disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, 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 process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The above description is merely illustrative of various embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily think about variations or substitutions within the scope of the present application, and the application is intended to be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.