SPI (Serial Peripheral Interface)-based configuration data source configuration method, system, equipment and medium

Through the SPI-based configuration data source configuration method, the data source implementation class is dynamically loaded, which solves the problem of increasing complexity of data source types in traditional methods, and improves system flexibility and maintainability.

CN119883428APending Publication Date: 2025-04-25BEIJING HUANENG XINRUI CONTROL TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510077548.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-17
Publication Date
2025-04-25

AI Technical Summary

Technical Problem

Traditional methods require different data access code for each data source, which increases development complexity and reduces system flexibility and maintainability.

Method used

The configuration data source configuration method based on SPI is adopted to obtain the data source type through configuration files, and the corresponding data source implementation class is loaded using SPI to dynamically obtain data, thereby improving the flexibility and maintainability of the system.

Benefits of technology

Adding or changing data source types without modifying code increases system flexibility and maintainability and simplifying deployment and maintenance processes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119883428A_ABST
    Figure CN119883428A_ABST
Patent Text Reader

Abstract

The invention discloses an SPI (Serial Peripheral Interface)-based configuration data source configuration method, system and device and a medium. The SPI-based configuration data source configuration method comprises the following steps: acquiring a configuration file; acquiring a receiving request, and querying a data source address to which a measuring point belongs from a database of the configuration system according to the measuring point information in the receiving request; reading a data source type corresponding to the data source address from a configuration file; according to the method, the system, the equipment and the medium, the corresponding data source implementation class is loaded through the SPI according to the data source type, then the getData method is called to obtain the data, then the obtained data is output, and the method, the system, the equipment and the medium can improve the flexibility and maintainability of the system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of data processing and configuration, and relates to a configuration data source configuration method, system, equipment and medium based on SPI. Background Art

[0002] In modern industrial and information systems, configuration systems (SCADA, Supervisory Control and Data Acquisition) are used to monitor and control various devices and processes. Configuration systems usually need to interact with multiple underlying data sources, such as real-time databases, MySQL, Redis, etc. These data sources store the time series data or attribute data of different measuring points respectively, and the underlying data source corresponding to each measuring point is configured in the database of the configuration system. Since different data sources have different interfaces and data access logic, the traditional method requires writing different data access codes for each data source, which not only increases the development complexity, but also reduces the flexibility and maintainability of the system. Summary of the invention

[0003] The purpose of the present invention is to overcome the shortcomings of the above-mentioned prior art and provide a method, system, device and medium for configuring a configuration data source based on SPI, which can improve the flexibility and maintainability of the system.

[0004] To achieve the above object, the present invention discloses a configuration data source configuration method based on SPI, comprising:

[0005] Get the configuration file;

[0006] Obtaining a receiving request, and querying a data source address to which the measuring point belongs from a database of a configuration system according to the measuring point information in the receiving request;

[0007] Read the data source type corresponding to the data source address from the configuration file;

[0008] According to the data source type, the corresponding data source implementation class is loaded through SPI, and then the getData method is called to obtain data, and then the obtained data is output.

[0009] A further improvement of the SPI-based configuration data source configuration system of the present invention is:

[0010] Furthermore, the database of the configuration system stores the underlying data source configuration information corresponding to each measuring point, and the underlying data source configuration information includes the data source type and connection parameters.

[0011] Furthermore, it also includes:

[0012] According to the mapping relationship between the URL and the data source type in the configuration file, the corresponding data source implementation class is dynamically loaded.

[0013] Furthermore, it also includes:

[0014] When the system starts, if dataSourceMap is not initialized, the initDataSourceMap() method is called to use ServiceLoader to load all data source classes registered with @AutoService annotation when dataSourceMap is accessed for the first time, and store the data source classes in dataSourceMap;

[0015] Call the DataSource.getDataSourceByName method to obtain the corresponding data source instance from the dataSourceMap according to the simple class name of the data source. If the corresponding data source instance is not found in the dataSourceMap, the default abstract DataSource instance is returned.

[0016] The present invention discloses a configuration data source configuration system based on SPI, comprising:

[0017] A first acquisition module, used to acquire a configuration file;

[0018] A second acquisition module is used to acquire a receiving request, and query the data source address to which the measuring point belongs from the database of the configuration system according to the measuring point information in the receiving request;

[0019] A reading module, used for reading the data source type corresponding to the data source address from a configuration file;

[0020] The configuration module is used to load the corresponding data source implementation class through SPI according to the data source type, then call the getData method to obtain data, and then output the obtained data.

[0021] A further improvement of the SPI-based configuration data source configuration system of the present invention is:

[0022] Furthermore, the database of the configuration system stores the underlying data source configuration information corresponding to each measuring point, and the underlying data source configuration information includes the data source type and connection parameters.

[0023] Furthermore, it also includes:

[0024] According to the mapping relationship between the URL and the data source type in the configuration file, the corresponding data source implementation class is dynamically loaded.

[0025] Furthermore, it also includes:

[0026] When the system starts, if dataSourceMap is not initialized, the initDataSourceMap() method is called to use ServiceLoader to load all data source classes registered with @AutoService annotation when dataSourceMap is accessed for the first time, and store the data source classes in dataSourceMap;

[0027] Call the DataSource.getDataSourceByName method to obtain the corresponding data source instance from the dataSourceMap according to the simple class name of the data source. If the corresponding data source instance is not found in the dataSourceMap, the default abstract DataSource instance is returned.

[0028] The invention discloses a computer device, comprising a memory, a processor and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the SPI-based configuration data source configuration method are implemented.

[0029] The invention discloses a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the SPI-based configuration data source configuration method are implemented.

[0030] The present invention has the following beneficial effects:

[0031] The SPI-based configuration data source configuration method, system, device and medium described in the present invention can dynamically load the data source through the SPI mechanism during specific operation. When adding or changing the data source type, there is no need to modify the code, only the configuration file needs to be updated, so as to improve the flexibility and maintainability of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] The accompanying drawings constituting a part of the present invention are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the accompanying drawings:

[0033] Figure 1 It is a structural diagram of the present invention. DETAILED DESCRIPTION

[0034] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0035] In the description of the present invention, it should be understood that the terms “include” and “comprises” indicate the presence of described features, wholes, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or collections thereof.

[0036] It should also be understood that the terms used in the present specification are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the present specification and the appended claims, the singular forms "a", "an" and "the" are intended to include plural forms unless the context clearly indicates otherwise.

[0037] It should be further understood that the term "and / or" used in the present specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes these combinations. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in the present invention generally indicates that the associated objects are in an "or" relationship.

[0038] It should be understood that, although the terms first, second, third, etc. may be used to describe preset ranges, etc. in the embodiments of the present invention, these preset ranges should not be limited to these terms. These terms are only used to distinguish preset ranges from each other. For example, without departing from the scope of the embodiments of the present invention, the first preset range may also be referred to as the second preset range, and similarly, the second preset range may also be referred to as the first preset range.

[0039] The word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)", depending on the context.

[0040] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. The components of the embodiments of the present invention described and shown in the drawings here can usually be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the claimed invention, but merely represents selected embodiments of the present invention. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0041] Various structural schematic diagrams of the embodiments disclosed in the present invention are shown in the accompanying drawings. These figures are not drawn to scale, and some details are magnified and some details may be omitted for the purpose of clear expression. The shapes of various regions and layers shown in the figures and the relative sizes and positional relationships therebetween are only exemplary, and may deviate in practice due to manufacturing tolerances or technical limitations, and those skilled in the art may additionally design regions / layers with different shapes, sizes, and relative positions according to actual needs.

[0042] Embodiment 1

[0043] The SPI-based configuration data source configuration method of the present invention comprises the following steps:

[0044] 1)Configure data source configuration

[0045] The database of the configuration system stores the underlying data source configuration information corresponding to each measuring point, and the underlying data source configuration information includes the data source type and connection parameters, such as URL, host, user name and password.

[0046] 2) Design data source interface

[0047] Assume an abstract DataSource class from which all concrete data source classes inherit. The abstract class includes two main methods:

[0048] a)getData(Map<String,String> params,Collection <metricnumberandtime>metrics) / / Method for obtaining data.

[0049] b)putData(Map<String,String> params,Map <String,Collection <metricvalue>>values) / / Method for writing data.

[0050] 3) SPI mechanism

[0051] Using Java's SPI mechanism, specify the specific data source implementation class through the configuration file. Specifically, the data source class is registered through the @AutoService(value=DataSource.class) annotation. @AutoService is an annotation provided by Google to simplify the registration process of SPI services. With this annotation, developers do not need to manually create

[0052] META-INF / services file, but automatically generates the corresponding service file through annotations.

[0053] 4) Loading and instantiation of data sources

[0054] The instantiation of the data source is realized through SPI loading. When obtaining data, there is no need to instantiate the data source class every time. The system dynamically loads the corresponding data source implementation class according to the mapping relationship between the URL and the data source type in the configuration file.

[0055] Specifically, the following steps are included:

[0056] 1) Create a configuration file

[0057] The configuration file is used to define the mapping relationship between data sources.

[0058] For example:

[0059] datasource:

[0060] map:

[0061] "[http: / / 192.168.0.1:9999 / DataById]":

[0062] RealtimeInterfaceDataSource / / defines

[0063] The data source type corresponding to the address http: / / 192.168.0.1:9999 / DataById is RealtimeInterfaceDataSource

[0064] "[192.168.1.2:6666]":OpenPlantDataSource / / Defines

[0065] The data source type corresponding to the address 192.168.1.2:6666 is

[0066] OpenPlantDataSource

[0067] "[http: / / 192.168.2.3:3333 / dimension / query / queryAttributeValues]":AttributeDataSource / / Defines

[0068] The data source type corresponding to the address http: / / 192.168.2.3:3333 / dimension / query / queryAttributeValues ​​is AttributeDataSource

[0069] 2) Read and write logic

[0070] Get the receiving request, query the data source address to which the measuring point belongs from the database according to the measuring point information in the receiving request, then read the data source type corresponding to the data source address from the configuration file, then load the corresponding data source implementation class through SPI, call the getData method to obtain data, and return the obtained data to the caller.

[0071] 3) Implementation of data source class

[0072] Different data source classes inherit from the DataSource abstract class and implement their own getData and putData methods. For example:

[0073] @AutoService(DataSource.class) / / SPI related annotations

[0074] public class OpenPlantDataSource extends DataSource{

[0075] @Override / / Implement parent class method

[0076] Public Map <String,Collection <metricvalue>>

[0077] getData(Map<String,String>params,

[0078] Collection <metricnumberandtime>metrics){

[0079] / / Implement the logic of obtaining data from the OpenPlant data source

[0080] }

[0081] @Override / / Implement parent class method

[0082] public void putData(Map<String,String> params,Map <String,Collection <metricvalue>>values){

[0083] / / Implement the logic of writing data to the OpenPlant data source

[0084] }

[0085] }

[0086] 4) Data source loading process

[0087] 41) Initialization:

[0088] When the system starts, dataSourceMap is not initialized. When dataSourceMap is accessed for the first time, the initDataSourceMap() method is called.

[0089] The initDataSourceMap() method uses ServiceLoader to load all

[0090] @AutoService annotates the registered data source class and stores the data source class in dataSourceMap.

[0091] 42) Lazy loading:

[0092] Lazy loading is a design pattern that initializes objects only when they are actually needed. In the data source loading process, lazy loading is used to ensure that the data source map (dataSourceMap) is initialized only when it is first accessed. When the dataSourceMap is first accessed, the initDataSourceMap() method is called to use ServiceLoader to load all classes that implement the DataSource interface and store them in the dataSourceMap.

[0093] 43) Get the data source instance

[0094] Call the DataSource.getDataSourceByName(String simpleName) method to get the corresponding data source instance from the dataSourceMap according to the simple class name of the data source. When dataSourceMap is not initialized, call initDataSourceMap() to initialize it. When the corresponding instance is not found in the dataSourceMap, the default abstract DataSource instance is returned. Among them, the getDataSourceByName method is used to get the corresponding data source instance from the dataSourceMap according to the simple class name of the data source; when the corresponding instance is not found, the default abstract DataSource instance is returned.

[0095] The present invention has the following characteristics:

[0096] 1) Flexibility: Through the SPI mechanism, the implementation of the data source can be loaded dynamically. When adding or changing the data source type, there is no need to modify the code, only the configuration file needs to be updated.

[0097] 2) Maintainability: The access logic of different data sources is abstracted into a unified interface, achieving code modularization and reuse.

[0098] 3) Performance optimization: Lazy loading and reuse of data source instances avoid instantiating the data source class for each request, improving system performance.

[0099] 4) Flexible configuration: The data source mapping relationship is specified through the configuration file, so that the system can flexibly configure the data source type and connection parameters during private deployment to adapt to different environments and requirements.

[0100] 5) Convenient private deployment: The solution of the present invention can adapt to different private deployment scenarios. Users can flexibly configure different data sources according to actual conditions without modifying the system code, thereby greatly simplifying the complexity of deployment and maintenance.

[0101] Embodiment 2

[0102] The SPI-based configuration data source configuration system of the present invention comprises:

[0103] A first acquisition module, used to acquire a configuration file;

[0104] A second acquisition module is used to acquire a receiving request, and query the data source address to which the measuring point belongs from the database of the configuration system according to the measuring point information in the receiving request;

[0105] A reading module, used for reading the data source type corresponding to the data source address from a configuration file;

[0106] The configuration module is used to load the corresponding data source implementation class through SPI according to the data source type, then call the getData method to obtain data, and then output the obtained data.

[0107] In one implementation mode of the present invention, the database of the configuration system stores the underlying data source configuration information corresponding to each measuring point, and the underlying data source configuration information includes the data source type and connection parameters.

[0108] One embodiment of the present invention further includes:

[0109] According to the mapping relationship between the URL and the data source type in the configuration file, the corresponding data source implementation class is dynamically loaded.

[0110] One embodiment of the present invention further includes:

[0111] When the system starts, if dataSourceMap is not initialized, the initDataSourceMap() method is called to use ServiceLoader to load all data source classes registered with @AutoService annotation when dataSourceMap is accessed for the first time, and store the data source classes in dataSourceMap;

[0112] Call the DataSource.getDataSourceByName method to obtain the corresponding data source instance from the dataSourceMap according to the simple class name of the data source. If the corresponding data source instance is not found in the dataSourceMap, the default abstract DataSource instance is returned.

[0113] The division of modules in the embodiments of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation. In addition, each functional module in each embodiment of the present application may be integrated into a processor, or may exist physically separately, or two or more modules may be integrated into one module. The above-mentioned integrated modules may be implemented in the form of hardware or in the form of software functional modules.

[0114] Embodiment 3

[0115] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the configuration method for configuring a data source based on SPI are implemented, for example, including: obtaining a configuration file; obtaining a receiving request, and querying the data source address to which the measuring point belongs from the database of the configuration system according to the measuring point information in the receiving request; reading the data source type corresponding to the data source address from the configuration file; loading the corresponding data source implementation class through SPI according to the data source type, and then calling the getData method to obtain data, and then outputting the obtained data. The memory may include a memory, such as a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk memory, etc. The processor, the network interface, and the memory are interconnected through an internal bus, and the internal bus may be an industrial standard architecture bus, a peripheral component interconnection standard bus, an extended industrial standard structure bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. The memory is used to store programs. Specifically, the program may include a program code, and the program code includes computer operation instructions. The memory may include a memory and a non-volatile memory, and provide instructions and data to the processor.

[0116] Embodiment 4

[0117] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the configuration method of the SPI-based configuration data source are implemented, for example, including: obtaining a configuration file; obtaining a receiving request, and querying the data source address to which the measuring point belongs from the database of the configuration system according to the measuring point information in the receiving request; reading the data source type corresponding to the data source address from the configuration file; according to the data source type, loading the corresponding data source implementation class through SPI, and then calling the getData method to obtain data, and then outputting the obtained data. Specifically, the computer-readable storage medium includes, but is not limited to, for example, volatile memory and / or non-volatile memory. The volatile memory may include random access memory (RAM) and / or cache memory (cache), etc. The non-volatile memory may include read-only memory (ROM), hard disk, flash memory, optical disk, magnetic disk, etc.

[0118] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0119] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0120] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0121] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0122] Those skilled in the art will readily appreciate other embodiments of the present invention after considering the specification and disclosure of the invention. This application is intended to cover any variations, uses or adaptations of the present invention that follow the general principles of the present invention and include common knowledge or customary techniques in the art that are not disclosed by the present invention. The specification and examples are to be considered exemplary only, and the true scope and spirit of the present invention are indicated by the following claims.

[0123] It should be understood that the present invention is not limited to the exact construction that has been described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the present invention is limited only by the appended claims.

[0124] The above description is only a preferred embodiment of the present invention and does not limit the present invention in any way. Any simple modification, change and equivalent structural change made to the above embodiment based on the technical essence of the present invention still falls within the protection scope of the technical solution of the present invention.< / metricvalue> < / metricnumberandtime> < / metricvalue> < / metricvalue> < / metricnumberandtime>

Claims

1. A configuration data source configuration method based on SPI, characterized in that: include: Get the configuration file; Obtaining a receiving request, and querying a data source address to which the measuring point belongs from a database of a configuration system according to the measuring point information in the receiving request; Read the data source type corresponding to the data source address from the configuration file; According to the data source type, the corresponding data source implementation class is loaded through SPI, and then the getData method is called to obtain data, and then the obtained data is output.

2. The SPI-based configuration data source configuration method according to claim 1, characterized in that: The database of the configuration system stores the underlying data source configuration information corresponding to each measuring point, and the underlying data source configuration information includes the data source type and connection parameters.

3. The SPI-based configuration data source configuration method according to claim 1, characterized in that: Also includes: According to the mapping relationship between the URL and the data source type in the configuration file, the corresponding data source implementation class is dynamically loaded.

4. The SPI-based configuration data source configuration method according to claim 1, characterized in that: Also includes: When the system starts, if dataSourceMap is not initialized, the initDataSourceMap() method is called to use ServiceLoader to load all data source classes registered with @AutoService annotation when dataSourceMap is accessed for the first time, and store the data source classes in dataSourceMap; Call the DataSource.getDataSourceByName method to obtain the corresponding data source instance from the dataSourceMap according to the simple class name of the data source. If the corresponding data source instance is not found in the dataSourceMap, the default abstract DataSource instance is returned.

5. A configuration data source configuration system based on SPI, characterized in that: include: A first acquisition module, used to acquire a configuration file; A second acquisition module is used to acquire a receiving request, and query the data source address to which the measuring point belongs from the database of the configuration system according to the measuring point information in the receiving request; A reading module, used for reading the data source type corresponding to the data source address from a configuration file; The configuration module is used to load the corresponding data source implementation class through SPI according to the data source type, then call the getData method to obtain data, and then output the obtained data.

6. The SPI-based configuration data source configuration system according to claim 5, characterized in that: The database of the configuration system stores the underlying data source configuration information corresponding to each measuring point, and the underlying data source configuration information includes the data source type and connection parameters.

7. The SPI-based configuration data source configuration system according to claim 5, characterized in that: Also includes: According to the mapping relationship between the URL and the data source type in the configuration file, the corresponding data source implementation class is dynamically loaded.

8. The SPI-based configuration data source configuration system according to claim 5, characterized in that: Also includes: When the system starts, if dataSourceMap is not initialized, the initDataSourceMap() method is called to use ServiceLoader to load all data source classes registered with @AutoService annotation when dataSourceMap is accessed for the first time, and store the data source classes in dataSourceMap; Call the DataSource.getDataSourceByName method to obtain the corresponding data source instance from the dataSourceMap according to the simple class name of the data source. If the corresponding data source instance is not found in the dataSourceMap, the default abstract DataSource instance is returned.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the SPI-based configuration data source configuration method as described in any one of claims 1 to 4 are implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the SPI-based configuration data source configuration method as claimed in any one of claims 1 to 4 are implemented.