Movatterモバイル変換


[0]ホーム

URL:


Squirrel State Machine

squirrel-foundation provided an easy use, type safe and highly extensible state machine implementation for Java.

View on GitHubDownload .zipDownload .tar.gz

squirrel-foundation

What is it?

Just like the squirrel, asmall,agile,smart,alert andcute animal, squirrel-foundation is aimed to provide alightweight, highlyflexible andextensible,diagnosable,easy use andtype safe Java state machine implementation for enterprise usage.

Here is the state machine diagram which describes the state change of an ATM:

ATMStateMachine
The sample code could be found in package“org.squirrelframework.foundation.fsm.atm”.

Maven

squirrel-foundation has been deployed to maven central repository, so you only need to add following dependency to the pom.xml.

Latest Released Version:

<dependency><groupId>org.squirrelframework</groupId>  <artifactId>squirrel-foundation</artifactId>  <version>0.3.8</version></dependency>

Latest Snapshot Version:

<dependency><groupId>org.squirrelframework</groupId>  <artifactId>squirrel-foundation</artifactId>  <version>0.3.9-SNAPSHOT</version></dependency>

Quick Start

To quickly try squirrel state machine functions, please create a maven project and include squirrel-foundation dependency properly. Then just run following sample code.

publicclassQuickStartSample{// 1. Define State Machine EventenumFSMEvent{ToA,ToB,ToC,ToD}// 2. Define State Machine Class@StateMachineParameters(stateType=String.class,eventType=FSMEvent.class,contextType=Integer.class)staticclassStateMachineSampleextendsAbstractUntypedStateMachine{protectedvoidfromAToB(Stringfrom,Stringto,FSMEventevent,Integercontext){System.out.println("Transition from '"+from+"' to '"+to+"' on event '"+event+"' with context '"+context+"'.");}protectedvoidontoB(Stringfrom,Stringto,FSMEventevent,Integercontext){System.out.println("Entry State \'"+to+"\'.");}}publicstaticvoidmain(String[]args){// 3. Build State TransitionsUntypedStateMachineBuilderbuilder=StateMachineBuilderFactory.create(StateMachineSample.class);builder.externalTransition().from("A").to("B").on(FSMEvent.ToB).callMethod("fromAToB");builder.onEntry("B").callMethod("ontoB");// 4. Use State MachineUntypedStateMachinefsm=builder.newStateMachine("A");fsm.fire(FSMEvent.ToB,10);System.out.println("Current state is "+fsm.getCurrentState());}}

At now you may have many questions about the sample code, please be patient. The following user guide will answer most of your questions. But before getting into the details, it requires you have basic understanding on state machine concepts. These materials are good for understanding state machine concepts.[state-machine-diagrams][qt-state-machine]

User Guide

Get Starting

squirrel-foundation supports both fluent API and declarative manner to declare a state machine, and also enable user to define the action methods in a straightforward manner.

Advanced Feature

Examples

SeeEXAMPLES file.

Release Notes

SeeRELEASE NOTES file.

Future Plan

Sponsors

IDEA

More Information


[8]ページ先頭

©2009-2025 Movatter.jp