Java的StateMachine(一)說明文件
Java的StateMachine(一)說明文件
首頁
http://smc.sourceforge.net/
圖形化工具
http://www.graphviz.org/
I download the Smc version 6.0.1.
smc.pdf Introduction of the State Machine Compiler
FSM(Finite State Machine) is everywhere.
A input source .sm(yacc-like syntax), a output source in your language like java or python.
1.conceptions
A Simple Transition
//State
Idle {
// Trans Next State Actions
Run Running {}
}
A Reflexive Transition
//State
Idle{
// Trans Next State Actions
Timeout Idle {}
}
A Internal Event
// State
Idle {
//Trans Next State Actions
Timeout nil {}
}
A Transition with Actions
// State
Idle{
//Trans
Run
//Actions
{
StopTimer("Idle");
DoWork();
}
}
Transition Guards
conditions that must be met in order for transitions to proceed
// State
Idle{
//Trans
Run
//Guard condition
[ctxt.isValid()]
//Next State
Running
//Actions
{
StopTimer("Idle");
DoWork();
}
Run Idle {RejectRequest();}
}
Transition Arguments
// State
Idle{
//Transition
Run(msg:const Message&)
//Guard condition
[msg.isValid()]
//Next State
Running
//Actions
{
StopTimer("Idle");
DoWork(msg);
}
Run(msg:const Message&)
//Next State Actions
Idle { RejectRequest(msg);}
}
Entry and Exit Actions
Actions performed every time we enter and exit a state,respectively
// State
Idle
Entry {StartTimer("Idle",1); CheckQueue();}
Exit {StopTimer("Idle");}
{
//Transitions
}
2.A case study: a Telephone
demo url:
http://smc.sourceforge.net/SmcDemo.htm
SMC_Tutorial.pdf book
An example of simple turnstile:
1.Description of the normal operation of a turnstile:
Turnstile initially locked
A coin or ticket is inserted(event)
triggers action: turnstile unlocks
A person passes through turnstile(event)
triggers action: turnstile locks again
most important concepts:States,Transitions and Actions
Transition table for turnstile
State Transition Next State Action
Locked coin Unlocked unlock
pass Locked alarm
Unlocked coin Unlocked thankyou
pass Locked lock
I use a sm file to show the workflow Turnstile.sm:
%class Turnstile
%package turnstile
%start MainMap::Locked
%map MainMap
%%
Locked
{
coin Unlocked { unlock(); }
pass nil { alarm(); }
}
Unlocked
{
pass Locked { lock(); }
coin nil { thankyou(); }
}
%%
And I put a bat file on Windows to compile the sm file to java output, BuildSm.bat:
java -jar smc-6.0.1.jar -java -d turnstile Turnstile.sm
rem -jar smc-6.0.1.jar The SMC Compiler
rem -java Specify java language output
rem -d turnstile Optionally specify target directory
rem turnstile.sm Specify the .sm file to process
After we run the bat shell, we get a single file named TurnstileContext.java and we get many classes:
TurnstileContext$MainMap.class
TurnstileContext$MainMap_Default$MainMap_Locked.class
TurnstileContext$MainMap_Default$MainMap_Unlocked.class
TurnstileContext$MainMap_Default.class
TurnstileContext$TurnstileState.class
TurnstileContext.class
Write the AppClass Turnstile.java:
package com.sillycat.sm.turnstile;
public class Turnstile implements TurnstileActions{
TurnstileContext _fsm;
TurnstileActions _actions;
public Turnstile(TurnstileActions actions){
_fsm = new TurnstileContext(this);
_actions = actions;
}
public void coin(){_fsm.coin();}
public void pass(){_fsm.pass();}
public void alarm(){_actions.alarm();}
public void lock() {_actions.lock();}
public void thankyou() {_actions.thankyou();}
public void unlock() {_actions.unlock();}
}
TurnstileActions.java:
package com.sillycat.sm.turnstile;
public interface TurnstileActions {
public void coin();
public void pass();
public void alarm();
public void lock();
public void thankyou();
public void unlock();
}
And we can build sm file into a .dot file and view the picturn of the workflow,GraphSm.bat:
java -jar smc-6.0.1.jar -graph -glevel 1 Turnstile.sm
we can get a Turnstile_sm.dot file after we run the command, and we can install graphviz-2.26.3.msi from URL
http://www.graphviz.org/
And we use Gvedit to open the file Turnstile_sm.dot and then we can see the picture.
首頁
http://smc.sourceforge.net/
圖形化工具
http://www.graphviz.org/
I download the Smc version 6.0.1.
smc.pdf Introduction of the State Machine Compiler
FSM(Finite State Machine) is everywhere.
A input source .sm(yacc-like syntax), a output source in your language like java or python.
1.conceptions
A Simple Transition
//State
Idle {
// Trans Next State Actions
Run Running {}
}
A Reflexive Transition
//State
Idle{
// Trans Next State Actions
Timeout Idle {}
}
A Internal Event
// State
Idle {
//Trans Next State Actions
Timeout nil {}
}
A Transition with Actions
// State
Idle{
//Trans
Run
//Actions
{
StopTimer("Idle");
DoWork();
}
}
Transition Guards
conditions that must be met in order for transitions to proceed
// State
Idle{
//Trans
Run
//Guard condition
[ctxt.isValid()]
//Next State
Running
//Actions
{
StopTimer("Idle");
DoWork();
}
Run Idle {RejectRequest();}
}
Transition Arguments
// State
Idle{
//Transition
Run(msg:const Message&)
//Guard condition
[msg.isValid()]
//Next State
Running
//Actions
{
StopTimer("Idle");
DoWork(msg);
}
Run(msg:const Message&)
//Next State Actions
Idle { RejectRequest(msg);}
}
Entry and Exit Actions
Actions performed every time we enter and exit a state,respectively
// State
Idle
Entry {StartTimer("Idle",1); CheckQueue();}
Exit {StopTimer("Idle");}
{
//Transitions
}
2.A case study: a Telephone
demo url:
http://smc.sourceforge.net/SmcDemo.htm
SMC_Tutorial.pdf book
An example of simple turnstile:
1.Description of the normal operation of a turnstile:
Turnstile initially locked
A coin or ticket is inserted(event)
triggers action: turnstile unlocks
A person passes through turnstile(event)
triggers action: turnstile locks again
most important concepts:States,Transitions and Actions
Transition table for turnstile
State Transition Next State Action
Locked coin Unlocked unlock
pass Locked alarm
Unlocked coin Unlocked thankyou
pass Locked lock
I use a sm file to show the workflow Turnstile.sm:
%class Turnstile
%package turnstile
%start MainMap::Locked
%map MainMap
%%
Locked
{
coin Unlocked { unlock(); }
pass nil { alarm(); }
}
Unlocked
{
pass Locked { lock(); }
coin nil { thankyou(); }
}
%%
And I put a bat file on Windows to compile the sm file to java output, BuildSm.bat:
java -jar smc-6.0.1.jar -java -d turnstile Turnstile.sm
rem -jar smc-6.0.1.jar The SMC Compiler
rem -java Specify java language output
rem -d turnstile Optionally specify target directory
rem turnstile.sm Specify the .sm file to process
After we run the bat shell, we get a single file named TurnstileContext.java and we get many classes:
TurnstileContext$MainMap.class
TurnstileContext$MainMap_Default$MainMap_Locked.class
TurnstileContext$MainMap_Default$MainMap_Unlocked.class
TurnstileContext$MainMap_Default.class
TurnstileContext$TurnstileState.class
TurnstileContext.class
Write the AppClass Turnstile.java:
package com.sillycat.sm.turnstile;
public class Turnstile implements TurnstileActions{
TurnstileContext _fsm;
TurnstileActions _actions;
public Turnstile(TurnstileActions actions){
_fsm = new TurnstileContext(this);
_actions = actions;
}
public void coin(){_fsm.coin();}
public void pass(){_fsm.pass();}
public void alarm(){_actions.alarm();}
public void lock() {_actions.lock();}
public void thankyou() {_actions.thankyou();}
public void unlock() {_actions.unlock();}
}
TurnstileActions.java:
package com.sillycat.sm.turnstile;
public interface TurnstileActions {
public void coin();
public void pass();
public void alarm();
public void lock();
public void thankyou();
public void unlock();
}
And we can build sm file into a .dot file and view the picturn of the workflow,GraphSm.bat:
java -jar smc-6.0.1.jar -graph -glevel 1 Turnstile.sm
we can get a Turnstile_sm.dot file after we run the command, and we can install graphviz-2.26.3.msi from URL
http://www.graphviz.org/
And we use Gvedit to open the file Turnstile_sm.dot and then we can see the picture.
相關文章
- 如何製作Java文件說明書Java
- Java的StateMachine(二)More ExamplesJavaMac
- Oracle 官方文件 結構說明Oracle
- Oracle官方文件結構說明Oracle
- java 關於操作Collection的一點說明Java
- 有關RFC文件的翻譯說明 (轉)
- SRS文件 軟體需求說明書
- Java常用中介軟體之 NGINX實現限流功能的官方文件說明JavaNginx
- [譯] React-Redux 官方 Hooks 文件說明ReactReduxHook
- knife4j api文件使用說明API
- java 類路徑說明Java
- java String類說明Java
- sql trace的使用說明一SQL
- percona-tool文件說明(6)- 系統類
- .Net解析html文件類庫HtmlAgilityPack完整使用說明HTML
- GoldenGate 配置文件,裡面有引數說明Go
- 一張圖說明SQL的join用法SQL
- Java正規表示式的解釋說明Java
- java中的單例模式,舉例說明。Java單例模式
- TailWind文件翻譯說明以及每日翻譯進度AI
- Theano 中文文件 0.9 - 5.4 CentOS 6安裝說明CentOS
- Java執行緒池使用說明Java執行緒
- java中finalkeyword使用說明Java
- oracle jdbc jar 的一些說明OracleJDBCJAR
- 汪子熙趣味成語接龍的遊戲軟體使用文件說明遊戲
- Java SE中的一些基礎知識點截圖說明Java
- Yul語言及物件說明——Solidity中文文件(9)物件Solid
- 以太坊 web3.js 文件翻譯及說明WebJS
- Java @FunctionInterface函式式介面使用說明JavaFunction函式
- Java之反射程式碼演示說明Java反射
- java開發環境配置說明書Java開發環境
- react + Ant Design + 支援 markdown 的 blog-react 專案文件說明React
- 一些網路協議的說明協議
- ip 命令的說明
- Java非阻塞I/O模型之NIO說明Java模型
- java WebSocket 即時通訊配置使用說明JavaWeb
- 說一下泛型原理,並舉例說明泛型
- SYSAUX 說明UX