Calling method and device for implementing strategy, electronic device, and storage medium
By creating a strategic container and strategy in the Spring framework to implement the mapping relationship of identification, the complexity problem of calling strategy is solved, and the strategy of manually writing the carrier code to achieve the call is achieved, which improves the development efficiency and accuracy.
Patent Information
- Application Number
- CN202010131597.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-02-28
- Publication Date
- 2025-01-28
- Estimated Expiration
- 2040-02-28
AI Technical Summary
When using the Spring framework for software development, calling policy implementation is a complex process. Developers need to manually write hosting code to implement policy implementation, which increases development difficulty and inefficiency.
By creating a strategic container corresponding to the strategic interface in advance, and establishing a strategic implementation and strategic implementation of the mapping relationship, developers do not need to manually write the carrier code. Just find the corresponding strategic container based on the strategy interface based on the strategy to achieve the strategy implementation Call.
Simplified the call process of strategic implementation, reduced the difficulty of software development and improved efficiency, reduced the number of strategies to be found, and increased the accuracy of calls.
Smart Images

Figure CN113326034B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software development, and in particular to a calling method and device, electronic device, and storage medium for implementing a strategy. Background Art
[0002] As users' demands for application software become more and more extensive, developers are paying more and more attention to how to reduce the difficulty of software development.
[0003] Java is an object-oriented programming language, which is favored by developers for its powerful functions and easy-to-use features. In order to further improve the efficiency of software development using Java, the Spring framework based on Java came into being. The Spring framework allows developers to focus on business-related codes instead of general codes in programming during software development, which reduces the difficulty of software development and improves efficiency. Summary of the invention
[0004] In view of this, the present application provides a policy implementation calling method and device, electronic device, and storage medium, which enable developers to call the policy implementation without having to specially write code to carry the policy implementation. They only need to find the corresponding policy container to carry the policy implementation to implement the call.
[0005] To achieve the above objectives, this application provides the following technical solutions:
[0006] According to a first aspect of the present application, a policy implementation calling method is proposed, which is applied to a programming device, wherein the programming device pre-creates a policy container corresponding to a policy interface, and establishes a mapping relationship between a policy implementation and a policy implementation identifier for the policy implementation carried in each policy container; the method comprises:
[0007] When a call instruction for a target policy implementation is detected, reading a policy implementation identifier contained in the call instruction and a target policy interface corresponding to the target policy implementation;
[0008] Determine a corresponding target policy container according to the target policy interface;
[0009] searching the target policy container for a policy implementation corresponding to the policy implementation identifier according to the mapping relationship, and using the found policy implementation as the target policy implementation;
[0010] The target policy implementation is carried based on the target policy container, so as to be used for calling the target policy implementation.
[0011] Optionally, the policy interface of the programming device corresponds to the business type one by one, at least one policy implementation carried in any policy container belongs to the same business type, and the target policy interface included in the calling instruction is the policy interface corresponding to the business type to which the target policy implementation belongs.
[0012] Optionally, each policy container is generated by calling a container generation tool in a Spring framework, where the container generation tool is defined based on a FactoryBean property of the Spring framework.
[0013] Optionally, the policy implementation carried in any policy container is obtained in the following way:
[0014] Determining a specific policy interface corresponding to any one of the policy containers;
[0015] Read at least one policy implementation corresponding to the specific policy interface stored in the Spring container; and add the read policy implementation to any one of the policy containers.
[0016] Optionally, the mapping relationship is obtained in the following manner:
[0017] Read annotations corresponding to the read strategy implementation from the Spring container;
[0018] Obtaining a custom annotation identification logic corresponding to the specific strategy interface; the custom annotation identification logic is customized based on the business type corresponding to each strategy interface;
[0019] Configure the corresponding strategy implementation identifier for the strategy implementation read according to the obtained custom annotation identification logic and the read annotation.
[0020] According to a second aspect of the present application, a policy implementation calling device is proposed, which is applied to a programming device, wherein the programming device pre-creates a policy container corresponding to a policy interface, and establishes a mapping relationship between a policy implementation and a policy implementation identifier for the policy implementation carried in each policy container; the method includes:
[0021] A reading unit, when detecting a call instruction for a target policy implementation, reads a policy implementation identifier contained in the call instruction and a target policy interface corresponding to the target policy implementation;
[0022] A determination unit, which determines a corresponding target policy container according to the target policy interface;
[0023] a searching unit, searching the target policy container for a policy implementation corresponding to the policy implementation identifier according to the mapping relationship, and using the found policy implementation as the target policy implementation;
[0024] A calling unit is configured to call the target policy implementation based on the target policy container carrying the target policy implementation.
[0025] Optionally, the policy interface of the programming device corresponds to the business type one by one, at least one policy implementation carried in any policy container belongs to the same business type, and the target policy interface included in the calling instruction is the policy interface corresponding to the business type to which the target policy implementation belongs.
[0026] Optionally, each policy container is generated by calling a container generation tool in a Spring framework, where the container generation tool is defined based on a FactoryBean property of the Spring framework.
[0027] Optionally, the policy implementation carried in any policy container is obtained in the following way:
[0028] The determining unit is further configured to determine a specific policy interface corresponding to any one of the policy containers;
[0029] The reading unit is further used to read at least one policy implementation corresponding to the specific policy interface stored in the Spring container; and add the read policy implementation to any one of the policy containers.
[0030] Optionally, the mapping relationship is obtained in the following manner:
[0031] The reading unit is further used to read annotations corresponding to the read strategy implementation from the Spring container;
[0032] An acquisition unit, which acquires a custom annotation identification logic corresponding to the specific strategy interface; the custom annotation identification logic is customized based on the business type corresponding to each strategy interface;
[0033] The configuration unit configures the corresponding strategy implementation identifier for the read strategy implementation according to the obtained custom annotation identification logic and the read annotation.
[0034] According to a third aspect of the present application, an electronic device is provided, including:
[0035] processor;
[0036] a memory for storing processor-executable instructions;
[0037] The processor implements any of the methods described in the above embodiments by running the executable instructions.
[0038] According to a fourth aspect of an embodiment of the present disclosure, there is provided a computer-readable storage medium on which computer instructions are stored. When the instructions are executed by a processor, the steps of the method described in any one of the above embodiments are implemented.
[0039] It can be seen from the above technical solution that before calling the policy implementation, the present application pre-creates a policy container corresponding to each policy interface, so that when the developer calls the policy implementation, there is no need to write specific code for carrying the policy implementation. The developer only needs to find the corresponding policy container based on the policy interface of the policy implementation to be called to carry the policy implementation to realize the call.
[0040] Furthermore, each policy interface is used to represent a different business type. After creating a policy container, the present application adds the policy implementation to the corresponding policy container based on the policy interface to which each policy implementation belongs, that is, the policy implementation is divided into different types based on the policy interface with the help of the policy container. The policy implementation is stored separately according to the policy container, so that when calling, it is not necessary to match all policy implementations, but only to find the corresponding policy container, and match a relatively smaller number of policy implementations in the container to find the policy implementation to be called. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 It is a flowchart of a calling method for implementing a strategy shown in an exemplary embodiment of the present application.
[0042] Figure 2 It is a flowchart of a method for generating a policy container shown in an exemplary embodiment of the present application.
[0043] Figure 3 It is a flowchart of another policy-implemented calling method shown in an exemplary embodiment of the present application.
[0044] Figure 4 It is a structural schematic diagram of an electronic device shown in an exemplary embodiment of the present application.
[0045] Figure 5 It is a block diagram of a calling device for implementing a policy shown in an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0046] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0047] The terms used in this application are for the purpose of describing specific embodiments only and are not intended to limit this application. The singular forms of "a", "said" and "the" used in this application and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0048] It should be understood that although the terms first, second, third, etc. may be used in the present application to describe various information, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0049] In the process of programming with Java language, developers proposed the Spring framework based on Java language in order to solve the problem of repeated writing of Java language. The Spring framework retains a large amount of common code for programming, so that developers do not need to pay attention to the common code required for programming during the software development process, but only need to pay attention to the code related to the business that the programming is targeting, that is, the business code.
[0050] Although the Spring framework reduces the complexity of programming in Java by injecting common code, writing code that calls business code is still a complicated process during program writing.
[0051] In the general Spring framework, there is a unique Spring container. In order to avoid duplication of business code, developers usually pre-write corresponding business codes for each business, that is, the policy implementation described in this application, and save the written policy implementation in the Spring container. When the developer wants to call a certain policy implementation, he only needs to find the corresponding policy implementation from the Spring container and call the written policy implementation.
[0052] However, in the related art, calling a policy implementation is a rather complicated process. When developers find the corresponding policy implementation in the Spring container, they need to first determine the policy interface (i.e., policy class, which can be understood as the category to which the policy implementation belongs), and then write the code for carrying the policy implementation based on the determined policy interface (for the convenience of introduction, it is expressed as carrying code below). Only after writing the carrying code can the policy implementation be called.
[0053] From the above process, it can be seen that calling the written strategy implementation in the general Spring framework is still a rather complicated process.
[0054] In order to solve the above problems, this application proposes a calling method for policy implementation. Figure 1 , Figure 1 This is a calling method for implementing a strategy as shown in an exemplary embodiment of the present application. Figure 1 As shown, the method is applied to a programming device, which may be a PC, a mobile terminal, etc. The programming device pre-creates a policy container corresponding to a policy interface, and establishes a mapping relationship between a policy implementation and a policy implementation identifier for the policy implementation carried in each policy container; the method may include the following steps:
[0055] Step S102: when a call instruction for a target policy implementation is detected, a policy implementation identifier contained in the call instruction and a target policy interface corresponding to the target policy implementation are read.
[0056] For the convenience of expression, this specification introduces the concept of policy container, which is understood as: on the one hand, it is used to carry policy implementation to complete the call of policy implementation (the function is equivalent to the carrier code manually written by the developer to carry the policy implementation); on the other hand, it is used to divide the policy implementation according to the different types of the policy interface to which it belongs, thereby realizing the classification management of policy implementation by developers.
[0057] In this embodiment, developers pre-write corresponding policy implementations for different services, and save them in corresponding policy containers according to the policy interfaces to which the policy implementations belong. When developers want to implement a service to be implemented, they only need to call a specific policy implementation from the corresponding policy container.
[0058] In this embodiment, the policy interfaces in the programming device correspond to the business types one by one, the policy implementations carried in any policy container belong to the same business type, and the target policy interface included in the calling instruction is the policy interface corresponding to the business type to which the target policy implementation belongs.
[0059] In other words, in order to call the target policy implementation, the policy interface to which the target policy implementation belongs and the policy implementation identifier corresponding to the target policy implementation need to be included in the calling instruction. The target policy implementation and its corresponding policy implementation identifier can be found by the developer in the pre-written code; similarly, the policy interface corresponding to the target policy implementation can also be obtained in this way.
[0060] After obtaining the policy implementation identifier corresponding to the target policy implementation, the developer can input the policy implementation identifier corresponding to the target policy implementation and the target policy interface through the programming interface of the programming device to call the target policy implementation.
[0061] Step S104: determining a corresponding target policy container according to the target policy interface.
[0062] The Spring framework includes a unique Spring container. In related technologies, all written strategy implementations are usually stored in the Spring container.
[0063] In this embodiment, different policy containers are created based on different policy interfaces, and the policy implementations stored in the Spring container are stored in different policy containers according to the different policy interfaces. Each policy container is generated by calling the container generation tool in the Spring framework, which is defined based on the FactoryBean feature of the Spring framework.
[0064] In general, the container generation tool is defined by developers based on the FactoryBean feature of the Spring framework for different strategy interfaces, and then the strategy container corresponding to each strategy interface is generated by the defined container generation tool for different strategy interfaces.
[0065] After generating the policy container, the policy implementations belonging to different policy interfaces can also be saved in the corresponding policy container. The policy implementations carried in any policy container can be obtained in the following way: first, determine the specific policy interface corresponding to any policy container; then, find at least one policy implementation corresponding to the specific policy interface from the Spring container and read it; finally, add the read policy implementation to the specific policy container.
[0066] Step S106: searching the target policy container for a policy implementation corresponding to the policy implementation identifier according to the mapping relationship, and using the found policy implementation as the target policy implementation.
[0067] In this embodiment, it is necessary to pre-create a mapping relationship between the policy implementation and the policy implementation identifier in the policy container. When creating the mapping relationship, it is necessary to first read the annotation corresponding to the read policy implementation from the Spring container, and then determine the corresponding custom annotation identification logic according to the policy interface to which the read policy implementation belongs, and then configure the corresponding policy implementation identifier for the read policy implementation according to the obtained custom annotation identification logic and the read annotation. Among them, the custom annotation identification logic is customized based on the business type corresponding to each policy interface.
[0068] The method of configuring the corresponding policy implementation identifier for the read policy implementation enables the developer to call the policy implementation by only providing the corresponding policy implementation identifier when the policy implementation needs to be called, thereby simplifying the difficulty of the developer calling the policy implementation.
[0069] Further, for the policy implementations belonging to different policy interfaces, different custom annotation identification logics are adopted, which can better distinguish the policy implementations belonging to different policy interfaces. In fact, in the general Spring framework, the same custom annotation identification logic is adopted for different policy interfaces, and the annotations of the policy implementations belonging to different policy interfaces may also have the same situation. At this time, since the annotations and the custom annotation identification logics are the same, the policy implementation identifications of the policy implementations belonging to different policy interfaces obtained by configuration are the same. In this way, when the policy implementation is called by the policy implementation identification, there may be a situation where the policy implementation is misadjusted and two policy implementations for implementing different businesses are called at the same time. In the present embodiment, since different custom annotation identification logics are adopted for different policy interfaces, even if the annotations are the same, the policy implementation identifications obtained by configuration are also different, and there is no situation where the policy implementation is misadjusted and multiple policy implementations are called at the same time. In other words, the accuracy of calling the policy implementation is improved.
[0070] Step S108: Carrying the target policy implementation based on the target policy container to call the target policy implementation.
[0071] In this embodiment, the policy implementation must be carried in the corresponding policy container to be called. Therefore, in this step, the target policy implementation is called by carrying the target policy container.
[0072] It is worth noting that in the actual calling process (i.e., the programming process), both the policy container and the policy implementation are essentially codes. Therefore, in the calling process, whether to call the code corresponding to the policy container first or to integrate the policy implementation and the policy container code and call them together can be set by those skilled in the art according to the actual situation and is not limited here.
[0073] It can be seen from the above technical solution that the present application pre-creates a corresponding policy container for each policy interface, so that in the process of calling the policy implementation, there is no need to write the corresponding carrying code for each policy implementation, and the corresponding policy container can be directly called according to the policy interface to which the policy implementation belongs, so as to carry the policy implementation to be called. In this way, there is no need to write the code for carrying the policy implementation, which reduces the difficulty of software development and improves efficiency.
[0074] It can be seen from the above content that the technical solution of the present application involves two stages. Next, the technical solution of the present application will be introduced for the two stages respectively.
[0075] 1. Configuration phase
[0076] refer to Figure 2 , Figure 2 FIG. 1 is a flow chart of a method for generating a policy container according to an exemplary embodiment of the present application. Figure 2 As shown, the method is applied to a programming device, and the method may include the following steps:
[0077] Step S201, calling a container generation tool for any policy interface.
[0078] In this embodiment, the developer will use the FactoryBean feature of the Spring framework to customize the corresponding container generation tool for each strategy interface. Usually, the developer calls a container generation tool customized by the FactoryBean feature FactoryBean.
[0079] It is worth noting that the policy container created by the container generation tool has much less code than the code manually written by the developer for each policy interface. The reason is that a general code for generating each policy container is called in the container generation tool, and this code and a small amount of code related to the policy interface are run once each time a policy container is generated. For example, when a policy container B+ corresponding to policy interface B is generated by container generation tool A, container generation tool A can directly call the general generation code D and add the custom code corresponding to policy interface B (usually a small amount, written by the developer) to generate policy container B+. In other words, the code of policy container B+ is: the call instruction of the generation code D + the custom code corresponding to policy interface B. Obviously, it is simpler than the bearer code manually written for a policy implementation.
[0080] To understand the difference before and after using the container generation tool, you can refer to the actual code below.
[0081] The following is the hosting code written manually by developers before the container generation tool was used.
[0082]
[0083]
[0084] Obviously, from the above actual written code, it can be seen that before using the container generation tool, developers need to write a lot of hosting code, while after using the container generation tool, they only need to write a small amount of custom code for the policy interface.
[0085] In addition, when customizing the container generation tool, you can also define the custom annotation identification logic corresponding to each strategy interface, so as to configure the corresponding strategy implementation identification for the strategy implementation later. The defined custom annotation identification logic can be included in the container generation tool corresponding to the corresponding strategy interface.
[0086] In this way, the container generation tool and the custom annotation identification logic that need to be customized can be completed in one configuration. Secondly, the custom annotation identification logic contained in the container generation tool can be read while calling the container generation tool through the strategy interface, without having to call the custom annotation identification logic separately from another storage space.
[0087] Step S202: Generate a policy container corresponding to any policy interface by calling a container generation tool.
[0088] Step S203, reading the policy implementation corresponding to any policy interface and the annotation corresponding to the read policy implementation from the Spring container.
[0089] In the Spring container, not only the strategy implementations written in advance by developers are saved, but also the annotations corresponding to each strategy implementation. However, in the Spring framework, the corresponding strategy implementation cannot be directly called based on the annotation. Therefore, the corresponding identifier must be generated based on the annotation to realize the call of the strategy implementation.
[0090] Step S204: read the custom annotation identification logic for any strategy interface.
[0091] In this embodiment, the custom annotation identification logic for each strategy interface is customized by the developer according to the business type corresponding to each strategy interface. Usually, the custom annotation identification logic can be saved in the container generation tool customized for this type of strategy interface. In other words, usually, the strategy interface, container generation tool, custom annotation identification logic and business type correspond one to one.
[0092] Step S205 , configuring a corresponding policy implementation identifier for the read policy implementation based on the read custom identification logic and the annotations corresponding to each read policy implementation.
[0093] In this embodiment, any custom annotation identification logic can be understood as an identification rule for annotations corresponding to different policy implementations under a certain policy interface. Therefore, based on the custom annotation identification logic, different policy implementation identifiers can be configured for different policy implementations to distinguish each policy implementation when calling.
[0094] Step S206: adding the read policy implementations and the mapping relationship between the policy implementations and the corresponding policy implementation identifiers to the generated policy container.
[0095] It can be seen from the above technical solution that this application generates a corresponding policy container for each policy interface, and saves the policy implementations belonging to the same policy interface in the corresponding policy container. In other words, this application divides the policy implementations stored in the Spring container according to the policy interfaces they belong to during the configuration phase, so that when calling, there is no need to traverse all policy implementations. You only need to search in the policy container corresponding to the policy interface to which the policy implementation to be called belongs to find the corresponding policy implementation to be called, reducing the number of policy implementations that need to be found.
[0096] In fact, the technical solution of the present application further creates a policy container based on the Spring container of the Spring framework, which can be regarded as a new framework based on the Spring framework, and can be called a policy framework. In the policy framework, a policy container corresponding to each policy interface is pre-established, which can be used to carry policy implementations on the one hand, and can also divide the policy implementations on the other hand, which is conducive to simplifying the management of policy implementations. For example, when a developer needs to add a new policy implementation to the policy framework, it is only necessary to add the written policy implementation to the corresponding policy container through the method of steps S203-S206 (the code corresponding to the policy container can be used as the carrier code of the newly added container), without having to write the corresponding carrier code for each newly added policy implementation.
[0097] 2. Calling phase
[0098] refer to Figure 3 , Figure 3 FIG. 1 is a flowchart of another calling method for implementing a strategy according to an exemplary embodiment of the present application. Figure 3 As shown, the method is applied to a programming device, and the method may include the following steps:
[0099] Step S301: when a calling instruction input by a user is detected, a policy implementation identifier and a policy interface included in the calling instruction are read.
[0100] In this embodiment, the programming device can determine whether a developer needs to call a policy implementation to implement the corresponding business by real-time detection. The basis for detection can be: whether the input policy implementation identifier and policy interface are detected. When the input policy implementation identifier and policy interface are detected, it is determined that the developer needs to call the policy implementation. Among them, the policy implementation corresponding to the detected policy implementation identifier belongs to the detected policy interface.
[0101] To facilitate understanding of the relationship between policy implementation, policy interface, policy container and business, the price calculation business class and the contract writing business class are used as examples for introduction, see Table 1.
[0102]
[0103] Table 1
[0104] As shown in Table 1, the developer has written strategy implementation 1 and strategy implementation 2 for the fruit price calculation business and the vegetable price calculation business respectively for the price calculation business class. Strategy implementation 1 and strategy implementation 2 belong to the same strategy interface A. In the configuration phase, the programming device creates a corresponding strategy container a for strategy interface A, which is used to store the strategy implementation corresponding to the price calculation business class, namely, strategy implementation 1 and strategy implementation 2. Similarly, the contract writing business class is similar to the price calculation business class, and will not be described in detail here.
[0105] Therefore, when you need to call policy implementation 1 or policy implementation 2, you only need to find policy container a according to policy interface A, and find policy implementation 1 or 2 in policy container a based on the policy implementation identifier of policy implementation 1 or 2; then carry policy implementation 1 or 2 in policy container a to complete the call to policy implementation 1 or 2.
[0106] In this step, assuming that the developer wants to implement the business of fruit price calculation, the developer will obtain the policy implementation identifier corresponding to policy implementation 1 used to implement the fruit price calculation business from the content configured in the configuration phase (or the policy framework). For the convenience of expression, the policy implementation identifier corresponding to policy implementation 1 is defined as X; similarly, it can also be learned from the content configured in the configuration phase that the policy interface to which policy implementation 1 belongs is policy interface A.
[0107] It is worth noting that in actual situations, the naming of the policy interface, policy container, policy implementation and its policy implementation identifier will be related to the business. Technical personnel who are familiar with the configuration content can directly know the policy implementation corresponding to each business and the corresponding policy interface and other information based on the naming, without having to search according to the configuration content. Even technical personnel who are not familiar with the configuration content can easily find the content they need to know from the configuration content because the naming is related to the business. For example, the name of strategy implementation 1 in Table 1 can be "FruitCalculatePriceStrategy" (fruit price calculation strategy); the name of strategy interface A can be "CalculatePriceStrategyClass" (price calculation strategy class); the policy implementation identifier X corresponding to strategy implementation 1 can be "FRUIT". Obviously, technical personnel in this field can directly know the policy implementation corresponding to the business to be implemented and the corresponding policy interface and other information from the configuration content.
[0108] Step S302: determine the corresponding policy container according to the read policy interface.
[0109] Continuing with the example in the previous step, in this step, based on the read strategy interface A, the corresponding strategy container is found in the configuration content. For example, the strategy container found based on the strategy interface A may be named: CalculatePriceStrategyContainer (price calculation strategy container).
[0110] Step S303: calling the policy implementation corresponding to the policy implementation identifier in the determined policy container according to the read policy implementation identifier.
[0111] In this embodiment, since the policy container storing the policy implementation has been determined by calling the policy interface in the instruction in step S303, it is only necessary to search for the policy implementation to be called in the determined policy container according to the read policy implementation identifier.
[0112] It is worth noting that, in the configuration content, the form of storing the policy implementation in the policy container can be: the policy implementation identifier and its indicator are included in the code of the policy container to indicate the location where the code corresponding to the policy implementation is stored.
[0113] Step S304: Use the determined policy container to carry the read policy implementation to call the policy implementation.
[0114] In this embodiment, since the policy container and the policy implementation are actually codes, the determined policy implementation can be carried in the determined policy container in this step and then called together, that is, the code corresponding to the policy container and the code corresponding to the policy implementation can be integrated and called together; or the code corresponding to the policy container can be called first when the policy container is determined, and when the policy implementation is determined in the policy container, the code corresponding to the policy implementation can be called. Of course, the specific calling method can be adopted by those skilled in the art in different ways according to the actual situation, and it is not limited here.
[0115] It can be seen from the above technical solution that when developers need to call a policy implementation, they do not need to write the bearer code for the policy implementation to be called in real time. They only need to determine the corresponding policy container through the policy interface to which the policy implementation to be called belongs to realize the call of the policy implementation to be called. In this way, the repeated writing of the bearer code is avoided, the difficulty of software development is reduced, and the efficiency is improved.
[0116] To facilitate understanding of the technical effects brought about by the technical solution of the present application, let's continue to take the policy implementation 1 corresponding to the fruit price calculation business as an example. Before adopting this solution, to call the policy implementation 1 through the Spring framework, you first need to write the carrier code corresponding to the policy interface A, then traverse all policy implementations from the Spring container to find the policy implementation 1, and carry the policy implementation 1 on the written carrier code to implement the call. In other words, at least you need to write the carrier code and the code for calling the policy implementation. After adopting the technical solution of the present application, you only need to enter the identifier X corresponding to the policy implementation 1 and the policy interface A to implement the call. Corresponding to the code, you only need to write two statements, that is, to enable the programming device to detect the statements corresponding to the two pieces of information "the policy implementation identifier corresponding to the policy implementation 1 is X, and the policy interface corresponding to the policy implementation 1 is the policy interface A", and then you can call the policy implementation of the fruit price calculation.
[0117] Figure 4 A schematic structural diagram of an electronic device according to an exemplary embodiment of the present application is shown. Figure 4 At the hardware level, the electronic device includes a processor 402, an internal bus 404, a network interface 406, a memory 408, and a non-volatile memory 410, and may also include hardware required for other services. The processor 402 reads the corresponding computer program from the non-volatile memory 410 into the memory 408 and then runs it, forming a calling device for policy implementation at the logical level. Of course, in addition to the software implementation method, this application does not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc., that is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0118] Please refer to Figure 5 In a software implementation, the calling means for implementing the policy may include:
[0119] The reading unit 501, when detecting a call instruction for a target policy implementation, reads a policy implementation identifier contained in the call instruction and a target policy interface corresponding to the target policy implementation;
[0120] A determination unit 502 determines a corresponding target policy container according to the target policy interface;
[0121] A searching unit 503 searches the target policy container for a policy implementation corresponding to the policy implementation identifier according to the mapping relationship, and uses the found policy implementation as the target policy implementation;
[0122] The calling unit 504 is configured to call the target policy implementation based on the target policy container carrying the target policy implementation.
[0123] Optionally, the policy interface of the programming device corresponds to the business type one by one, at least one policy implementation carried in any policy container belongs to the same business type, and the target policy interface included in the calling instruction is the policy interface corresponding to the business type to which the target policy implementation belongs.
[0124] Optionally, each policy container is generated by calling a container generation tool in a Spring framework, where the container generation tool is defined based on a FactoryBean property of the Spring framework.
[0125] Optionally, the policy implementation carried in any policy container is obtained in the following way:
[0126] Determining a specific policy interface corresponding to any one of the policy containers;
[0127] Read at least one policy implementation corresponding to the specific policy interface stored in the Spring container; and add the read policy implementation to any one of the policy containers.
[0128] Optionally, the mapping relationship is obtained in the following manner:
[0129] Read annotations corresponding to the read strategy implementation from the Spring container;
[0130] Obtaining a custom annotation identification logic corresponding to the specific strategy interface; the custom annotation identification logic is customized based on the business type corresponding to each strategy interface;
[0131] Configure the corresponding strategy implementation identifier for the strategy implementation read according to the obtained custom annotation identification logic and the read annotation.
[0132] The implementation process of the functions and effects of each unit in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.
[0133] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present application scheme. A person of ordinary skill in the art can understand and implement it without paying any creative work.
[0134] In an exemplary embodiment, a non-temporary computer-readable storage medium including instructions is also provided, such as a memory including instructions. The above instructions can be executed by a processor of a policy implementation calling device to implement a method as described in any of the above embodiments. For example, the method may include: when a calling instruction for a target policy implementation is detected, reading a policy implementation identifier and a target policy interface corresponding to the target policy implementation contained in the calling instruction; determining a corresponding target policy container according to the target policy interface; searching for a policy implementation corresponding to the policy implementation identifier in the target policy container according to the mapping relationship, and using the found policy implementation as the target policy implementation; carrying the target policy implementation based on the target policy container for calling the target policy implementation.
[0135] The non-temporary computer-readable storage medium may be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc., and the present application does not limit this.
[0136] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.
Claims
1. A calling method for implementing a strategy, characterized in that: Applied to a programming device, the programming device pre-creates a policy container corresponding to a policy interface, wherein the policy container is generated by calling a container generation tool in a Spring framework, and the container generation tool is obtained by a FactoryBean characteristic definition based on the Spring framework; a mapping relationship between a policy implementation and a policy implementation identifier is established for the policy implementation carried in each policy container; the method includes: When a call instruction for a target policy implementation is detected, reading a policy implementation identifier contained in the call instruction and a target policy interface corresponding to the target policy implementation; Determine a corresponding target policy container according to the target policy interface; searching the target policy container for a policy implementation corresponding to the policy implementation identifier according to the mapping relationship, and using the found policy implementation as the target policy implementation; Carrying the target policy implementation based on the target policy container to call the target policy implementation; The policy implementation carried by any policy container is obtained in the following ways: Determine a policy interface corresponding to any one of the policy containers; Read at least one strategy implementation corresponding to the strategy interface stored in the Spring container; Adding the read policy implementation to any one of the policy containers; The mapping relationship is obtained in the following way: Read annotations corresponding to the read strategy implementation from the Spring container; Obtain the custom annotation identification logic corresponding to the strategy interface; the custom annotation identification logic is customized based on the business type corresponding to each strategy interface; the custom annotation identification logic is the identification rule for the annotations corresponding to different strategy implementations under a certain strategy interface, wherein different strategy implementations of different strategy interfaces use different custom annotation identification logics; Configure the corresponding strategy implementation identifier for the read strategy implementation according to the obtained custom annotation identification logic and the read annotation.
2. The method according to claim 1, characterized in that The policy interface of the programming device corresponds to the business type one by one, at least one policy implementation carried in any policy container belongs to the same business type, and the target policy interface contained in the calling instruction is the policy interface corresponding to the business type to which the target policy implementation belongs.
3. A device for invoking a strategy, characterized in that: Applied to a programming device, the programming device pre-creates a policy container corresponding to a policy interface, wherein the policy container is generated by calling a container generation tool in a Spring framework, and the container generation tool is obtained by a FactoryBean characteristic definition based on the Spring framework; a mapping relationship between a policy implementation and a policy implementation identifier is established for the policy implementation carried in each policy container; the device comprises: A reading unit, when detecting a call instruction for a target policy implementation, reads a policy implementation identifier contained in the call instruction and a target policy interface corresponding to the target policy implementation; A determination unit, which determines a corresponding target policy container according to the target policy interface; a searching unit, searching the target policy container for a policy implementation corresponding to the policy implementation identifier according to the mapping relationship, and using the found policy implementation as the target policy implementation; A calling unit, based on the target policy container carrying the target policy implementation, for calling the target policy implementation; The policy implementation carried in any policy container is obtained by: determining a policy interface corresponding to any policy container; reading at least one policy implementation corresponding to the policy interface stored in the Spring container; and adding the read policy implementation to any policy container; The mapping relationship is obtained in the following manner: reading annotations corresponding to the read strategy implementation from the Spring container; obtaining custom annotation identification logic corresponding to the strategy interface; the custom annotation identification logic is customized based on the business type corresponding to each strategy interface; the custom annotation identification logic is an identification rule for annotations corresponding to different strategy implementations under a certain strategy interface, wherein the strategy implementations of different strategy interfaces adopt different custom annotation identification logics; configuring a corresponding strategy implementation identification for the read strategy implementation according to the obtained custom annotation identification logic and the read annotations.
4. The device according to claim 3, characterized in that The policy interface of the programming device corresponds to the business type one by one, at least one policy implementation carried in any policy container belongs to the same business type, and the target policy interface contained in the calling instruction is the policy interface corresponding to the business type to which the target policy implementation belongs.
5. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 1 to 2 by running the executable instructions.
6. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the instruction is executed by a processor, the steps of the method according to any one of claims 1 to 2 are implemented.
Citation Information
Patent Citations
System and method for developing business process policies
CA2452719A1
Method for implementing application and service controller
WO2017000803A1