在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:stateless4j/stateless4j开源软件地址:https://github.com/stateless4j/stateless4j开源编程语言:Java 100.0%开源软件介绍:Maven <dependency>
<groupId>com.github.stateless4j</groupId>
<artifactId>stateless4j</artifactId>
<version>2.6.0</version>
</dependency> IntroductionCreate state machines and lightweight state machine-based workflows directly in java code. StateMachineConfig<State, Trigger> phoneCallConfig = new StateMachineConfig<>();
phoneCallConfig.configure(State.OffHook)
.permit(Trigger.CallDialed, State.Ringing);
phoneCallConfig.configure(State.Ringing)
.permit(Trigger.HungUp, State.OffHook)
.permit(Trigger.CallConnected, State.Connected);
// this example uses Java 8 method references
// a Java 7 example is provided in /examples
phoneCallConfig.configure(State.Connected)
.onEntry(this::startCallTimer)
.onExit(this::stopCallTimer)
.permit(Trigger.LeftMessage, State.OffHook)
.permit(Trigger.HungUp, State.OffHook)
.permit(Trigger.PlacedOnHold, State.OnHold);
// ...
StateMachine<State, Trigger> phoneCall =
new StateMachine<>(State.OffHook, phoneCallConfig);
phoneCall.fire(Trigger.CallDialed);
assertEquals(State.Ringing, phoneCall.getState()); stateless4j is a port of stateless for java FeaturesMost standard state machine constructs are supported:
Some useful extensions are also provided:
Parallel states are not supported, but if you are looking for it, there is a fork that supports it: ParallelStateless4j. Hierarchical StatesIn the example below, the phoneCall.configure(State.OnHold)
.substateOf(State.Connected)
.permit(Trigger.TakenOffHold, State.Connected)
.permit(Trigger.HungUp, State.OffHook)
.permit(Trigger.PhoneHurledAgainstWall, State.PhoneDestroyed); In addition to the Entry/Exit EventsIn the example, the The call can move between the Entry/Exit event handlers can be supplied with a parameter of type Action on transitionIt is possible to execute a user-defined action when doing a transition. For a 'normal' or 're-entrant' transition this action will be called without any parameters. For 'dynamic' transitions (those who compute the target state based on trigger-given parameters) the parameters of the trigger will be given to the action. This action is only executed if the transition is actually taken; so if the transition is guarded and the guard forbids a transition, then the action is not executed. If the transition is taken, the action will be executed between the
LicenseApache 2.0 License Created by @oxo42 Maintained by Chris Narkiewicz @ezaquarii |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论