ãã®èšäºã§ã¯ãèè
ãéçºãããããã¥ã¢Javaã©ã€ãã©ãªã«ã€ããŠèª¬æããŸããããã«ãããæéç¶æ
ãã·ã³ãç°¡åãã€æ確ã«å®çŸ©ã§ããŸãã ã©ã€ãã©ãªã¯ãAkerFSMãšåŒã³ãŸããããGoogleCodeã§å
¥æã§ããŸãã
èšäºã®æåã®éšåã§ã¯ãã©ã€ãã©ãªã®åææ¡ä»¶ãšèŠä»¶ãå®åŒåãããŠããŸãã 2çªç®ã®éšåã§ã¯ãã©ã€ãã©ãªã®äœ¿çšã®æœè±¡çãªäŸã瀺ããŸãã 3çªç®ã®éšåã§ã¯ãã©ã€ãã©ãªèªäœã®èšèšã®éèŠãªåŽé¢ãæ€èšããŸãã 4çªç®ã®éšåã¯ãGWTã¢ããªã±ãŒã·ã§ã³ã®ã³ã³ãããŒã©ãŒã®1ã€ã®åäœãã¹ããŒããã·ã³ã䜿çšããŠèšå®ãããåçŽåãããå®éã®äŸãæ€èšããããšã«å°å¿µããŸãã
èæ¯
æéç¶æ
ãã·ã³ãå®è£
ããã«ã¯ããŸããŸãªæ¹æ³ããããŸãã ææ¡ãããã©ã€ãã©ãªãäœæãããŸã§ãçŸåšã®ç¶æ
çªå·ã§éžæããswitchã¹ããŒãã¡ã³ãã䜿çšããæãæåããæ¹æ³ãæ€èšããŸããã ã³ãŒãã®äŸã¯
ããã«ãããŸãããSWITCH technologyãããã³ãAutomatic programmingããšããååã§è¡šç€ºãããã¢ãããŒãèªäœã¯ãèšåããããµã€ãã«ããShalytoãšTukkelã®èšäºã§è©³çŽ°ã«èª¬æãããŠããŸãã
ãã®åçŽãã®ããã«ãswitchã¹ããŒãã¡ã³ãã®å®è£
ã¯ãªããžã§ã¯ãæåã®ãã©ãã€ã ã«ãŸã£ããé©åããããã®ãããçŸä»£ã®èšèªã®æ©èœãå®å
šã«äœ¿çšããããšã¯ã§ããŸããã ãããã£ãŠãç§ã¯æ¬¡ã®èŠä»¶ãæºããå®è£
ãäœæããããšã«ããŸããã
- ãã·ã³ã¯ãswitchã¹ããŒãã¡ã³ãã䜿çšãããšããšåãããã«æ確ãã€ç°¡æœã«èšå®ãããŸãã
- å®è£
ã¯ãªããžã§ã¯ãæåã§ã
- å®è£
ã¯èªåããã°ã©ãã³ã°ã®ãã¹ãŠã®å¯èœæ§ããµããŒãããŸã
ä»åŸãçµæãåé¡ã®å
ã®ã¹ããŒãã¡ã³ããè¶
ããããšã«æ³šæããŸãïŒè©³çŽ°ã¯èšäºã®æåŸã«ãããŸãïŒã
æœè±¡äŸ
æåã®äŸãšããŠãç»é¢ãã©ãŒã ã®ããæœè±¡çãªãŠã£ã³ããŠãèããŸãã ãŠã£ã³ããŠã¯éããŠããŠãéããŠããŠãããŸããŸããã ãŠã£ã³ããŠãéããŠããå Žåã¯ããã©ãŒã ããŒã¿ãä¿åã§ããŸãã ãŠã£ã³ããŠãæåã«è¡šç€ºããåã«ããã®åæåãå¿
èŠã§ãã
ãŸãããªãŒãããã³ã宣èšãããã®ç¶æ
ã®ã»ãããå®çŸ©ããŸãã
ããã§ããªãŒãããã³èªäœãšãããäœæããã¡ãœãããå®çŸ©ããŸãã
ãã·ã³ã䜿çšããã«ã¯ããªããžã§ã¯ããäœæããhandleEventïŒïŒã¡ãœãããåŒã³åºããŠã€ãã³ããåŠçããã€ãã³ãããã©ã¡ãŒã¿ãŒãšããŠæž¡ããŸãã
ãããã£ãŠãææ¡ãããå®è£
ã§ã¯ãswitchã¹ããŒãã¡ã³ãã®å ŽåãšåãèŠèŠçãã€ç°¡æœãªæ¹æ³ã§ãªãŒãããã³ãèšè¿°ããããšãã§ããŸããç¶æ
ãå€æããã«ã¯æ°è¡ã®ã³ãŒããå¿
èŠã§ããªãŒãããã³å®çŸ©å
šäœãåäžã®ãããã¯ã«é
眮ãããŸãã switchã¹ããŒãã¡ã³ãã®å Žåã®ããã«ãæšæºã®ãœãŒã¹åœ¢åŒã䜿çšãããšãç»åãå°ãæªããªããŸãããããã§éžæããå¿
èŠããããŸãã ã䜿çšã®ç°å¢ã§ãç¹å®ã®ããã¹ãã®èªåæžåŒèšå®ãç¡å¹ã«ã§ããå Žåã¯ã幞éã§ãã
ããŒãã¹ | enumã䜿çšãããšãã·ãªã¢ã«çªå·ãŸãã¯å®æ°ã§ç¶æ
ãã³ãŒãã£ã³ã°ããããããªãŒãããã³ã®å®çŸ©ãã¯ããã«çŽæçã«ãªããŸãã ãšããã§ãenumã®å®æ°ã®ååã«ããªã«æåã䜿çšã§ããŸã
|
ã©ã€ãã©ãªããã€ã¹ã®æ©èœ
äž»ãªã©ã€ãã©ãªã¯ã©ã¹ã¯StateãšFSMã§ããã®ç®çã¯æããã§ãã 以äžã«ç€ºãããã«ãäž¡æ¹ã®ã¯ã©ã¹ã¯ç°¡åã«æ¡åŒµã§ããŸãã
ã¯ã©ã¹ã¯æ¬¡ã®ããã«å®£èšãããŸãã
Generic STATESã¯ããã·ã³ã®å€ãã®ç¶æ
ãä¿åããenumãå®çŸ©ããŸãã ãžã§ããªãã¯EVENTã¯ãèªåã€ãã³ãã®ã¯ã©ã¹ãå®çŸ©ããŸãã å®éã®ã¢ããªã±ãŒã·ã§ã³ã§ã¯ãEVENTã¯ã€ãã³ããšã³ãžã³ã§äœ¿çšãããåºæ¬ã€ãã³ãã¯ã©ã¹ã瀺ããŸãã åé¡ã®äŸã§ã¯ãç°¡åã«ããããã«Stringã䜿çšããŠããŸãã
Stateã¯ã©ã¹ã®3ã€ã®ã¡ãœããïŒenterïŒïŒãhandleEventïŒïŒãexitïŒïŒã¯ãç¹å®ã®ç¶æ
ãäœæãããšãã«ãªãŒããŒã©ã€ããããããã«èšèšãããŠããŸãã ãã·ã³ãåé¡ã®ç¶æ
ã«ãªããšenterãåŒã³åºãããã€ãã³ããåŠçãããšãã«handleEventãåŒã³åºããããã·ã³ãåé¡ã®ç¶æ
ãé¢ãããšexitãããããåŒã³åºãããŸãã ãããã®ã¡ãœããã¯Template Methodãã¿ãŒã³ãå®è£
ãããããããããåå®çŸ©ããå Žåãsuperã®åŒã³åºãã¯ãªãã·ã§ã³ã§ãã
ãªãŒãããã³ãå®çŸ©ãããšããStateã¯ã©ã¹ãšå
±ã«ããã®åå«ã§ããSuperStateã¯ã©ã¹ã䜿çšã§ããŸãïŒStateãšSuperStateã¯ãCompositeãã¿ãŒã³ã®é¡äŒŒç©ãå
±åã§å®è£
ããŸãïŒã SuperStateã®ç®çã¯ãã°ã«ãŒãé·ç§»ãªã©ãç¶æ
ã®ã°ã«ãŒãã«äžè¬çãªåäœãå®è£
ããããšã§ãã
State.toStringïŒïŒã¡ãœããã¯ãç¶æ
ã®ååãšã·ãªã¢ã«çªå·ãè¿ããŸãïŒé·ãã©ã€ãåæïŒïŒFSM.toStringïŒïŒããã³SuperState.toStringïŒïŒã¡ãœããã¯ãåãæ¹æ³ã§å®çŸ©ãããŸãã
handleEventïŒïŒã¡ãœãããåŒã³åºããšãã®FSMã¯ã©ã¹ã®åäœã¯æ¬¡ã®ãšããã§ãã
- çŸåšã®ç¶æ
ããã³çŸåšã®ç¶æ
ã°ã«ãŒãã®handleEventïŒïŒãåŒã³åºããŸã
- 次ã®ç¶æ
ã決å®ããŸãïŒã°ã«ãŒãé·ç§»ã¯éåžžã®é·ç§»ãããåªå
ãããŸãïŒ
- çŸåšã®ç¶æ
ãšãé·ç§»æã«ç Žæ£ããããã¹ãŠã®ã°ã«ãŒãç¶æ
ã®exitïŒïŒãåŒã³åºããŸã
- æ°ããç¶æ
ãšé·ç§»æã«åé¡ããããã¹ãŠã®ã°ã«ãŒãç¶æ
ã®enterïŒïŒãåŒã³åºããŸã
- 次ã®ç¶æ
ã®å€å®çµæãnullã«ãªããŸã§é·ç§»ãå®è¡ããŸã
ããã«ãFSMã¯14åã®ã€ãã³ããå®è£
ããŠããŸãããããã®ã€ãã³ãã«å¯ŸããŠãã³ãã©ãŒãå²ãåœãŠãç¹å®ã®ã€ãã³ããã³ãã©ãŒã¡ãœãããŸãã¯ããããã®ã€ãã³ããçºçãããšãã«åŒã³åºãããã¡ãœããããªãŒããŒã©ã€ãããŸãã ã€ãã³ããã³ãã©ãŒã®äœ¿çšäŸã¯ãMonitoredFSMããã³LoggedFSMã¯ã©ã¹ã§ãã
ã©ã€ãã©ãªã¯ã©ã¹ã®åäœããã詳现ã«ç解ããæè¯ã®æ¹æ³ã¯ããããã¬ã§ã©ã€ãã©ãªã«ä»å±ããJUnitãã¹ããå®è¡ããããšã§ãã ãããã®ãã¹ãã¯ãã©ã€ãã©ãªã䜿çšããŠãã®åäœã®ããžãã¯ã瀺ãäŸãšãªãããã«ç¹å¥ã«äœæãããŸããã
ããŒãã¹ | ã©ã€ãã©ãªãœãŒã¹ã³ãŒãã¯GWTã§æ£åžžã«ã³ã³ãã€ã«ãããŸã
|
å®ç掻ã®äŸ
次ã«ãå®éã®ç掻ã«ããè¿ãäŸãèããŠã¿ãŸãããã ãã¿ã³ãæŒããŠç¹å®ã®ãã©ãŒã ãç»é¢ã«è¡šç€ºããGWTã¢ããªã±ãŒã·ã§ã³ãäœæããŸãããã ãã©ãŒã ã衚瀺ããå Žåã2段éã§ãµãŒããŒããããŒã¿ãããŠã³ããŒãããå¿
èŠããããŸãããŸãããã©ãŒã ã®æ§æãããŒãããã次ã«ããŒã¿ãããŠã³ããŒããããŠãã©ãŒã ã«è¡šç€ºãããŸãã ãã¿ã³ãã¯ãªãã¯ããã ãã§ãã©ãŒã ãéããããšãã§ããŸãã ããŠã³ããŒãããã»ã¹ã¯ããŠãŒã¶ãŒã«ãã£ãŠäžæãããå ŽåããããŸãã ããŠã³ããŒãããã»ã¹äžã«ãå®è¡ããæäœã®ååã瀺ãé²è¡ç¶æ³ã€ã³ãžã±ãŒã¿ã衚瀺ãããŸãã
ãã·ã³ã«ã¯5ã€ã®ç¶æ
ããããŸãã
éåžžã®ç¶æ
ã«å ããŠã2ã€ã®ã°ã«ãŒãç¶æ
ãå®çŸ©ããŸãã 1ã€ç®ã¯LOADCONFIGç¶æ
ãšLOADDATAç¶æ
ãå«ã¿ãRPCFailureã€ãã³ããåŠçããŸãã 2çªç®ã«ã¯ãLOADCONFIGãLOADDATAãããã³SHOWç¶æ
ãå«ãŸããHideEventã€ãã³ããåŠçãã圹å²ãæãããŸãã
é²è¡ç¶æ³ããŒãå®è£
ããããšã¯æ®ã£ãŠããŸãã ããã¯éåžžã«ãšã¬ã¬ã³ãã§æ®éçãªæ¹æ³ã§è¡ãããšãã§ããæœè±¡çãªã¢ããªã±ãŒã·ã§ã³ã ãã§ãªããã»ãšãã©ã®åæ§ã®ã¿ã¹ã¯ã«ãé©ããŠããŸãã
ãŸããFSMã®ä»£ããã«ãObserverãã¿ãŒã³ãå®è£
ããMonitoredFSMã¯ã©ã¹ã䜿çšããŸãã ããã«ãããã€ãã³ããã·ã³ã®ç¶æ
å€æŽã€ãã³ããã³ãã©ãŒãæ¥ç¶ã§ããŸãïŒå¥ã®æ¹æ³ã¯ãFSMã¯ã©ã¹ã®onAfterSwitchStateïŒïŒã¡ãœãããèªåã§åå®çŸ©ããããšã§ãïŒã
次ã«ãStateã¯ã©ã¹ããProgressStateã¯ã©ã¹ãçæããŸãã ã³ã³ã¹ãã©ã¯ã¿ãŒã§æå®ãããç¶æ
ã®èª¬æã®ååšã«ãã£ãŠãç¥å
ãšã¯ç°ãªããŸãã
3çªç®ã«ãMonitoredFSMã¯ã©ã¹ã€ã³ã¹ã¿ã³ã¹ã®ã³ãŒã«ããã¯ã次ã®ããã«å®çŸ©ããŸãã
ProgressStateåã®ç¶æ
ãžã®åé·ç§»ã§ããã®ã³ãŒã«ããã¯ã¯é²è¡ç¶æ³ã€ã³ãžã±ãŒã¿ãŒã衚瀺ããŸããé²è¡ç¶æ³ã€ã³ãžã±ãŒã¿ãŒã¯ãçŸåšã®ç¶æ
ã®èª¬æãçŸåšã®ç¶æ
ã®æ°ãããã³ç¶æ
ã®ç·æ°ã瀺ããŸãã éåžžã®ç¶æ
ã«ç§»è¡ãããšãé²è¡ç¶æ³ã€ã³ãžã±ãŒã¿ãæ¶ããŸãã
ã芧ã®ãšãããçŸåšã®ç¶æ
ããããã«åæ¢ãã衚瀺ãããæ°ã®ç¶æ
ã®ç·æ°ïŒã2/5ããšã3/5ãã衚瀺ãããŸãããã1/2ããšã ã2/2ãïŒã ãã®åé¡ã®å¯èœãªè§£æ±ºçã«ã€ããŠã¯èª¬æããŸãããEnumSetã¯ã©ã¹ãšãã®éçã¡ãœãããæçšã§ãããšèšãã ãã§ãã
ãŸãšãããšããªãŒãããã³ã®æ¬¡ã®å®çŸ©ãåŸãããŸãïŒLOADCONFIGç¶æ
ãšLOADDATAç¶æ
ã§ã¯ãå€éšã®åœ±é¿ãåŠçããããŸããŸãªæ¹æ³ã瀺ãããŠããŸãïŒã
ãã¿ã³ã¯ãªãã¯ã€ãã³ããã³ãã©ãŒã¯æ¬¡ã®ããã«ãªããŸãã
RPCãªã¯ãšã¹ããã³ãã©ã¯æ¬¡ã®ããã«ãªããŸãã
æåŸã®2ã€ã®ã³ãŒããã©ã°ã¡ã³ããã次ã®ããã«ãäžæ°ã«GWTã¢ããªã±ãŒã·ã§ã³ã®éåæéšåãæ£ç¢ºã«å®è£
ãããã®ããã®åçŽã§æ®éçãªãã¿ãŒã³ãäœæããã¿ã¹ã¯ãèŠã€ããŸããã ããã«ããã®ãã¿ãŒã³ã¯ãRPCèŠæ±ãã³ãã©ãŒãšéåžžã®ã€ãã³ããã³ãã©ãŒã®äž¡æ¹ã§åäžã§ãã
ã©ã€ãã©ãªã®ãœãŒã¹ã³ãŒãã¯ã
Google Codeã§å
¥æã§ããŸãã trunk / fsmãã©ã«ããŒã«ã¯ã©ã€ãã©ãªèªäœãšJUnitãã¹ãããããtrunk / gwt_fsmãã©ã«ããŒã«ã¯äŸãšããŠèæ
®ãããGWTã¢ããªã±ãŒã·ã§ã³ããããŸãã
çµè«
AkerFSMã©ã€ãã©ãªã¯ããã¹ãŠã®èªåããã°ã©ãã³ã°æ©èœããµããŒãããŠããŸãã
- æ瀺çãªç¶æ
ã®å²ãåœãŠãšç¶æ
ãã·ã³ã®ã³ãŒãã£ã³ã°
- switchã¹ããŒãã¡ã³ããšå€èŠ³ã䌌ãŠãããæéç¶æ
ãã·ã³ã®æ確ã§ç°¡æœãªå®çŸ©
- ããŸããŸãªçš®é¡ã®ãã·ã³ïŒMilesãMooreãmixedïŒã®ãµããŒã
- ã€ãã³ããã·ã³ãšã³ã³ãã¥ãŒãã£ã³ã°ãã·ã³ã®ãµããŒãïŒããã³ããã2ã€ã®ã¢ãã«ã1å°ã®ãã·ã³ã«æ··åšãããæ©èœïŒ
- çµã¿èŸŒã¿ãã·ã³ã®ãµããŒã
- ã°ã«ãŒã移è¡ãµããŒã
- æéç¶æ
ãã·ã³ã®èŠ³ç¹ãããã®ã³ã°ããå¯èœæ§
èªåããã°ã©ãã³ã°ã®ãªã¹ããããæ©èœã®ãµããŒãã«å ããŠãAkerFSMã©ã€ãã©ãªã«ã¯2ã€ã®åºæ¬çãªå©ç¹ããããŸãã
- ããžãã¹ããžãã¯ã¯ããã¯ãããžãŒã³ãŒããšã¯å¥ã®ãã®ã§ãã å®éãç¹å®ã®ãã·ã³ã®ããžãã¯ïŒããžãã¹ããžãã¯ïŒã¯ãæéç¶æ
ãã·ã³ã®ã¢ãã«ãå®è£
ããã³ãŒããšã¯å¥ã«èšå®ãããŸãã ã¢ãã«ã®å®è£
ã¯ãç¹å®ã®ãã·ã³ãšã¯ç¬ç«ããŠåå®çŸ©ããã³æ¡åŒµã§ããå¿
èŠãªæè¡æäœã§ããžãã¹ããžãã¯ããè£
食ãããŸãã
- ã©ã€ãã©ãªã¯ãªããžã§ã¯ãæåã§ãããã©ã€ãã©ãªã®åºæ¬ã¯ã©ã¹ã¯ç°¡åã«æ¡åŒµå¯èœã§ãã
ãããã®å©ç¹ã®ãããã§ãå€ãã®å©ç¹ãšæ¡åŒµã®æ©äŒããããŸãã ãããã®ããã€ãããªã¹ãããŸã
- é·ç§»ã®æ¡ä»¶ã確èªãããšããç¶æ
ã«å
¥ããšããããã³çµäºãããšãã«å®è¡ãããã¢ã¯ã·ã§ã³ã決å®ãã1ã€ã®ã³ãŒããããã¯ã®æ©èœã
- ãã°ã«ãŒãé·ç§»ãã¯ã°ã©ãã£ãã¯è¡šèšã®èŠçŽ ãšããŠã®ã¿ååšããå®è£
ã§ã¯ãŸã£ãããµããŒããããªãäžèšã®èªåããã°ã©ãã³ã°ã«é¢ããåºçç©ãšã¯ç°ãªããAkerFSMã©ã€ãã©ãªã¯ãã°ã«ãŒãç¶æ
ãã®æŠå¿µãå®å
šã«å®è£
ããŸãã éåžžã®ç¶æ
ãšåæ§ã«ãã°ã«ãŒãç¶æ
ã®å Žåãé·ç§»ç¶æ
ãããã³ã°ã«ãŒãç¶æ
ã«åºå
¥ããããšãã«å®è¡ãããã¢ã¯ã·ã§ã³ã決å®ããããšãã§ããŸãã
- æéç¶æ
ãã·ã³ã¢ãã«ãããããªãããã¢ãã«ãžã®ç§»è¡ã¯ãFSMã¯ã©ã¹ã®åçŽãªæ¡åŒµã§ãã
- ãŸããé·ç§»ã®å±¥æŽãä¿åã§ãããã·ã³ã®ã¢ãã«ãç°¡åã«äœæã§ããŸãã
- æŠç¥ãã¿ãŒã³ãšFSMã¯ã©ã¹ã®å®è£
ã«ãããå¶åŸ¡ããã¯ã©ã¹ãããã·ã³ãåé¢ã§ããŸãã ããã«ãããç¹ã«ããã·ã³ã®JUnitãã¹ããå®è¡ããä»ã®ã¢ããªã±ãŒã·ã§ã³ããå®å
šã«åé¢ããããšãã§ããŸãã
- Stateã¯ã©ã¹ã¯ïŒFSMã¯ã©ã¹ãšçµã¿åãããŠïŒStateãã¿ãŒã³ãå®è£
ããŸãã ãã®ããŒã«ã§ã®äœ¿çšã®æãåçŽãªããŒãžã§ã³ã¯ãã¿ã¹ã¯ã«åºæã®æäœã§ã€ã³ã¿ãŒãã§ã€ã¹ãå®çŸ©ããStateã¯ã©ã¹ã®å¿
èŠãªæ°ã®åå«ã§ãã®ã€ã³ã¿ãŒãã§ã€ã¹ãå®è£
ããããšã ããå¿
èŠã§ãã Stateãã¿ãŒã³ã®èª¬æã®ãGang of Fourãã«ã¯ãç¹å®ã®ç¶æ
å
ã®é·ç§»ããžãã¯ã®å®çŸ©ãããµãã¯ã©ã¹éã®å®è£
äŸåé¢ä¿ããå°å
¥ãããšæžãããŠããŸãããAkerFSMã©ã€ãã©ãªã¢ãŒããã¯ãã£ã«ã¯ãã®æ¬ ç¹ã¯ãããŸããã ãã®å Žåãç¶æ
éã®é·ç§»ã®ããžãã¯ã¯æéç¶æ
ãã·ã³ã«ãã£ãŠæ±ºå®ãããç¹å®ã®ç¶æ
ã®ã¯ã©ã¹ã§èšè¿°ãããŸããããããã®éã«äŸåé¢ä¿ã¯ãããŸããã
- FSMã¯ã©ã¹ã®æ¡åŒµãå¯èœã§ããããã«ãããå®è¡æã«ãªãŒãããã³ã®å®çŸ©ãå€æŽã§ããŸãïŒç¶æ
ã®è¿œå ãåé€ãããã³çœ®æïŒã
èŠçŽãããšãAkerFSMã©ã€ãã©ãªã¯ã
Polkarpovaã®èæž
Shalytoã®ãAutomated Programmingãã§èª¬æãããŠããå®è£
ããã倧å¹
ã«åªããŠãã
ãšèšããŸãã
PSã GroovyãŸãã¯Rubyã§ã¯ãåæ§ã®å®è£
ãããã«çŸããã§ãããšç¢ºä¿¡ããŠããŸãã