State machine configuration method and device, electronic equipment, storage medium and program product
By configuring the state merging function of the state machine, the problems of high complexity and error-prone traditional state machine configuration methods are solved, and simpler and more accurate state machine configuration is achieved.
Patent Information
- Application Number
- CN202411728551.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-28
- Publication Date
- 2025-02-28
AI Technical Summary
Traditional state machine configuration methods are complex and prone to configuration errors or omissions.
By obtaining the preset state transition rules for the state machine, determining the state group, and configuring the state merging function for the state machine, it enables it to merge multiple states into one state.
Reduces the complexity of state transition configuration of the state machine and reduces possible errors or omissions during the configuration process.
Smart Images

Figure CN119536858A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a state machine configuration method, device, electronic device, storage medium and program product. Background Art
[0002] As a tool for implementing and managing data state transitions in the Spring framework, state machines are widely used in a variety of projects. However, the traditional state machine configuration method requires developers to exhaustively list all possible data state changes. For example, if a piece of data contains 10 states, and any of these states can be transformed into any other state, then configuring the state machine requires a detailed list of 90 possible state transitions. This configuration method is not only complex, but also prone to configuration errors or omissions due to the cumbersome configuration. Summary of the invention
[0003] In response to the above technical problems, the embodiments of the present application provide a state machine configuration method, device, electronic device, storage medium and program product, which can reduce the complexity of the state transition configuration of the state machine, and also reduce the errors or omissions that may occur during the state transition configuration process.
[0004] The technical solution of this application is implemented as follows:
[0005] In a first aspect, an embodiment of the present application provides a state machine configuration method, including:
[0006] Get the state transition rules preset for the state machine to be configured;
[0007] Based on the state transition rule, at least one state group is determined; the target transition state of each state in each state group under the same trigger event is the same state;
[0008] The state machine is configured with a state merging function so that the state machine has the function of merging the states in the state groups into one state.
[0009] In some embodiments, the state machine is configured with a state merging function so that the state machine has a function of merging each state in each state group into one state, including:
[0010] Define a state enumeration class, and overload the constructor of the state enumeration class so that the state enumeration class supports the state merging function;
[0011] A static method for obtaining the merge status is defined in the status enumeration class.
[0012] In some embodiments, the input parameters of the static method include the current state parameters and the current trigger event parameters of the state machine, and the return parameters of the static method include the merged state parameters, which are the parameters that the static method uses to merge and transform the current state parameters based on the current state parameters and the current trigger event parameters.
[0013] In some embodiments, the state machine configuration method further includes:
[0014] A data reading method is defined in the state machine persistence interface, and the data reading method is used to read the current state of the state machine from the persistent storage, and call the static method during the reading process to convert the read current state into a merged state.
[0015] In some embodiments, the state machine configuration method further includes:
[0016] The current trigger event received by the state machine is embedded in the context object of the state machine.
[0017] In some embodiments, the data reading method is further used for:
[0018] The current trigger event received by the state machine is obtained from the context object, and the obtained current trigger event is used as the current trigger event parameter included in the input parameter of the called static method.
[0019] In a second aspect, an embodiment of the present application provides a state machine configuration device, including:
[0020] An acquisition module, used to acquire a state transition rule preset for a state machine to be configured;
[0021] A determination module, configured to determine at least one state group based on the state transition rule; the target transition states of the states in each state group under the same triggering event are the same state;
[0022] The configuration module is used to configure the state merging function for the state machine so that the state machine has the function of merging the states in the state groups into one state.
[0023] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory and a processor, wherein the memory is used to store executable data instructions; when the processor is used to execute the executable data instructions stored in the memory, the steps in the state machine configuration method described in the first aspect are implemented.
[0024] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps in the state machine configuration method described in the first aspect are implemented.
[0025] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program or instructions, which, when executed by a processor, implements the steps in the state machine configuration method described in the first aspect.
[0026] The state machine configuration method, device, electronic device, storage medium and program product provided in the embodiments of the present application first obtain the state transition rules preset for the state machine to be configured, and then determine at least one state group based on the state transition rules, and the target transition state of each state in each state group under the same trigger event is the same state, and then configure the state machine for a state merging function so that the state machine has the function of merging each state in each state group into one state. This state merging function can reduce the total number of states in the state machine, and the state transition paths that the state machine needs to manage and maintain are also reduced accordingly, thereby reducing the complexity of the state transition configuration of the state machine, and also reducing the errors or omissions that may occur during the state transition configuration process. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0028] Figure 1 One of the flow charts of a state machine configuration method provided in an embodiment of the present application;
[0029] Figure 2 A second flow chart of a state machine configuration method provided in an embodiment of the present application;
[0030] Figure 3 A third flow chart of a state machine configuration method provided in an embodiment of the present application;
[0031] Figure 4 A schematic diagram of the structure of a state machine configuration device provided in an embodiment of the present application;
[0032] Figure 5 A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0033] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0034] In order to facilitate a clearer understanding of the embodiments of the present application, some related technologies are first introduced as follows.
[0035] The traditional state machine configuration method requires developers to exhaust all possibilities of data state changes. If the total number of states in the state machine is N, then the complexity of the state machine configuration is N×N when the state machine is configured according to the traditional state machine configuration method. This configuration method is not only complex, but also prone to configuration errors or configuration omissions.
[0036] In order to overcome the above-mentioned defects of the traditional state machine configuration method, the embodiments of the present application provide a state machine configuration method, device, electronic device, storage medium and program product, which can reduce the total number of states in the state machine and reduce the complexity of the state machine configuration from N×N to N. At the same time, since the total number of states in the state machine is reduced, the simplified state machine structure is clearer, and the conversion relationship between states is more intuitive, which can also reduce the errors or omissions that may occur in the state machine state conversion configuration process.
[0037] The following is an illustrative introduction to the state machine configuration method, device, electronic device, storage medium and program product provided in the embodiments of the present application in conjunction with the drawings in the embodiments of the present application.
[0038] Figure 1 One of the flow charts of a state machine configuration method provided in an embodiment of the present application is as follows: Figure 1 As shown, the method includes:
[0039] S101: Acquire a state transition rule preset for a state machine to be configured.
[0040] It should be noted that the execution subject of the state machine configuration method provided in the embodiment of the present application can be an electronic device, a component in an electronic device, an integrated circuit or a chip. The electronic device can be a mobile electronic device or a non-mobile electronic device. Exemplarily, the mobile electronic device can be a mobile phone, a tablet computer, a laptop computer, a handheld computer, a wearable device, an ultra-mobile personal computer (Ultra-mobile Personal Computer, UMPC), a netbook or a personal digital assistant (Personal Digital Assistant, PDA), etc., and the non-mobile electronic device can be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (Personal Computer, PC), a teller machine or a self-service machine, etc., and the embodiment of the present application does not specifically limit this.
[0041] The following describes in detail the technical solution of the embodiment of the present application by taking a computer executing the state machine configuration method provided by the embodiment of the present application as an example.
[0042] In some embodiments, the state machine to be configured may be a Spring state machine applicable to various business scenarios that require management of complex state transitions.
[0043] It should be noted that a state machine is a mathematical model that describes the sequence of states that an object may experience during its life cycle and the transition rules between these states. These rules are defined based on actual application scenarios and business logic to ensure that the state machine can correctly simulate and control the behavior of the system.
[0044] It should be noted that the state transition rule defines how the state machine transitions between different states. A state is a behavior mode or condition of a state machine at a certain moment, and the state machine performs its functions by transitioning between different states.
[0045] It should be noted that the state transition rules of the state machine can be preset based on actual application scenarios and business logic.
[0046] In some embodiments, the state transition rules of the state machine can be extracted based on the project's business requirement documents (these documents usually describe the system's business processes, state transitions, and event triggering conditions in detail).
[0047] S102: Determine at least one state group based on the state transition rule; the target transition state of each state in each state group under the same triggering event is the same state.
[0048] It should be noted that an event is an external signal or condition that triggers a state transition. When a state machine receives an event, it will decide whether to perform a state transition based on the current state and the preset state transition rules. A transition is the process of going from one state to another. It is usually triggered by an event and may be accompanied by the execution of some actions.
[0049] It should be noted that the configuration of the Spring state machine supports multiple source states to be converted to the same target state under the same trigger event. This is a many-to-one configuration.
[0050] In the embodiment of the present application, at least one state group can be determined based on a state transition rule preset for the state machine to be configured, wherein the target transition state of each state in each state group under the same trigger event is the same state.
[0051] For example, in an e-commerce order processing system, the following statuses are defined: pending payment (the order has been created but not paid yet), paid (the order has been paid but not shipped yet), shipped (the order has been shipped but not received yet), completed (the order has been received and completed), and canceled (the order has been canceled).
[0052] The transition rules of these states in the e-commerce order processing system are: when the order is paid, it is converted from the "pending payment" state to the "paid" state; when the order is shipped, it is converted from the "paid" state to the "shipped" state; when the order is received, it is converted from the "shipped" state to the "completed" state; when the order is cancelled, it is converted from any state to the "cancelled" state.
[0053] Based on the transition rules of these states in the e-commerce order processing system, a state group can be determined, namely the "cancellable state group", which includes the three states of "pending payment", "paid" and "shipped". These three states will be converted to the "cancelled" state when the "cancel order" event is triggered.
[0054] The following is an example of a state transition: Source state: the order is in the "pending payment" state; Trigger event: the user chooses to cancel the order; Target transition state: the order transitions from the "pending payment" state to the "cancelled" state. Similarly, if the order is in the "paid" or "shipped" state, when the user chooses to cancel the order, the order will also transition from the current state to the "cancelled" state.
[0055] S103: Perform state merging function configuration for the state machine, so that the state machine has the function of merging the states in the state groups into one state.
[0056] In the embodiment of the present application, a state merging function can be configured for the state machine so that the state machine can merge the states in each state group into one state, wherein the merged state can be a new state or any state in the corresponding state group.
[0057] For example, for the state group {state 1, state 2, state 3}, the state after merging them may be a new state of state 4, or the state after merging them may be any one of state 1, state 2 and state 3.
[0058] It should be noted that the state transition relationship in the state machine can be expressed as a state transition table. In this state transition table, each row (or each node) represents a source state, each column (or each edge) represents a possible trigger event, and the value in the state transition table (or the end point of the edge) represents the target state. If there are N different states, each state may respond to M different trigger events, then the size of the state transition table will be N×M. In the worst case, each trigger event may trigger a state to transition to any one of the N possible target states, so each element in the state transition table may be different, resulting in a configuration complexity of N×N (when M is close to N, considering all possible input and output combinations). In the embodiment of the present application, by merging multiple source states (the target transition states of these source states under the same trigger event are the same state) into a unified source state, corresponding to M trigger events, each event may trigger a state to transition to one of the N possible target states. Therefore, the optimized configuration complexity is reduced to N.
[0059] It can be understood that the state machine configuration method provided in the embodiment of the present application first obtains the state transition rules preset for the state machine to be configured, and then determines at least one state group based on the state transition rules, and the target transition state of each state in each state group under the same trigger event is the same state, and then configures the state machine for a state merging function so that the state machine has the function of merging each state in each state group into one state. This state merging function can reduce the total number of states in the state machine, and the state transition paths that the state machine needs to manage and maintain are also reduced accordingly, thereby reducing the complexity of the state transition configuration of the state machine, and also reducing the errors or omissions that may occur during the state transition configuration process.
[0060] In some embodiments, the state machine is configured with a state merging function so that the state machine has a function of merging each state in each state group into one state, including:
[0061] Define a state enumeration class, and overload the constructor of the state enumeration class so that the state enumeration class supports the state merging function;
[0062] A static method for obtaining the merge status is defined in the status enumeration class.
[0063] In an embodiment of the present application, a state enumeration class may be defined, and the constructor of the state enumeration class may be overloaded so that the state enumeration class supports a state merging function, and then a static method for obtaining the merged state may be defined in the state enumeration class.
[0064] It should be noted that the state enumeration class is usually used to define and represent a limited set of states in programming. These states can be the current status of a system, object or process. In the embodiment of the present application, the state enumeration class is used to define and represent the state of the state machine, and the state merging of the state machine is realized by overloading the constructor in the state enumeration class and defining a static method for obtaining the merged state.
[0065] It should be noted that static methods are usually associated with the class itself, rather than with an instance of the class. Since the state merging logic is based on enumeration values rather than on the instance state of the class, the present application embodiment uses static methods. In this way, the method can be called directly by the class name without creating an instance of the class.
[0066] For example, Figure 2 A second flow chart of a state machine configuration method provided in an embodiment of the present application is shown in FIG. Figure 2 As shown, the method includes:
[0067] S201: Acquire a state transition rule preset for a state machine to be configured.
[0068] S202: Determine at least one state group based on the state transition rule; the target transition states of the states in each state group under the same triggering event are the same state.
[0069] S203: Define a state enumeration class, and overload the constructor of the state enumeration class so that the state enumeration class supports a state merging function.
[0070] S204: Define a static method for obtaining a merge status in the status enumeration class.
[0071] It should be noted that, for the description of the same steps and the same contents in this embodiment as those in other embodiments, reference can be made to the description in other embodiments and will not be repeated here.
[0072] It can be understood that the embodiment of the present application defines a state enumeration class and overloads the constructor of the state enumeration class so that the state enumeration class supports the state merging function, and then defines a static method for obtaining the merged state in the state enumeration class, thereby effectively realizing the complex state management and state merging logic of the state machine.
[0073] In some embodiments, the input parameters of the static method include the current state parameters and the current trigger event parameters of the state machine, and the return parameters of the static method include the merged state parameters, which are the parameters that the static method uses to merge and transform the current state parameters based on the current state parameters and the current trigger event parameters.
[0074] In an embodiment of the present application, the input parameters of the static method defined in the state enumeration class for obtaining the merged state include the current state parameters of the state machine and the current trigger event parameters, and the return parameters of the static method include the merged state parameters, and the merged state parameters are the parameters obtained by the defined static method by merging and transforming the current state parameters of the state machine based on the current state parameters of the state machine and the current trigger event parameters.
[0075] In some embodiments, a state enumeration class may be defined by the following program code, and the constructor of the state enumeration class may be overloaded so that the state enumeration class supports the state merging function. At the same time, a static method for obtaining the merged state is defined in the state enumeration class, and the input parameters of the static method include the current state parameters of the state machine and the current trigger event parameters, and the return parameters of the static method include the merged state parameters:
[0076] public enum TestStatus ieplements Basestatus{
[0077] A(value:1,name:"Status A"),
[0078] B(value:2,name:"Status B"),
[0079] C(value:3,name:"Status C"),
[0080] D(value:4,name:"Status D"),
[0081] / / Merge multiple states into one state
[0082] CAN_A(B,C,D),
[0083] CAN_B(A,C,D),
[0084] CAN_C(A,B,D),
[0085] CAN_D(A,B,C),
[0086] private String name;
[0087] private Integer value;
[0088] TestStatus(Integer value, String name) {
[0089] this.value = value;
[0090] this.name = name;
[0091] }
[0092] / / Overloaded constructor
[0093] private List <teststatus>statusGroup;
[0094] TestStatus(TestStatus...statusGroup){
[0095] if (statusGroup!= null) {
[0096] this.statusGroup=Arrays.astist(statusGroup);
[0097] }
[0098] }
[0099] public Integer getValue(){return value;}
[0100] public String getName(){return name;}
[0101] / / Define a static method for obtaining the merge status
[0102] public static TestStatus getReadstatus(TestEvent event,Integer value){
[0103] Teststatus read=get(value);
[0104] switch(event){
[0105] case A_EVENT:
[0106] Assert.isTrue(CAN_A.statusGroup.contains(read),message "The current status cannot flow to A");
[0107] return CAN_A;
[0108] case B_EVENT:
[0109] Assert.isTrue(CAN_B.statusGroup.contains(read),message "The current status cannot flow to B");
[0110] return CAN_B;
[0111] case C_EVENT:
[0112] Assert.isTrue(CAN_C.statusGroup.contains(read),message "Current status cannot be transferred to C");
[0113] return CAN_C;
[0114] case D_EVENT:
[0115] Assert.isTrue(CAN_D,statusGroup.contains(read),message:"The current status cannot be transferred to D");
[0116] return CAN_D;
[0117] default:
[0118] return read;
[0119] }
[0120] }
[0121] public static Teststatus get(Integer value){
[0122] Optional <teststatus>optional=Arrays.stream(TestStatus.votues()).filter(e->objects.equals(e.getvalue(),value))
[0123] return optional.orElseThrow(()->new RuntimeException("testStatus isnotfound"));
[0124] }
[0125] }
[0126] It can be understood that the embodiment of the present application achieves the purpose of merging multiple states into one state by overloading the constructor of the state enumeration class and defining a static method getReadstatus for obtaining the merged state in the state enumeration class, and its input parameters are the trigger event event and the source state value.
[0127] In some embodiments, the state machine configuration method further includes:
[0128] A data reading method is defined in the state machine persistence interface, and the data reading method is used to read the current state of the state machine from the persistent storage, and call the static method during the reading process to convert the read current state into a merged state.
[0129] It should be noted that the use of the state machine includes the following three core steps:
[0130] Step 1, StateMachinePersister.restore(stateMachine, contextObj): Initialize the state machine context according to the state machine and data contextObj and start the state machine.
[0131] In Spring Statemachine, the StateMachinePersister interface is used to persist and restore the state of a state machine instance. When you need to save the current state of the state machine so that it can be restored later, you can use the persist method to save the state to some persistent storage (such as a database or file system). Similarly, when you need to restore the state machine from a known state, you can use the restore method. The purpose of the StateMachinePersister.restore(stateMachine, contextObj) method is to restore the state of the state machine based on the provided state machine instance (stateMachine) and context object (contextObj). The contextObj here is usually an identifier used to retrieve the state information of the state machine from the persistent storage. Once the state is retrieved and restored, the state machine can continue execution from that point.
[0132] Step 2, Boolean result = StateMachine.sendEvent (eventMsg): check whether the source state and the current trigger event have a target state that meets the conditions according to the incoming event message and the state configuration of the state machine itself.
[0133] In Spring Statemachine, when the StateMachine.sendEvent(eventMsg) method is called, the state machine will decide the next action based on the current state configuration (i.e. the state machine's state definition, transition rules, etc.) and the incoming event message (eventMsg). This includes checking whether the current state (source state) and the triggering event have matching transition rules, and determining the target state (target state). The StateMachine.sendEvent(eventMsg) method usually returns a Boolean value indicating whether the triggering event was successfully processed. If the event is successfully processed and the state machine successfully transitions to the new state, true is returned; otherwise, false may be returned.
[0134] Step 3, If (result) StateMachinePersister.persist (stateMachine, contextObj): If there is a target state that meets the conditions, the state in the entity is automatically modified according to the state machine configuration.
[0135] It should be noted that since the core of the embodiment of the present application is to merge the source state, and the restore method in the above three core steps of the Spring state machine includes the parsing and initialization of the source state, the read method of the StateMachinePersist interface is what actually parses and initializes the source state in the restore method. Therefore, in the embodiment of the present application, the read method of the StateMachinePersist interface can be used as the data reading method defined in the state machine persistence interface. The data reading method is used to read the current state of the state machine from the persistent storage, and call the static method for obtaining the merged state during the reading process to convert the read current state into the merged state.
[0136] In some embodiments, the state machine configuration method further includes:
[0137] The current trigger event received by the state machine is embedded in the context object of the state machine.
[0138] In the embodiment of the present application, the current trigger event event received by the state machine can be built into the context object contextObj of the state machine so that the event can be obtained in the StateMachinePersist implementation class.
[0139] In some embodiments, the current trigger event event received by the state machine can be embedded in the context object contextObj of the state machine through the following program code:
[0140] public boolean sendEvent(TestEntity entity,TestEvent event){
[0141] try{
[0142] StateMachine<TestStatus,TestEvent> stateMachine=testStateMachineFactory getStateMachine(machineld:"testStateMachine");
[0143] if(entity instanceof IEventcontextobj){
[0144] ((IEventcontextobj)entity).setEvent(event);
[0145] }
[0146] testStateMachinePersister.restore(stateMachine,entity);
[0147] Message <testevent>eventMsg=MessageBuilder.withPayload(event).setHeader(headerName:"entity",entity).build();
[0148] boolean result=stateMachine.sendEvent(eventMsg);
[0149] if(result){
[0150] testStateMachinePersister.persist(stateMachine,entity);
[0151] return result;
[0152] }catch(Exception ex){
[0153] throw new BizException(ExceptionEnum.ORDER_STATUS_CAN_NO T_CHANGE.getCode(),ExceptionEnum.ORDER_STATUS_CAN_NOT_CHANG E.getDesc(),ex);
[0154] }
[0155] It can be understood that the embodiment of the present application can facilitate obtaining the current trigger event event of the state machine in the StateMachinePersist implementation class by embedding the current trigger event event received by the state machine into the context object contextObj of the state machine.
[0156] In some embodiments, the data reading method is further used for:
[0157] The current trigger event received by the state machine is obtained from the context object, and the obtained current trigger event is used as the current trigger event parameter included in the input parameter of the called static method.
[0158] In an embodiment of the present application, the read method (data reading method) of the StateMachinePersist interface can be implemented to obtain the current trigger event event from the context object contextObj of the state machine, and then the static method in the state enumeration class for obtaining the merged state is called based on the current trigger event event and the current state of the state machine, thereby realizing the merging of multiple states.
[0159] In some embodiments, the following program code can be used to obtain the current trigger event received by the state machine from the context object of the state machine, and use the obtained current trigger event as the current trigger event parameter included in the input parameter of the called static method:
[0160] public StateMachineContext<TestStatus,TestEvent> read(TestEntityentity){
[0161] return new DefaultStateMachineContext<>(TestStatus.getReadStatus((TestEv ent)entity.getEvent(),entity.getstatus());
[0162] }
[0163] It can be understood that the embodiment of the present application achieves the purpose of merging state machine states to reduce the complexity of state machine configuration by encapsulating state enumeration classes and entity classes and implementing the read method of the StateMachinePersist interface.
[0164] For example, Figure 3 A third flow chart of a state machine configuration method provided in an embodiment of the present application is as follows: Figure 3 As shown, the method includes:
[0165] S301: Acquire a state transition rule preset for a state machine to be configured.
[0166] S302: Determine at least one state group based on the state transition rule; the target transition states of the states in each state group under the same triggering event are the same state.
[0167] S303: Define a state enumeration class, and overload the constructor of the state enumeration class so that the state enumeration class supports a state merging function.
[0168] S304. Define a static method for obtaining a merged state in the state enumeration class, wherein the input parameters of the static method include the current state parameters of the state machine and the current trigger event parameters, and the return parameters of the static method include merged state parameters, which are parameters used by the static method to merge and transform the current state parameters based on the current state parameters and the current trigger event parameters.
[0169] S305: embed the current trigger event received by the state machine into the context object of the state machine.
[0170] S306. Define a data reading method in the state machine persistence interface, the data reading method is used to read the current state of the state machine from the persistent storage, and call the static method during the reading process, and is also used to obtain the current trigger event received by the state machine from the context object, and use the obtained current trigger event as the current trigger event parameter included in the input parameter of the called static method, so as to convert the read current state into a merged state.
[0171] It should be noted that, for the description of the same steps and the same contents in this embodiment as those in other embodiments, reference can be made to the description in other embodiments and will not be repeated here.
[0172] It can be understood that the embodiment of the present application first obtains the state transition rule preset for the state machine to be configured, and then determines at least one state group based on the state transition rule, and the target transition state of each state in each state group under the same trigger event is the same state, and then defines a state enumeration class, and overloads the constructor of the state enumeration class so that the state enumeration class supports the state merging function, and further defines a static method for obtaining the merged state in the state enumeration class, and the input parameters of the static method include the current state parameters and the current trigger event parameters of the state machine, and the return parameters of the static method include the merged state parameters, and then the current trigger event received by the state machine is built into the context object of the state machine, and finally a data reading method is defined in the state machine persistence interface, the data reading method is used to read the current state of the state machine from the persistent storage, and call the static method for obtaining the merged state during the reading process, and is also used to obtain the current trigger event received by the state machine from the context object, and the obtained current trigger event is used as the current trigger event parameter included in the input parameter of the called static method to convert the read current state into a merged state. In this way, the state merging function is configured for the state machine, so that the state machine has the function of merging each state in each state group into one state. This state merging function can reduce the total number of states in the state machine, and the state transition paths that the state machine needs to manage and maintain are also reduced accordingly, thereby reducing the complexity of the state transition configuration of the state machine, and at the same time can also reduce the errors or omissions that may occur during the state transition configuration process.
[0173] The state machine configuration device provided in an embodiment of the present application is described below. The state machine configuration device described below and the state machine configuration method described above can be referenced to each other.
[0174] Figure 4 A schematic diagram of a state machine configuration device provided in an embodiment of the present application is shown in FIG. Figure 4 As shown, the device includes: an acquisition module 410, a determination module 420 and a configuration module 430; wherein:
[0175] An acquisition module 410 is used to acquire a state transition rule preset for a state machine to be configured;
[0176] A determination module 420 is used to determine at least one state group based on the state transition rule; the target transition state of each state in each state group under the same trigger event is the same state;
[0177] The configuration module 430 is used to configure the state merging function for the state machine so that the state machine has the function of merging the states in the state groups into one state.
[0178] The state machine configuration device provided in the embodiment of the present application first obtains the state transition rule preset for the state machine to be configured, and then determines at least one state group based on the state transition rule, and the target transition state of each state in each state group under the same trigger event is the same state, and then configures the state machine for a state merging function so that the state machine has the function of merging each state in each state group into one state. This state merging function can reduce the total number of states in the state machine, and the state transition paths that the state machine needs to manage and maintain are also reduced accordingly, thereby reducing the complexity of the state transition configuration of the state machine, and also reducing the errors or omissions that may occur during the state transition configuration process.
[0179] In some embodiments, the configuration module 430 includes:
[0180] A first definition unit is used to define a state enumeration class and overload a constructor of the state enumeration class so that the state enumeration class supports the state merging function;
[0181] The second definition unit is used to define a static method for obtaining the merge status in the status enumeration class.
[0182] In some embodiments, the input parameters of the static method include the current state parameters and the current trigger event parameters of the state machine, and the return parameters of the static method include the merged state parameters, which are the parameters that the static method uses to merge and transform the current state parameters based on the current state parameters and the current trigger event parameters.
[0183] In some embodiments, the second definition unit is further configured to:
[0184] A data reading method is defined in the state machine persistence interface, and the data reading method is used to read the current state of the state machine from the persistent storage, and call the static method during the reading process to convert the read current state into a merged state.
[0185] In some embodiments, the second definition unit is further configured to:
[0186] The current trigger event received by the state machine is embedded in the context object of the state machine.
[0187] In some embodiments, the data reading method is further used for:
[0188] The current trigger event received by the state machine is obtained from the context object, and the obtained current trigger event is used as the current trigger event parameter included in the input parameter of the called static method.
[0189] It should be noted here that the above-mentioned state machine configuration device provided in the embodiment of the present application can implement all the method steps implemented in the above-mentioned state machine configuration method embodiment, and can achieve the same technical effect. The parts and beneficial effects that are the same as the method embodiment in this embodiment will not be described in detail here.
[0190] Figure 5 A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present application, such as Figure 5 As shown, the electronic device may include: a processor 510, a communication interface 520, a memory 530 and a communication bus 540, wherein the processor 510, the communication interface 520 and the memory 530 communicate with each other via the communication bus 540. The processor 510 may execute executable data instructions stored in the memory 530 to implement some or all steps in the state machine configuration method provided in the above embodiments.
[0191] In addition, the executable data instructions stored in the above-mentioned memory 530 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the embodiment of the present application can be essentially or partly embodied in the form of a software product that contributes to the relevant technology. The software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read Only Memory, ROM), random access memory (Random Access Memory, RAM), disk or optical disk and other media that can store program code.
[0192] An embodiment of the present application also provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, part or all of the steps in the state machine configuration method provided in the above embodiments are implemented.
[0193] An embodiment of the present application also provides a computer program product, which includes a computer program or instructions. When the computer program or instructions are executed by a processor, some or all of the steps in the state machine configuration method provided in the above embodiments are implemented.
[0194] The device embodiments described above are merely illustrative, 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 scheme of this embodiment. Those of ordinary skill in the art may understand and implement it without creative work.
[0195] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the embodiments of the present application may adopt the form of hardware embodiments, software embodiments, or embodiments in combination with software and hardware. Moreover, the embodiments of the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) that contain computer-usable program code.
[0196] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0197] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0198] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0199] The above description is merely an optional embodiment of the present application and is not intended to limit the protection scope of the present application.< / testevent> < / teststatus> < / teststatus>
Claims
1. A state machine configuration method, characterized in that: include: Get the state transition rules preset for the state machine to be configured; Based on the state transition rule, determining at least one state group; The target transition state of each state in each state group under the same trigger event is the same state; The state machine is configured with a state merging function so that the state machine has the function of merging the states in the state groups into one state.
2. The state machine configuration method according to claim 1, characterized in that: The configuring the state machine to merge the states so that the state machine has the function of merging the states in the state groups into one state includes: Define a state enumeration class, and overload the constructor of the state enumeration class so that the state enumeration class supports the state merging function; A static method for obtaining the merge status is defined in the status enumeration class.
3. The state machine configuration method according to claim 2, characterized in that: The input parameters of the static method include the current state parameters of the state machine and the current trigger event parameters, and the return parameters of the static method include the merged state parameters, which are the parameters used by the static method to merge and transform the current state parameters based on the current state parameters and the current trigger event parameters.
4. The state machine configuration method according to claim 2 or 3, characterized in that: The method further comprises: A data reading method is defined in the state machine persistence interface, and the data reading method is used to read the current state of the state machine from the persistent storage, and call the static method during the reading process to convert the read current state into a merged state.
5. The state machine configuration method according to claim 4, characterized in that: The method further comprises: The current trigger event received by the state machine is embedded in the context object of the state machine.
6. The state machine configuration method according to claim 5, characterized in that: The data reading method is also used for: The current trigger event received by the state machine is obtained from the context object, and the obtained current trigger event is used as the current trigger event parameter included in the input parameter of the called static method.
7. A state machine configuration device, characterized in that: include: An acquisition module, used to acquire a state transition rule preset for a state machine to be configured; A determination module, configured to determine at least one state group based on the state transition rule; The target transition state of each state in each state group under the same trigger event is the same state; The configuration module is used to configure the state merging function for the state machine so that the state machine has the function of merging the states in the state groups into one state.
8. An electronic device, characterized in that: include: A memory for storing executable data instructions; A processor is used to implement the steps in the state machine configuration method described in any one of claims 1 to 6 when executing the executable data instructions stored in the memory.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the state machine configuration method according to any one of claims 1 to 6 are implemented.
10. A computer program product comprising a computer program or instructions, characterized in that When the computer program or instruction is executed by a processor, the steps in the state machine configuration method according to any one of claims 1 to 6 are implemented.
Citation Information
Cited By
Control method, device and equipment for double-door intelligent container
CN120954137A