Method and device for implementing finite-state machine based on dynamic configuration
By loading configuration files in the state machine execution engine and decoupling configuration and code, a dynamic configuration finite state machine is realized, which solves the problem of inflexible state machine configuration in the existing technology, and improves the flexibility and stability of the system .
Patent Information
- Application Number
- CN202411011426.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-25
- Publication Date
- 2024-11-15
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing state machine configuration is hard-coded in the code, resulting in the need to modify the code and repost it online in dynamically changing scenarios, which lacks flexibility and increases maintenance costs.
By defining the state machine execution engine, introducing Spring-related Maven dependencies, loading the state machine configuration file from the configuration center or local directory, and authenticating it. When the authentication is passed, the state machine execution engine triggers the business state transition action, and performs the The required business logic is extracted and the configuration files are placed independently, and decoupled from the state machine execution engine to realize flexible configuration and code-free modification functions.
Improves the flexibility of state machine configuration and system stability, saves maintenance costs, and avoids the need to modify code when adding or modifying configurations.
Smart Images

Figure CN118963866A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of state machine configuration, and in particular to an implementation method, device, computer equipment and storage medium of a finite state machine based on dynamic configuration. Background Art
[0002] A finite-state machine (FSM), also known as a finite-state automaton (FSA), is a mathematical computational model that represents a finite number of states and behaviors such as transitions and actions between these states. It is often used to control business processes involving multiple state transitions, such as a typical e-commerce transaction scenario.
[0003] Currently, there are many ways to implement state machines, and the most commonly used one is Spring State Machine (hereinafter referred to as SSM). SSM is a framework provided by Spring Framework (an application framework for the Java platform), which allows developers to combine traditional state machine concepts with Spring applications. For example, taking the order state machine as an example, the steps to implement the order state machine through SSM include: introducing the Maven dependency of SSM; creating order state enumeration and order state transition event enumeration; creating order state transition configuration and configuring the state machine; creating an order event listener, listening to transition events, and doing specific business logic.
[0004] However, when implementing the above-mentioned order creation state transition configuration and configuring the state machine, since the configuration of the state machine is hard-coded in the code, especially for scenarios that require dynamic changes, the code needs to be modified and re-published to take effect, which is not flexible enough and also increases maintenance costs. Summary of the invention
[0005] Based on this, it is necessary to provide an implementation method, apparatus, computer device and storage medium based on a dynamically configured finite state machine to address the above technical issues, so as to solve at least one problem existing in the above-mentioned prior art.
[0006] In a first aspect, the embodiment of the present application is implemented by providing an implementation method based on a dynamically configured finite state machine, comprising the following steps:
[0007] Define a state machine execution engine, and introduce spring-related Maven dependencies into the state machine execution engine;
[0008] Loading the state machine configuration file from a configuration center or a local directory through the state machine execution engine, and authenticating the state machine configuration file;
[0009] When the authentication is passed, the state machine execution engine is called to trigger the service state transition action, and the service logic required for the service transition action is executed.
[0010] In one embodiment, calling the state machine execution engine to trigger a service state transition action to execute the service logic required for the service transition action includes:
[0011] Initializing local data of the state machine execution engine, the local data including a process template;
[0012] Obtain the business ID and business status from the context model;
[0013] Determine whether there is a target process template matching the business identifier in the process template;
[0014] If so, determining whether there is a target execution node that matches the business state and the target process template;
[0015] If yes, find the execution program corresponding to the target execution node from the spring container to execute the business logic required for the business transition action;
[0016] After the execution is completed, the execution result is returned to the upper business call layer.
[0017] In one embodiment, determining whether there is a target process template matching the service identifier in the process templates includes:
[0018] Constructing a mapping relationship between the business identifier and the process template;
[0019] Based on the mapping relationship between the service identifier and the process template, it is determined whether there is a target process template matching the service identifier.
[0020] In one embodiment, before the state machine execution engine loads the state machine configuration file from a configuration center or a local directory, the process includes:
[0021] Get business type;
[0022] Based on the service type, determining a service state and a service state transition event;
[0023] The state machine configuration file is generated based on the service state and the service state transition event.
[0024] In one embodiment, authenticating the state machine configuration file includes:
[0025] Parsing the state machine configuration file to obtain a state machine process file, wherein the state machine process file includes a plurality of process nodes;
[0026] Determining whether the process node meets the preset authentication conditions;
[0027] If so, the state machine configuration file is authenticated successfully.
[0028] In one embodiment, the defining of the state machine execution engine includes:
[0029] Introduce spring-related Maven dependencies;
[0030] Defining a data model of the state machine execution engine, the data model comprising a transition model, a node model, a template model and a context model;
[0031] A plurality of interfaces of the state machine execution engine are defined, and implementation functions of target interfaces in the interfaces are configured.
[0032] In one embodiment, the defining of multiple interfaces of the state machine execution engine and configuring the implementation function of the target interface in the interface includes:
[0033] Creating an internal interface of the state machine execution engine and implementing the functions of the internal interface, wherein the internal interface includes an engine execution interface;
[0034] Create an external interface for the state machine execution engine to implement its functions when the upper-layer business logic accesses it;
[0035] Implement the internal logic of the engine execution interface.
[0036] In a second aspect, an implementation device based on a dynamically configurable finite state machine is provided, comprising:
[0037] An execution engine definition unit is used to define a state machine execution engine, into which spring-related Maven dependencies are introduced;
[0038] An authentication unit, used to load the state machine configuration file from a configuration center or a local directory through the state machine execution engine, and authenticate the state machine configuration file;
[0039] The state machine execution engine execution unit is used to call the state machine execution engine to trigger the service state transition action when the authentication is passed, and execute the service logic required for the service transition action.
[0040] In a third aspect, a computer device is provided, comprising a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor, wherein the processor implements the steps of implementing a dynamically configurable finite state machine as described above when executing the computer-readable instructions.
[0041] In a fourth aspect, a readable storage medium is provided, wherein the readable storage medium stores computer-readable instructions, wherein the computer-readable instructions, when executed by a processor, implement the steps of the implementation method of a dynamically configurable finite state machine as described above.
[0042] The above-mentioned implementation method, device, computer equipment and storage medium based on dynamically configured finite state machine, its method implementation includes: defining a state machine execution engine, introducing spring-related Maven dependencies into the state machine execution engine; loading the state machine configuration file from the configuration center or local directory through the state machine execution engine, and authenticating the state machine configuration file; when the authentication is passed, calling the state machine execution engine to trigger the business state transition action, and executing the business logic required for the business transition action. In the embodiment of the present application, the configuration of the state machine is extracted and placed independently in the configuration file, that is, the configuration and the state machine execution engine are decoupled, the state machine configuration can be flexibly customized, and when adding or modifying the state machine configuration, there is no need to modify the code and release it online, which can improve configuration flexibility, save maintenance costs, and improve system stability. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0044] Figure 1 It is a flowchart of an implementation method based on a dynamically configurable finite state machine in one embodiment of the present invention;
[0045] Figure 2 It is a flow chart of a method for implementing a state machine execution engine in one embodiment of the present invention;
[0046] Figure 3 is a schematic diagram of a definition environment of a state machine execution engine related data model in one embodiment of the present invention;
[0047] Figure 4 It is a schematic diagram of an interface definition environment in a state machine execution engine in an embodiment of the present invention;
[0048] Figure 5 It is a structural schematic diagram of an implementation device based on a dynamically configurable finite state machine in one embodiment of the present invention;
[0049] Figure 6 is a schematic diagram of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION
[0050] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0051] In one embodiment, if Figure 1 As shown, a method for implementing a finite state machine based on dynamic configuration is provided, comprising the following steps:
[0052] In step S110, a state machine execution engine is defined, and spring-related Maven dependencies are introduced into the state machine execution engine;
[0053] In an embodiment of the present application, a state machine execution engine is used to execute a state flow process. For example, taking an e-commerce transaction order as an example, the specific state flow process may include paid, shipped, confirmed receipt, etc.
[0054] In the embodiment of the present application, by adding spring-related Maven dependencies to the state machine execution engine, for example, spring-expression, spring-beans, spring-context, etc., it can be used to manage business dependencies, which may specifically include dependency identifiers and version numbers. Maven dependencies can find all dependencies by traversing the dependency graph and define the state machine execution engine.
[0055] Among them, the spring can be an open source design-level framework. By combining the state machine with spring, it can provide state machine flow control, event listening, and Spring Ioc (inversion of control) integration to associate beans with state machines and other functions. The bean can be a Java-based component model, which can free developers from the cumbersome state machine implementation and focus more on the development of business logic.
[0056] In step S120, the state machine configuration file is loaded from a configuration center or a local directory through the state machine execution engine, and the state machine configuration file is authenticated;
[0057] In an embodiment of the present application, after obtaining the state machine configuration file, the state machine configuration file can be parsed by a file parser, or it can be implemented by using two methods in the SrsConfDirective class. For example, parse_conf can parse all instructions in the current instruction area in a loop. When an instruction in the instruction area encounters a sub-instruction block, parse_conf will be called nested to parse the sub-instruction block, and parsing command names, command parameters, returning parsing status, etc. can be parsed by read_token.
[0058] It can be understood that the state machine configuration file may include a process file, and the process file may include multiple process nodes such as a start node, an end node, a process node, etc. Different nodes can be represented by different classes under Java. For example, the code file can be searched to determine whether there are corresponding start nodes, end nodes, and process nodes. If so, the configuration file is a legal file, that is, the authentication is successful; otherwise, it is an illegal file, that is, the authentication fails, and the current process is terminated.
[0059] In step S150, when the authentication is passed, the state machine execution engine is called to trigger the service state transition action and execute the service logic required for the service transition action.
[0060] In an embodiment of the present application, the state machine execution engine may include multiple related data models, such as a context model, a node model, a push model, a template model, etc. After obtaining the state machine configuration file, the corresponding template and the corresponding node can be matched based on the business type and business status of the state machine configuration file, and the bean corresponding to the node can be found and executed from the spring container. After execution, the result can be returned to the upper-level business call.
[0061] In an embodiment of the present application, a method for implementing a finite state machine based on dynamic configuration is provided, including: defining a state machine execution engine, introducing spring-related Maven dependencies into the state machine execution engine; loading the state machine configuration file from a configuration center or a local directory through the state machine execution engine, and authenticating the state machine configuration file; when the authentication is passed, calling the state machine execution engine to trigger a business state transition action, and executing the business logic required for the business transition action. In an embodiment of the present application, the configuration of the state machine is extracted and placed independently in the configuration file, that is, the configuration and the state machine execution engine are decoupled, the state machine configuration can be flexibly customized, and when adding or modifying the state machine configuration, there is no need to modify the code and release it online, which can improve configuration flexibility, save maintenance costs, and improve system stability.
[0062] See also Figure 2In one embodiment of the present application, the calling of the state machine execution engine to trigger the service state transition action to execute the service logic required for the service transition action includes:
[0063] Initializing local data of the state machine execution engine, the local data including a process template;
[0064] Obtain the business ID and business status from the context model;
[0065] Determine whether there is a target process template matching the business identifier in the process template;
[0066] If so, determining whether there is a target execution node that matches the business state and the target process template;
[0067] If yes, find the execution program corresponding to the target execution node from the spring container to execute the business logic required for the business transition action;
[0068] After the execution is completed, the execution result is returned to the upper business call layer.
[0069] Specifically, the state machine configuration file is determined based on business needs, and after parsing the state machine configuration file, the legitimacy is verified. When the verification is passed, the local data of the state machine execution engine can be initialized. The local data may include multiple data models, such as context, node, template, etc. The context model can store multiple business identifiers and business states to represent different business types. The business state is used to represent the current business state corresponding to the corresponding business type. Based on the business identifier, it can be determined whether there is a process template corresponding to the business identifier in the process template. If so, based on the process template and the current business state, it is determined whether there is a node corresponding to the business state in the node. If so, the bean corresponding to the target execution node is found from the spring container, that is, the execution program, to execute the business logic required for the business transition action. After the execution is completed, the execution result is returned to the upper-level business call layer.
[0070] Among them, different process templates are constructed based on different business types, such as approval business template, payment business template, after-sales business template, etc. The node can be a common process node in the business processing flow, for example, it can include nodes such as waiting for payment, waiting for receipt, waiting for inquiry, and receipt completion.
[0071] It can be understood that the state machine execution engine is also provided with business state transition events for triggering the node flow, such as order creation, order cancellation, payment and other events.
[0072] In an embodiment of the present application, determining whether there is a target process template matching the service identifier in the process template includes:
[0073] Constructing a mapping relationship between the business identifier and the process template;
[0074] Based on the mapping relationship between the service identifier and the process template, it is determined whether there is a target process template matching the service identifier.
[0075] Specifically, the context model may store multiple business identifiers and business states in advance, and the business identifier may be used to uniquely identify the state machine configuration file corresponding to the business type, and the business state may be used to indicate the current business processing status, such as pending payment, pending receipt, etc. Therefore, a mapping relationship between the business identifier and the process template may be established in advance, and similarly, a mapping relationship between the business state, the process template and the node may also be established. When the business identifier and business state corresponding to the state machine configuration file are obtained, it may be first queried whether there is a matching process template based on the business identifier. If so, it may be queried again based on the process template and the business state to see whether there is a matching execution node.
[0076] In an embodiment of the present application, before the state machine configuration file is loaded from the configuration center or the local directory by the state machine execution engine, the following steps are included:
[0077] Get business type;
[0078] Based on the service type, determining a service state and a service state transition event;
[0079] The state machine configuration file is generated based on the service state and the service state transition event.
[0080] Specifically, the service type can be determined according to the current service needs, and the service status and service status transition events can be enumerated based on the service type, so as to obtain the service status and service status transition events corresponding to the service type. The service status can be different according to different service types.
[0081] Exemplarily, the business type may be payment business, approval business, after-sales business, customer service business, e-commerce order business, etc. For example, taking the e-commerce order business as an example, its business status specifically refers to the current business status. For example, after the user adds the product to the shopping cart, its corresponding business status may be waiting for payment. After the user pays, its corresponding business status may be waiting for shipment. After the merchant ships the product, the corresponding business status may be waiting for confirmation of receipt. After the user receives the product, its corresponding business status may be confirmed receipt. It can be understood that the business status transition event specifically refers to the business status flow action, such as the user performs a payment action, the merchant performs a shipment action, the user performs a confirmation of receipt action, etc.
[0082] Among them, the state machine can be used to describe the state in different time periods and the conversion operations that may be performed when a specific event is received. The state machine configuration file can be used to determine the state machine, which is configured with the state machine's inherent set of state machine logic to be executed. For example, it can be initially set through a state machine configuration tool.
[0083] It can be understood that different business scenarios may correspond to different state machines. For example, payment business may correspond to a payment state machine, and approval business may correspond to an approval state machine. Different business state machines correspond to different business states and business transition events. Therefore, the state machine configuration file can be determined through predetermined business states and business state transition events.
[0084] It should be noted that the state machine configuration file can be stored in a configuration center, such as apollo, or in a local project.
[0085] In an embodiment of the present application, authenticating the state machine configuration file includes:
[0086] Parsing the state machine configuration file to obtain a state machine process file, wherein the state machine process file includes a plurality of process nodes;
[0087] Determining whether the process node meets the preset authentication conditions;
[0088] If so, the state machine configuration file is authenticated successfully.
[0089] Specifically, the state machine configuration file can be parsed through a file parser, or it can be implemented using two methods in the SrsConfDirective class. For example, parse_conf can parse all instructions in the current instruction area in a loop. When an instruction in the instruction area encounters a sub-instruction block, parse_conf will be called nested to parse the sub-instruction block. Parsing command names, command parameters, returning parsing status, etc. can be parsed by read_token.
[0090] After parsing, the process file of the state machine can be obtained, which includes multiple process nodes, such as a start node, an end node, a process node, etc., and legality verification is performed based on the node. For example, it is determined whether there are multiple start nodes. If so, the verification fails. For example, whether there is a start node, an end node or a process node. If not, the verification fails.
[0091] In one embodiment of the present application, the definition of the state machine execution engine includes:
[0092] Introduce spring-related Maven dependencies;
[0093] Defining a data model of the state machine execution engine, the data model comprising a transition model, a node model, a template model and a context model;
[0094] A plurality of interfaces of the state machine execution engine are defined, and implementation functions of target interfaces in the interfaces are configured.
[0095] Specifically, by adding spring-related Maven dependencies to the state machine execution engine, such as spring-expression, spring-beans, spring-context, etc., it can be used to manage business dependencies, which may specifically include dependency identifiers and version numbers. Maven dependencies can find all dependencies by traversing the dependency graph, build the state machine execution engine, and define and implement the relevant data models and interfaces of the state machine execution engine.
[0096] Among them, see Figure 3 The state machine execution engine may include multiple related data models, including context model (Context), template (template), transition (Transition) and node (Node). The specific definition of each model is as follows:
[0097] The context model (Context) may include input parameter objects, output parameter objects, names of transitions, and names of state machine identifiers.
[0098] The transition model is used to represent the transfer and replacement between business states. The model defines the state transition events that can trigger the current transition, which can usually be triggered by the outside of the state machine execution engine, the transfer to the target node after the transition occurs, and the actions triggered during the transition. It should be noted that the action can implement specific business logic and can be specified by the outside of the state machine execution engine.
[0099] The node model (Node) is used to indicate which transformations can occur under a certain condition. For example, when an order is created, it can be paid or closed. It specifically defines the node name, the condition that matches the current node, the set of transformations that can occur at the node, and whether it is a start / end node. It should be noted that the condition that matches the current node can be implemented using Spring Expression Language, that is, Spring expression language.
[0100] The template model (template) is used to represent the state machine transition configuration in a business scenario. It specifically defines the template name and template id, which can be used to identify uniqueness, node list, start transition set, and can be used to distinguish the start state of the state machine. It should be noted that in the template model, the init() initialization method can be used to fill the start transition into the above start transition set, and the isStartTransition() method can be used to determine whether a transition is a start transition.
[0101] Among them, see Figure 4 The interface of the state machine execution engine may specifically include the StateMachineEngine interface, the ConditionCheck interface, the Action interface, and the TemplateIdentifier interface. The specific definition of the interface is as follows:
[0102] The StateMachineEngine interface is the entry point for the state machine engine to provide external services.
[0103] perform(Context) is the specific calling method, which takes the Context as the input parameter and is used to pass the parameters required during the execution process.
[0104] The ConditionCheck interface is used to perform conditional checks on nodes in the matching template during the execution of the state machine engine.
[0105] Action interface, which represents the action triggered when the conversion occurs. Business logic is usually implemented in the action and is implemented by the upper-level user.
[0106] TemplateIdentifier interface is used to match a specific template according to the context during the execution of the state machine engine. Usually the upper layer will configure multiple templates according to different scenarios, and the engine needs to match a specific template to execute during execution.
[0107] In an embodiment of the present application, the defining of multiple interfaces of the state machine execution engine and configuring the default implementation of the target interface includes:
[0108] Creating an internal interface of the state machine execution engine and implementing the functions of the internal interface, wherein the internal interface includes an engine execution interface;
[0109] Create an external interface for the state machine execution engine to implement its functions when the upper-layer business logic accesses it;
[0110] Implement the internal logic of the engine execution interface.
[0111] Specifically, the internal interface of the state machine execution engine can be defined, such as the execution interface and node matching interface of the state machine execution engine, to reserve certain extensions for the follow-up, and implement the functions of the internal interface. Then, the external interface of the state machine execution engine can be defined to implement its functions when the upper-level business logic is accessed. After the internal and external interfaces are defined, the internal logic of the engine execution interface can be implemented.
[0112] In one embodiment, the internal interface includes a node matching interface and a template matching interface, and the implementation of the internal interface includes:
[0113] Determine a template matching the service identifier through a template matching interface;
[0114] According to the node usage conditions, a corresponding parser is used to perform condition matching verification, so as to match the node in the template through the node matching interface;
[0115] Specifically, the node matching interface, namely the ConditionCheck interface, can be implemented as follows: the node condition uses Spring Expression Language (Spring expression language, such as "status == 'paid'"), and the condition matching is verified by the Spring Expression Language parser. The code implementation is as follows:
[0116] Parser.paresExpression(condition).getValue(evalContext,Boolean.class)
[0117] The implementation of the template matching interface, i.e., the StateMachineEngine interface, is as follows: the state machine configuration file is in json format, so it is necessary to load the configuration file in json format, i.e., the template file, when the application is initialized. It can be loaded locally or from a configuration center, such as apollo. After loading, the template file needs to be parsed to verify its legitimacy, and then the parsed template file is stored locally. The core logic of the perform(Context) method defined in the StateMachineEngine interface is to first match a template from the local template file loaded as described above according to the Context context, and throw an exception if no match is found. If a match is found, a specific Node node is matched according to the Context context and the matched template file, and then a specific transition is matched according to the transition name in the Context context, and finally the action in the transition is executed to complete the business logic corresponding to a certain state transition. In this way, the execution of the entire state machine engine is completed.
[0118] It is understandable that by reading the configuration file from the configuration center or locally, the configuration and code are separated, and the configuration can be adjusted without modifying the code, thereby improving efficiency.
[0119] In the embodiment of the present application, a state machine execution engine is constructed, a state machine configuration file that conforms to its own business is customized, and the actions corresponding to the state transition are implemented at the same time. Finally, the state machine execution engine is called during the execution of the business process to trigger the state transition action and execute the business logic required for the state transition. The configuration of the state machine is extracted and placed independently in the configuration file, that is, the configuration and the state machine execution engine are decoupled, the state machine configuration can be flexibly customized, and when adding or modifying the state machine configuration, there is no need to modify the code and release it online, which can improve configuration flexibility, save maintenance costs, and improve system stability.
[0120] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0121] In one embodiment, a device for implementing a finite state machine based on dynamic configuration is provided, and the device for implementing a finite state machine based on dynamic configuration corresponds to the implementation method of the finite state machine based on dynamic configuration in the above embodiment. Figure 5 As shown, the implementation device based on the dynamically configured finite state machine includes an execution engine definition unit 10, an authentication unit 20 and a state machine execution engine execution unit 30. The functional modules are described in detail as follows:
[0122] An execution engine definition unit 10 is used to define a state machine execution engine, into which spring-related Maven dependencies are introduced;
[0123] An authentication unit 20, configured to load the state machine configuration file from a configuration center or a local directory through the state machine execution engine, and authenticate the state machine configuration file;
[0124] The state machine execution engine execution unit 30 is used to call the state machine execution engine to trigger the service state transition action when the authentication is passed, and execute the service logic required for the service transition action.
[0125] In one embodiment of the present application, the state machine execution engine execution unit 30 is further used to:
[0126] Initializing local data of the state machine execution engine, the local data including a process template;
[0127] Obtain the business ID and business status from the context model;
[0128] Determine whether there is a target process template matching the business identifier in the process template;
[0129] If so, determining whether there is a target execution node that matches the business state and the target process template;
[0130] If yes, find the execution program corresponding to the target execution node from the spring container to execute the business logic required for the business transition action;
[0131] After the execution is completed, the execution result is returned to the upper business call layer.
[0132] In one embodiment of the present application, the state machine execution engine execution unit 30 is further used to:
[0133] Constructing a mapping relationship between the business identifier and the process template;
[0134] Based on the mapping relationship between the service identifier and the process template, it is determined whether there is a target process template matching the service identifier.
[0135] In an embodiment of the present application, the device further includes: a state machine configuration file generating unit, configured to:
[0136] Get business type;
[0137] Based on the service type, determining a service state and a service state transition event;
[0138] The state machine configuration file is generated based on the service state and the service state transition event.
[0139] In one embodiment of the present application, the authentication unit 20 is further configured to:
[0140] Parsing the state machine configuration file to obtain a state machine process file, wherein the state machine process file includes a plurality of process nodes;
[0141] Determining whether the process node meets the preset authentication conditions;
[0142] If so, the state machine configuration file is authenticated successfully.
[0143] In one embodiment of the present application, the execution engine definition unit 10 is further used to:
[0144] Introduce spring-related Maven dependencies;
[0145] Defining a data model of the state machine execution engine, the data model comprising a transition model, a node model, a template model and a context model;
[0146] A plurality of interfaces of the state machine execution engine are defined, and implementation functions of target interfaces in the interfaces are configured.
[0147] In one embodiment of the present application, the execution engine definition unit 10 is further used to:
[0148] Creating an internal interface of the state machine execution engine and implementing the functions of the internal interface, wherein the internal interface includes an engine execution interface;
[0149] Create an external interface for the state machine execution engine to implement its functions when the upper-layer business logic accesses it;
[0150] Implement the internal logic of the engine execution interface.
[0151] In the embodiment of the present application, a state machine execution engine is constructed, a state machine configuration file that conforms to its own business is customized, and the actions corresponding to the state transition are implemented at the same time. Finally, the state machine execution engine is called during the execution of the business process to trigger the state transition action and execute the business logic required for the state transition. The configuration of the state machine is extracted and placed independently in the configuration file, that is, the configuration and the state machine execution engine are decoupled, the state machine configuration can be flexibly customized, and when adding or modifying the state machine configuration, there is no need to modify the code and release it online, which can improve configuration flexibility, save maintenance costs, and improve system stability.
[0152] For the specific limitations of the implementation device based on the dynamically configured finite state machine, please refer to the limitations of the implementation method based on the dynamically configured finite state machine mentioned above, which will not be repeated here. Each module in the above-mentioned implementation device based on the dynamically configured finite state machine can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0153] In one embodiment, a computer device is provided. The computer device may be a terminal device, and its internal structure diagram may be as follows: Figure 6 As shown. The computer device includes a processor, a memory, and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a readable storage medium. The readable storage medium stores computer-readable instructions. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer-readable instructions are executed by the processor, a method for implementing a finite state machine based on dynamic configuration is implemented. The readable storage medium provided in this embodiment includes a non-volatile readable storage medium and a volatile readable storage medium.
[0154] In an embodiment of the present application, a computer device is provided, including a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor. When the processor executes the computer-readable instructions, the steps of the implementation method of the dynamically configurable finite state machine as described above are implemented.
[0155] In an embodiment of the application, a readable storage medium is provided, wherein the readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the implementation method of the dynamically configurable finite state machine as described above are implemented.
[0156] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing related hardware through computer-readable instructions, and the computer-readable instructions can be stored in a non-volatile readable storage medium or a volatile readable storage medium. When the computer-readable instructions are executed, they may include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0157] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0158] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.
Claims
1. A method for implementing a finite state machine based on dynamic configuration, characterized in that: The method comprises: Define a state machine execution engine, and introduce spring-related Maven dependencies into the state machine execution engine; Loading the state machine configuration file from a configuration center or a local directory through the state machine execution engine, and authenticating the state machine configuration file; When the authentication is passed, the state machine execution engine is called to trigger the service state transition action, and the service logic required for the service transition action is executed.
2. The implementation method of the finite state machine based on dynamic configuration as claimed in claim 1, characterized in that: The calling of the state machine execution engine to trigger the service state transition action to execute the service logic required for the service transition action includes: Initializing local data of the state machine execution engine, the local data including a process template; Obtain the business ID and business status from the context model; Determine whether there is a target process template matching the business identifier in the process template; If so, determining whether there is a target execution node that matches the business state and the target process template; If yes, find the execution program corresponding to the target execution node from the spring container to execute the business logic required for the business transition action; After the execution is completed, the execution result is returned to the upper business call layer.
3. The implementation method of the finite state machine based on dynamic configuration as claimed in claim 2, characterized in that: The determining whether there is a target process template matching the service identifier in the process templates includes: Constructing a mapping relationship between the business identifier and the process template; Based on the mapping relationship between the service identifier and the process template, it is determined whether there is a target process template matching the service identifier.
4. The implementation method of the finite state machine based on dynamic configuration as claimed in claim 1, characterized in that: Before the state machine configuration file is loaded from the configuration center or the local directory by the state machine execution engine, the following steps are included: Get business type; Based on the service type, determining a service state and a service state transition event; The state machine configuration file is generated based on the service state and the service state transition event.
5. The implementation method of the finite state machine based on dynamic configuration as claimed in claim 1, characterized in that: The authenticating the state machine configuration file includes: Parsing the state machine configuration file to obtain a state machine process file, wherein the state machine process file includes a plurality of process nodes; Determining whether the process node meets the preset authentication conditions; If so, the state machine configuration file is authenticated successfully.
6. The implementation method of the finite state machine based on dynamic configuration as claimed in claim 1, characterized in that: The defined state machine execution engine comprises: Introduce spring-related Maven dependencies; Defining a data model of the state machine execution engine, the data model comprising a transition model, a node model, a template model and a context model; A plurality of interfaces of the state machine execution engine are defined, and implementation functions of target interfaces in the interfaces are configured.
7. The implementation method of the finite state machine based on dynamic configuration as claimed in claim 6, characterized in that: The defining of multiple interfaces of the state machine execution engine and configuring the implementation function of the target interface in the interface includes: Creating an internal interface of the state machine execution engine and implementing the functions of the internal interface, wherein the internal interface includes an engine execution interface; Create an external interface for the state machine execution engine to implement its functions when the upper-layer business logic accesses it; Implement the internal logic of the engine execution interface.
8. An implementation device based on a dynamically configurable finite state machine, characterized in that: The device comprises: An execution engine definition unit is used to define a state machine execution engine, into which spring-related Maven dependencies are introduced; An authentication unit, used to load the state machine configuration file from a configuration center or a local directory through the state machine execution engine, and authenticate the state machine configuration file; The state machine execution engine execution unit is used to call the state machine execution engine to trigger the service state transition action when the authentication is passed, and execute the service logic required for the service transition action.
9. A computer device comprising a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor, characterized in that: When the processor executes the computer-readable instructions, the processor implements the steps of implementing the dynamically configurable finite state machine according to any one of claims 1 to 7.
10. A readable storage medium storing computer-readable instructions, characterized in that: When the computer-readable instructions are executed by a processor, the steps of the implementation method based on a dynamically configurable finite state machine as described in any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Method for controlling business system by dynamic modeling of state machine
CN103049264A
Implementation method and device of state machine engine, computer equipment and storage medium
CN110580155A
Business processing method and device, electronic equipment and computer readable medium
CN117273177A
