Method and device for adapting external dependency service
Through dynamic proxy and reflection mechanism, the automation of interface adaptation is achieved, solving the problem of large workload and stability challenges of dependant interface switching in the existing technology, and improving the flexibility and scalability of the system.
Patent Information
- Application Number
- CN202311473791.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-07
- Publication Date
- 2025-05-09
AI Technical Summary
After the application architecture is upgraded, the dependencies need to switch interfaces, resulting in large workloads and stability challenges. Traditional adapter solutions increase code complexity and configuration complexity.
Through dynamic proxy and reflection mechanisms, we create adaptation policy interfaces and adapter classes, dynamically generate proxy classes and call adapter methods to achieve adaptation of the target interface.
It realizes automation of interface adaptation, reduces code complexity and configuration complexity, improves flexibility and scalability, and reduces development and maintenance workload.
Smart Images

Figure CN119960815A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for adapting external dependent services. Background Art
[0002] In the prior art, after the application architecture is upgraded, it is necessary to switch the service provider that depends on the application to a new application interface service, and then complete the replacement of the old application with the new application.
[0003] However, in the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art: the dependent parties are required to carry out corresponding modifications, which poses certain challenges to the workload and the stability of their applications; the dependent parties need to be encouraged to switch interfaces, but this part of the work is difficult to advance; if the switching time is prolonged, it will lead to the coexistence of new and old applications, and the workload of daily maintenance and new function development will be doubled.
[0004] The disadvantages of traditional adapter solutions include: class adapter solutions and object adapter solutions need to inherit the original interface class or combine the original interface objects, which increases the complexity of the code to a certain extent; the interface adapter solution needs to define multiple default implementations, so when implementing the adapter interface in the adapter class, it is necessary to select the appropriate default implementation, which is more cumbersome. Summary of the invention
[0005] In view of this, the embodiments of the present invention provide a method, device, computer-readable medium and electronic device for adapting external dependent services, which can achieve adaptation through dynamic proxy and other means, have better flexibility and scalability, and are easier to achieve adapter automation.
[0006] To achieve the above object, according to one aspect of an embodiment of the present invention, a method for adapting an external dependency service is provided, comprising:
[0007] Create an adaptation strategy interface and implement one or more adaptation strategy classes;
[0008] Define the target interface to be adapted in the configuration file, and specify the corresponding adaptation strategy for each target interface;
[0009] Initialize the adapter framework and load the adapter class;
[0010] Dynamically generate a proxy class according to the target interface defined in the configuration file; and
[0011] By calling the proxy method of the proxy class, a suitable adapter class is selected according to the adaptation strategy configured in the configuration file, and the method of the adapter class is called to execute the adaptation logic to complete the adaptation of the target interface.
[0012] In a preferred embodiment of the present invention, the configuration file includes the name of the adapter, the name of the target interface, and the adaptation strategy.
[0013] In a preferred embodiment of the present invention, in the configuration file, the fully qualified name of the target interface is used as a key, and the fully qualified name of the adapter class is used as a value to implement registration of the adapter.
[0014] In a preferred embodiment of the present invention, the adapter class is loaded through a reflection mechanism, and the information of the target interface is dynamically acquired to generate a proxy class of the target interface to adapt the adaptation request to the target interface.
[0015] In a preferred embodiment of the present invention, the method for adapting external dependent services further comprises modifying the configuration file to add, update or delete an adapter.
[0016] In a preferred embodiment of the present invention, the execution adaptation logic includes adapting the method and input and output parameters according to the information in the configuration file.
[0017] In a preferred embodiment of the present invention, the loading adapter class includes loading an adapter method to read the adapter configuration from a configuration file, creating an adapter instance through a reflection mechanism, and registering the adapter instance in the adaptation framework.
[0018] To achieve the above object, according to another aspect of an embodiment of the present invention, a device for adapting an external dependency service is provided, which is characterized by comprising:
[0019] The adaptation strategy writing module is used to create an adaptation strategy interface and implement one or more adaptation strategy classes;
[0020] A configuration file preparation module, used to define the target interface to be adapted in the configuration file and specify a corresponding adaptation strategy for each target interface;
[0021] The adapter framework initialization module is used to load the adapter class;
[0022] A proxy class creation module, used to dynamically generate a proxy class according to a target interface defined in the configuration file; and
[0023] The adaptation method calling module is used to select a suitable adapter class according to the adaptation strategy configured in the configuration file by calling the proxy method of the proxy class, and call the method of the adapter class to execute the adaptation logic to complete the adaptation of the target interface.
[0024] To achieve the above objective, according to another aspect of an embodiment of the present invention, a computer storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the method for adapting an external dependent service is implemented.
[0025] To achieve the above-mentioned purpose, according to another aspect of an embodiment of the present invention, there is provided an electronic device, comprising: one or more processors; and a storage device for storing one or more programs, wherein the one or more programs are executed by the one or more processors, so that the one or more processors implement the above-mentioned method for adapting external dependent services.
[0026] One or more embodiments of the above invention have the following advantages or beneficial effects: a method, device, computer-readable medium and electronic device for adapting external dependent services based on Java technology can automatically adapt different interfaces and provide a unified calling method and data transmission format. The implementation of various aspects of the present invention is based on dynamic proxy and reflection mechanism (specifically, Java's reflection mechanism). First, various aspects of the present invention are intended to establish a multifunctional interface adaptation framework, using a dynamic proxy mechanism to achieve adaptation between different interfaces. When an adaptation request is passed to the adaptation framework, the framework will automatically detect the parameters and return type of the adaptation request, and automatically adapt to the target interface through the reflection mechanism. This adaptation process is automatically executed without the need for developers to manually write adaptation code. For the required interface adaptation, only a simple configuration is required in the configuration file of the framework. Secondly, the framework provides a unified calling method and data transmission format, so that all interfaces can be called and transmitted using the same method. This method is automatically created by the framework and uniformly configured in the configuration file of the framework, so that all interfaces can be guaranteed to adopt the same standard during the calling and transmission process. In addition, the framework also has the ability of dynamic configuration. The framework can dynamically load the target interface and support dynamic configuration of adaptation strategies and data transmission formats, which will take effect in real time during runtime. This dynamic configuration capability is very suitable for large software systems and can adapt to changes in interfaces at any time.
[0027] In summary, the method, device, computer-readable medium and electronic device for adapting external dependent services based on Java technology provided by the present invention have the characteristics of automatic adaptation, unified calling and dynamic configuration, and can easily and quickly realize adaptation between different interfaces, greatly improving development efficiency and adaptability.
[0028] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0030] Figure 1 is a schematic diagram of the main process of the method for adapting external dependency services according to an embodiment of the present invention;
[0031] Figure 2 is a schematic diagram of a call link of a method for adapting an external dependency service according to an embodiment of the present invention;
[0032] Figure 3 is a schematic diagram of main modules of an apparatus for adapting external dependency services according to an embodiment of the present invention;
[0033] Figure 4 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0034] Figure 5 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0035] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0036] Traditional adapter solutions generally need to be adapted one by one for different interfaces, and developers need to manually write adaptation code, so they are not automated and flexible enough. Traditional adapter solutions can only determine the implementation method of the adapter during compilation, and do not support dynamic updating and loading of adapters, which limits the flexibility and scalability of the system. Different from traditional adapter solutions based on static coding, the technical solution of adapting external dependent services in this application is adapted through dynamic proxy and other methods, which has better flexibility and scalability and is easier to realize the automation of the adapter.
[0037] Figure 1 is a method for adapting external dependent services according to an embodiment of the present invention, such as Figure 1 As shown, the method includes:
[0038] Step S101: writing an adaptation strategy step—defining the target interface to be adapted in the configuration file, and specifying a corresponding adaptation strategy for each target interface;
[0039] Step S102: preparing a configuration file—defining the target interface to be adapted in the configuration file, and specifying a corresponding adaptation strategy for each target interface;
[0040] Step S103: Initialization step—initialize the adapter framework and load the adapter class;
[0041] Step S104: Creating a proxy class step—dynamically generating a proxy class according to the target interface defined in the configuration file; and
[0042] Step S105: calling the adaptation method step - selecting a suitable adapter class according to the adaptation strategy configured in the configuration file by calling the proxy method of the proxy class, and calling the method of the adapter class to execute the adaptation logic to complete the adaptation of the target interface.
[0043] The configuration file may be a file in XML, JSON or other formats, which contains configuration information of the adapter, such as the name of the adapter class, the name of the target interface, the adaptation strategy, etc.
[0044] Traditional adapter patterns usually require explicit configuration of the relationship between the adapter and the target interface in the code. However, the method for adapting external dependent services according to an embodiment of the present invention uses a configuration file to achieve dynamic loading and updating of the adapter. At runtime, new adapter configurations can be loaded as needed, or existing adapter configurations can be updated without stopping the application or redeploying. This dynamic loading feature provides greater flexibility and scalability, so that the configuration of the adapter can be dynamically adjusted and expanded as needed.
[0045] The adapter is registered by using the fully qualified name of the target interface as the key and the fully qualified name of the adapter class as the value in the configuration file. The information in the configuration file describes the mapping relationship between the adapter class and the target interface, as well as the specific implementation details of the adapter.
[0046] The traditional adapter mode usually tightly couples the adapter and the target interface, resulting in the development and maintenance of the adapter being closely related to the target interface. However, according to the method for adapting external dependent services according to an embodiment of the present invention, by using a configuration file, an adapter instance can be dynamically created and associated with the target interface according to the information in the configuration file during system initialization or operation. The adapter is decoupled from the target interface so that the adapter can be developed and maintained independently of the target interface. This decoupling and independence improves the maintainability and testability of the code.
[0047] The adapter class is loaded through a reflection mechanism, and the information of the target interface is dynamically acquired to generate a proxy class of the target interface, so as to adapt the adaptation request to the target interface.
[0048] An adaptation request refers to a normal network request process, that is, a request to access the target interface. However, after the interface is upgraded, the adaptation request needs to go through a series of adaptation processes. At runtime, the system can dynamically load the adapter using a reflection mechanism or other appropriate methods based on the information in the configuration file.
[0049] The method for adapting external dependency services according to an embodiment of the present invention further includes modifying a configuration file to add, update or delete an adapter.
[0050] In this way, you can add, update or delete adapters by modifying the configuration file without modifying the source code, thereby achieving adaptation of multiple functional interfaces. Through the configuration file, developers can configure the relationship between the adapter and the target interface more intuitively without manual configuration in the code. This can reduce the complexity of configuration and improve development efficiency.
[0051] Wherein, executing the adaptation logic includes adapting the method and input and output parameters according to the information in the configuration file. In addition, loading the adapter class includes loading the adapter method to read the adapter configuration from the configuration file, creating an adapter instance through a reflection mechanism, and registering the adapter instance in the adaptation framework.
[0052] According to the present invention, a configuration file is used to configure the relationship between the adapter and the target interface instead of using annotations. By using the configuration file, developers can flexibly configure the adapter and dynamically load the adapter configuration at runtime without modifying the code. This configuration method provides higher flexibility and scalability.
[0053] Figure 2 The schematic diagram of the call link according to this embodiment shows the logic of using an external middleware adapter for adaptation. The configuration related and proxy class generation logic required in the adaptation process are relatively complex, so as to achieve decoupling of system dependencies on the service provider and the dependent party. Compared with the traditional adaptation solution, Figure 2 The method for adapting external dependent services according to the present embodiment does not involve any code intrusion on the provider and the relying party services.
[0054] The following describes a method for adapting external dependent services according to an embodiment of the present invention, which is applied to the following scenario: Assume that the membership system needs to adapt different identity authentication interfaces, such as mobile phone number verification, email verification, and social media verification. By using the method for adapting external dependent services according to the present invention, a unified member identity authentication interface can be implemented without having to worry about the specific verification interface implementation details. The specific steps are as follows:
[0055] 1. Write an adaptation strategy:
[0056] -Create an adaptation strategy interface `AdapterStrategy`, which contains an abstract method for executing the adaptation logic and adapting the corresponding adaptation strategy to the specific target interface;
[0057] -Implement one or more adaptation strategy classes, each of which inherits from the `AdapterStrategy` interface and implements the abstract methods in it. Each adaptation strategy class is responsible for forwarding method calls of the target interface to the adapter class and handling the adaptation logic.
[0058] 2. Prepare the configuration file:
[0059] -Define the target interface that needs to be adapted in the configuration file, such as the member authentication interface. The configuration file can be a file in XML, JSON or other formats, and is configured according to the requirements of the framework;
[0060] -Specify the adaptation strategy for each target interface in the configuration file. This can be done through key-value pairs in the configuration file or other appropriate means. For example, for the membership authentication interface, you can specify the use of the `AuthenticationAdapterStrategy` defined for the specific scenario as the adaptation strategy.
[0061] 3. Initialize the adaptation framework:
[0062] - Initialize the adaptation framework at system startup. This can be done by calling the adaptation framework's initialization method in the application's startup code.
[0063] -During the initialization of the adaptation framework, the adapter class is loaded through reflection mechanism or other means. The adapter class is a class that implements specific adaptation logic, such as `PhoneAuthenticationAdapter`, `EmailAuthenticationAdapter` and `SocialMediaAuthenticationAdapter`. The above three categories are all adapter classes managed in AuthenticationAdapterStrategy. AuthenticationAdapterStrategy uses a certain adaptation strategy to determine which adapter to use. This adaptation strategy is the relationship in the configuration file. The "relationship" here can specifically include two relationships: one is which strategy mode is requested to use, classified according to the request type; the other is the proxy method mapping relationship of the target interface proxy class, the mapping of input and output parameters, etc. For example: PhoneAuthenticationAdapter completes the adaptation of the phone permission related interface, EmailAuthenticationAdapter completes the adaptation of the email permission related interface, and SocialMediaAuthenticationAdapter completes the adaptation of the social media permission related interface.
[0064] 4. Create a proxy class:
[0065] -Generate a proxy class using the adapter framework based on the target interface defined in the configuration file. The proxy class is the class that implements the target interface. It selects the appropriate adapter class based on the adaptation strategy configured in the configuration file when the method is called and executes the adaptation logic.
[0066] 5. Call the adaptation method:
[0067] -In the membership system, when member identity authentication is required, adaptation is performed by calling the proxy method of the proxy class. The proxy class selects the appropriate adapter class according to the configured adaptation strategy and calls the adapter class method to execute the adaptation logic;
[0068] -After the adaptation process is completed, the membership system can obtain the adapted results without having to worry about the specific adapter class and adaptation logic.
[0069] Through the above steps, the multifunctional interface adaptation framework of the membership system can achieve the adaptation of different authentication interfaces. Developers only need to focus on the writing of adaptation strategies and the setting of configuration files, without having to worry about specific adapter classes and adaptation logic. The framework will dynamically generate proxy classes based on the information in the configuration file, and select adapter classes for adaptation based on the configured adaptation strategy.
[0070] When implementing the method for adapting external dependent services according to the present invention in the above application scenario, you can first define the adapter interface for member identity authentication, and then implement this adapter interface through the mobile phone number identity authentication adapter and the email identity authentication adapter. Simply put, it is an interface definition and multiple implementation classes, which are used to distinguish the implementation of interfaces in different scenarios. Then define a proxy class. The function of the proxy class is to dynamically generate the target interface when the code is running, which is used to execute the call interface. Finally, execute the proxy method of this proxy class, execute the target interface method, and at the same time, adapt the method and input and output parameters through the information in the configuration file, and return the result. This completes the adaptation logic of the interface.
[0071] In the above embodiment, a configuration file is used to configure the relationship between the adapter and the target interface. In the configuration file, the fully qualified name of the target interface is used as the key and the fully qualified name of the adapter class is used as the value to implement the registration of the adapter.
[0072] The load adapter method of the multifunctional interface adapter framework reads the adapter configuration from the configuration file, creates an adapter instance through reflection, and registers it with the adapter framework.
[0073] In the main function, the adapter framework instance is first created, and the adapter configuration is loaded by calling the load adapter method. Then, the proxy class is generated by calling the generate proxy class method of the adapter framework. Finally, the adaptation method is called through the proxy class to implement the adaptation of member authentication.
[0074] The innovation of the above embodiment is to use a configuration file to configure the relationship between the adapter and the target interface instead of using annotations. By using a configuration file, developers can flexibly configure the adapter and dynamically load the adapter configuration at runtime without modifying the code. This configuration method provides higher flexibility and scalability.
[0075] Figure 3 is a device for adapting external dependent services according to an embodiment of the present invention, such as Figure 3 As shown, the device comprises:
[0076] Module 301: Adaptation strategy writing module, used to create an adaptation strategy interface and implement more than one adaptation strategy class;
[0077] Module 302: a configuration file preparation module, used to define the target interface to be adapted in the configuration file, and specify a corresponding adaptation strategy for each target interface;
[0078] Module 303: Adapter framework initialization module, used to load the adapter class;
[0079] Module 304: a proxy class creation module, used to dynamically generate a proxy class according to the target interface defined in the configuration file; and
[0080] Module 305: An adaptation method calling module, used to select a suitable adapter class according to the adaptation strategy configured in the configuration file by calling the proxy method of the proxy class, and call the method of the adapter class to execute the adaptation logic to complete the adaptation of the target interface.
[0081] The configuration file preparation module 302 is mainly used to manage various configuration information of the interface adaptation framework. The target interface, adaptation strategy, data transmission format and other information can be set through the configuration file. The configuration file preparation module 302 can also realize dynamic loading and updating of the configuration file, so that the configuration information and adaptation strategy of the framework are always kept up to date.
[0082] The adaptation framework initialization module 303 can load the adapter class through a reflection mechanism.
[0083] The proxy class creation module 304 utilizes the reflection mechanism to dynamically generate the interface proxy class by passing the information of the target interface in the configuration file to adapt the adaptation request to the target interface. Using the dynamic proxy mechanism can reduce the code writing and maintenance work of the developers, and can ensure the elasticity and scalability of the system.
[0084] The adaptation method calling module 305 calls the proxy method of the proxy class to call the adaptation method, automatically adapts the request to the target interface through the reflection mechanism, and returns the result. The "adaptation method" here can include two meanings: one is to divide it into large adaptation strategy processing according to the type of adaptation request, and the adaptation strategy corresponding to different types of adaptation requests may be different; the second is to dynamically generate the proxy class of the target interface according to the reflection mechanism, and perform the mapping and matching process. Through the reflection mechanism, the class information can be dynamically obtained at runtime and corresponding operations can be performed. In the adaptation framework, the reflection mechanism is mainly used to dynamically obtain the information of the target interface at runtime and adapt the request to the target interface. The use of the reflection mechanism can make the adaptation framework more flexible and extensible.
[0085] Among them, the device for adapting external dependent services according to an embodiment of the present invention may also include: an exception handling module for handling exceptions that occur during the adaptation process. During the adaptation process, some exceptions may occur, such as type mismatch, method non-existence, etc. The adaptation framework needs to be able to capture these exceptions in a timely manner and perform corresponding processing. In the framework, the stability and security of the adaptation process are guaranteed by capturing and processing exceptions during the adaptation process.
[0086] Figure 4An exemplary system architecture 400 is shown to which the method for adapting an externally dependent service or the apparatus for adapting an externally dependent service according to the embodiment of the present invention can be applied.
[0087] like Figure 4 As shown, system architecture 400 may include terminal devices 401, 402, 403, network 404 and server 405. Network 404 is used to provide a medium for communication links between terminal devices 401, 402, 403 and server 405. Network 404 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0088] Users can use terminal devices 401, 402, 403 to interact with server 405 through network 404 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 401, 402, 403, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0089] The terminal devices 401 , 402 , and 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0090] The server 405 may be a server that provides various services, such as a background management server that provides support for websites browsed by users using the terminal devices 401, 402, and 403. The background management server may analyze and process the received request data, and feed back the processing results to the terminal device.
[0091] It should be noted that the external dependency service adaptation method provided in the embodiment of the present invention is generally executed by the server 405 , and accordingly, the external dependency service adaptation device is generally set in the server 405 .
[0092] It should be understood that Figure 4 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0093] Reference below Figure 5 , which shows a schematic diagram of the structure of a computer system 500 of a terminal device suitable for implementing an embodiment of the present invention. Figure 5 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0094] like Figure 5As shown, the computer system 500 includes a central processing unit (CPU) 501, which can 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 part 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the system 500 are also stored. The CPU 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0095] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed, so that a computer program read therefrom is installed into the storage section 508 as needed.
[0096] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 509, and / or installed from the removable medium 511. When the computer program is executed by the central processing unit (CPU) 501, the above-mentioned functions defined in the system of the present invention are executed.
[0097] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, 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 disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0098] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0099] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes an adaptation strategy writing module, a configuration file preparation module, an adaptation framework initialization module, a proxy class creation module, and an adaptation method calling module. The names of these modules do not, in some cases, constitute limitations on the modules themselves.
[0100] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes:
[0101] Write an adaptation strategy to create an adaptation strategy interface and implement one or more adaptation strategy classes;
[0102] Preparing a configuration file, which is used to define the target interface to be adapted in the configuration file, and specifying a corresponding adaptation strategy for each target interface;
[0103] Initialize the adapter framework to load the adapter class;
[0104] Creating a proxy class for dynamically generating a proxy class according to a target interface defined in the configuration file; and
[0105] The adaptation method is called to select a suitable adapter class according to the adaptation strategy configured in the configuration file by calling the proxy method of the proxy class, and the method of the adapter class is called to execute the adaptation logic to complete the adaptation of the target interface.
[0106] According to the technical solution of the embodiment of the present invention, a method, device, computer-readable medium and electronic device for adapting external dependent services based on Java technology can automatically adapt different interfaces and provide a unified calling method and data transmission format. The implementation of various aspects of the present invention is based on dynamic proxy and reflection mechanism. First, various aspects of the present invention are intended to establish a multifunctional interface adaptation framework, using dynamic proxy mechanism to achieve adaptation between different interfaces. When a calling method is passed to the adaptation framework, the framework will automatically detect the parameters and return type of the calling method, and automatically adapt to the target interface through the reflection mechanism. This adaptation process is automatically executed, without the need for developers to manually write adaptation code. For the required interface adaptation, only a simple configuration is required in the configuration file of the framework. Secondly, the framework provides a unified calling method and data transmission format, so that all interfaces can be called and transmitted using the same method. This method is automatically created by the framework and uniformly configured in the configuration file of the framework, so that all interfaces can use the same standard in the process of calling and transmitting. In addition, the framework also has the ability of dynamic configuration. The framework can dynamically load the target interface, and supports dynamic configuration of adaptation strategy and data transmission format, and takes effect in real time at runtime. This dynamic configuration capability is very suitable for large software systems and can adapt to changes in interfaces at any time.
[0107] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for adapting an external dependent service, characterized in that: include: Create an adaptation strategy interface and implement one or more adaptation strategy classes; Define the target interface to be adapted in the configuration file, and specify the corresponding adaptation strategy for each target interface; Initialize the adapter framework and load the adapter class; Dynamically generate a proxy class according to the target interface defined in the configuration file; as well as By calling the proxy method of the proxy class, a suitable adapter class is selected according to the adaptation strategy configured in the configuration file, and the method of the adapter class is called to execute the adaptation logic to complete the adaptation of the target interface.
2. The method for adapting external dependent services according to claim 1, characterized in that: The configuration file includes the name of the adapter, the name of the target interface, and the adaptation strategy.
3. The method for adapting external dependent services according to claim 1, characterized in that: In the configuration file, the fully qualified name of the target interface is used as a key, and the fully qualified name of the adapter class is used as a value to implement the registration of the adapter.
4. The method for adapting external dependent services according to claim 1, characterized in that: The adapter class is loaded through the reflection mechanism, and the information of the target interface is dynamically obtained to generate a proxy class of the target interface to adapt the adaptation request to the target interface.
5. The method for adapting external dependent services according to claim 1, characterized in that: Also includes Modify the configuration file to add, update or delete adapters.
6. The method for adapting external dependent services according to claim 1, characterized in that: The execution adaptation logic includes adapting the method and input and output parameters according to the information in the configuration file.
7. The method for adapting external dependent services according to claim 1, characterized in that: The loading adapter class includes loading an adapter method to read the adapter configuration from a configuration file, creating an adapter instance through a reflection mechanism, and registering the adapter instance in the adaptation framework.
8. A device for adapting external dependent services, characterized in that: include: The adaptation strategy writing module is used to create an adaptation strategy interface and implement one or more adaptation strategy classes; A configuration file preparation module, used to define the target interface to be adapted in the configuration file and specify a corresponding adaptation strategy for each target interface; The adapter framework initialization module is used to load the adapter class; A proxy class creation module, used to dynamically generate a proxy class according to a target interface defined in the configuration file; as well as The adaptation method calling module is used to select a suitable adapter class according to the adaptation strategy configured in the configuration file by calling the proxy method of the proxy class, and call the method of the adapter class to execute the adaptation logic to complete the adaptation of the target interface.
9. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
10. An electronic device adapted to external dependent services, characterized in that: include: one or more processors; as well as a storage device for storing one or more programs, The one or more programs are executed by the one or more processors, so that the one or more processors implement the method according to any one of claims 1 to 7.