Open Telecom Platform / Open Telecommunication PlatformïŒOTP / OTPïŒã®æŠèŠ
gen_serverã®æŠèŠïŒErlybank
ããã¯ãOTPã·ãªãŒãºã®æŠèŠã®2çªç®ã®èšäºã§ãã gen_serverã«ã€ããŠèª¬æã ããããèªãåã«éè¡ã·ã¹ãã ã®åºç€ãç¯ãæåã®èšäºãèªãããšããå§ãããŸãã ãã°ããææ¡ããã°ã å®æããããŒãžã§ã³ã®ãµãŒããŒã確èªããŠå ã«é²ãããšãã§ããŸãã
ã·ããªãªïŒ ErlyBankãµãŒããŒã顧客ã«æäŸããŸãããã顧客ã¯éåžžã«æºè¶³ããŠããŸããã ãããã21äžçŽã¯åºã«ãããå®å šã§äœ¿ããããATMãæ±ããŠããããããµãŒããŒãæ¡åŒµããATMçšã®ãœãããŠã§ã¢ãäœæããããäŸé ŒãããŸããã ãŠãŒã¶ãŒã¢ã«ãŠã³ãã¯4æ¡ã®PINã³ãŒãã§ä¿è·ããå¿ èŠããããŸãã ATMã§ã¯ã以åã«äœæããã¢ã«ãŠã³ãã䜿çšããŠãã°ã€ã³ããã¢ã«ãŠã³ãããå ¥éãŸãã¯åŒãåºããè¡ãããšãã§ããŸãã çŸããã€ã³ã¿ãŒãã§ã€ã¹ãäœæããå¿ èŠã¯ãããŸãã;ä»ã®äººãããããã£ãŠããŸãã
ç®æšïŒæåã«ãã¢ã«ãŠã³ãã®PINã³ãŒãã®ãµããŒããšPINã³ãŒãã«ããèªèšŒãè¿œå ããŠããµãŒããŒãæ¡åŒµããŸãã 次ã«ãgen_fsmã䜿çšããŠATMããã¯ãšã³ããäœæããŸãã ããŒã¿æ€èšŒã¯ãµãŒããŒåŽã§å®è¡ãããŸãã
gen_fsmãšã¯äœã§ããïŒ
gen_fsmã¯å¥ã®Erlang / OTPã€ã³ã¿ãŒãã§ã€ã¹ã¢ãžã¥ãŒã«ã§ãã æéç¶æ ãã·ã³ãå®è£ ããããã«äœ¿çšãããŸãã
ãã®èšäºã§ã¯ãç¶æ ãã®æŠå¿µã2ã€ã®ããšãæå³ããããã«äœ¿çšããããããäºåã«è¬çœªããŸãã
- state gen_fsm-ç¶æ ãã·ã³ã®ç¶æ ããã®æäœã®çŸåšã®ãã¢ãŒããã gen_serverããã®ç¶æ ïŒããŒã¿ïŒãšã¯é¢ä¿ãããŸããã
- ã¹ããŒã¿ã¹ïŒããŒã¿ïŒ -ãµãŒããŒã¹ããŒã¿ã¹ããŒã¿ã¯ãgen_serverã«ã€ããŠã®ä»¥åã®èšäºããåŠãã ããšã§ãã
ãã¡ããå°ãcã§ãããäžèšã®æ¡ä»¶ã®ã³ã³ããã¹ãã§ã®ã¿åç §ããããã«ããŸãã
gen_fsmã¯ããç¶æ ã§åäœãéå§ããŸãã gen_fsmãžã®åŒã³åºã/ãã£ã¹ãåŒã³åºãã¯ãç¹å¥ãªã³ãŒã«ããã¯ã¡ãœããã§åŠçãããŸãããã®ã¡ãœããã¯ãgen_fsmã®çŸåšã®ç¶æ ïŒã¹ããŒããã·ã³ïŒã®ååãšåŒã°ããŸãã å®è¡ãããã¢ã¯ã·ã§ã³ã«åºã¥ããŠãã¢ãžã¥ãŒã«ã¯ç¶æ ãå€æŽã§ããŸãïŒ[çŸåšã®ç¶æ ãçä¿¡æå]->æ°ããç¶æ ãçŽïŒã ã¹ããŒããã·ã³ã®æç§æžã®äŸã¯ãéãããã¢ã§ãã æåã¯ããã¢ã¯ãéãããç¶æ ã§ãã éãã«ã¯4æ¡ã®ã³ãŒããå ¥åããå¿ èŠããããŸãã 1æ¡ãå ¥åãããšããã¢ã¯ãããä¿åããŸããã1æ¡ã§ã¯äžååãªã®ã§ããéãããç¶æ ã§åŸ æ©ãç¶ããŸãã 4æ¡ãå ¥åããåŸãããããæ£ããå Žåããã¢ã¯ãã°ãããã®ç¶æ ããéããã«å€æŽããŸãã æ°å€ãæ£ãããªãå Žåããã¯ããŒãºãç¶æ ã®ãŸãŸã«ãªããã¡ã¢ãªãã¯ãªã¢ãããŸãã ãããããgen_fsmã䜿çšããŠã¹ããŒããã·ã³ãå®è£ ããæ¹æ³ã«ã€ããŠããã§ã«ããã€ãã®æšæž¬ããæã¡ãããããŸããã
gen_serverã®å Žåãšåæ§ã«ãgen_fsmã§å®è£ ããå¿ èŠãããã³ãŒã«ããã¯ã¡ãœããã®ãªã¹ãã瀺ããŸãã gen_serverã«é¢é£ããããšããããããããŸãã
- init / 1-ã¹ããŒããã·ã³ãµãŒããŒãåæåããŸãã gen_serverãšã»ãŒåãã§ãã
- StateName / 2 -StateNameã¯å·ã®ååã«çœ®ãæããããŸãã ãã®ã¡ãœããã¯ãã¹ããŒããã·ã³ããã®ç¶æ ã«ãããã¡ãã»ãŒãžãåä¿¡ãããšãã«åŒã³åºãããŸãã ãã®çµæãç¹å®ã®ã¢ã¯ã·ã§ã³ãå®è¡ãããŸãã ããã¯éåæã³ãŒã«ããã¯ã¡ãœããã§ãã
- handle_event / 3 -StateName / 2ãšåãããã ãããã®ã¡ãœããã¯ããã·ã³ã®çŸåšã®ç¶æ ã«é¢ä¿ãªããã¯ã©ã€ã¢ã³ããgen_fsmïŒsend_all_state_eventãåŒã³åºãããšãã«èµ·åããŸãã ç¹°ãè¿ããŸãããéåæã§ãã
- StateName / 3 -StateName / 2ã®åæããŒãžã§ã³ã ã¯ã©ã€ã¢ã³ãã¯ãµãŒããŒã®å¿çãåŸ ã¡ãŸãã
- handle_sync_event / 4 -handle_eventã®åæããŒãžã§ã³/ 3ã
- handle_info / 3 -gen_server handle_infoãšåçã§ãã ãã®ã¡ãœããã¯ãgen_fsmã®éæšæºã®æ段ã«ãã£ãŠéä¿¡ããããã¹ãŠã®ã¡ãã»ãŒãžãåä¿¡ããŸãã ããã¯ãã¿ã€ã ã¢ãŠãã¡ãã»ãŒãžãããã»ã¹çµäºã¡ãã»ãŒãžããŸãã¯ãïŒãã䜿çšããŠãµãŒããŒããã»ã¹ã«éä¿¡ããããã®ä»ã®ã¡ãã»ãŒãžã§ãã
- terminate / 3-ãµãŒããŒã®ã·ã£ããããŠã³æã«åŒã³åºããããµãŒããŒå ã®å æãªãœãŒã¹ã解æŸã§ããŸãã
- code_change / 4-ãµãŒããŒããªã¢ã«ã¿ã€ã ã§æŽæ°ããããšãã«åŒã³åºãããŸãã çŸåšã¯äœ¿çšããŠããŸããããä»åŸã®èšäºã§äœ¿çšããäºå®ã§ãã
gen_fsmã¹ã±ã«ãã³
gen_serverãšåæ§ã«ãäžè¬çãªã¹ã±ã«ãã³ã䜿çšããŠã¹ããŒããã·ã³ãäœæãå§ããŸãã gen_fsmã®ã¹ã±ã«ãã³ã¯ãã¡ãã«ãããŸã ã
ç¹å¥ãªãã®ã¯ãããŸããã start_linkã¯ãgen_serverçšã«äœæãããã®ã«äŒŒãŠããŸãã :)ã¹ã±ã«ãã³ãeb_atm.erlãšããŠä¿åããŸãã ããã§ãéå§ããæºåãã§ããŸããïŒ
ã¢ã«ãŠã³ãèªèšŒã¡ã«ããºã ãäœæããããã®eb_serveræ¡åŒµã
ããã¯ç§ãããªãã«ä»»ããå¥ã®ã¿ã¹ã¯ã§ãã å¿ èŠãªå€æŽïŒ
- ããã§ãã¢ã«ãŠã³ããäœæãããšãã«ãæå·åããã«ã¢ã«ãŠã³ããšå ±ã«ä¿åãããPINã³ãŒããèŠæ±ããå¿ èŠããããŸãã
- ååãšPINåŒæ°ã䜿çšããŠauthorize / 2ã¡ãœãããè¿œå ããŸãã æ»ãå€ã¯
ok
ãŸãã¯{error, Reason}
ãªããã°ãªããŸããã
ãŸããå ¥é/åºéæäœããšã«PINã³ãŒããèŠæ±ããããšã¯çŽ æŽãããããšã§ãããæéãç¯çŽããããã«ããŸãéè¡ãåœç©ã§ããããïŒç§ã®å¿ãå£ããŠããŸãïŒïŒhaïŒïŒãããã¯è¡ããŸããïŒã
æ£çŽãªãšãããããã¯ããã»ã©ç°¡åã§ã¯ãããŸããããErlangãèªåã§åŠã¹ã°ãååã«è³¢ããªããã°ãªããŸãã;ïŒã ããããªãã¯ãããã§ãããšæããŸãïŒ ç¶è¡ããåã«å€æŽããã¹ãããããå°ãªããšã以äžã®åçãšæ¯èŒããŠãã ããã
å€æŽåŸãeb_server.erlã¯æ¬¡ã®ããã«ãªããŸã ã ãµãŒããŒã«éä¿¡ããã¡ãã»ãŒãžã¯ç°ãªãå Žåãããããšã«æ³šæããŠãã ãããããã¯æ£åžžãªåäœã§ãã 誰ããç°ãªãèãæ¹ãæã£ãŠããŸãã APIãåãããŒã¿ãæ£ããåºåããããšãéåžžã«éèŠã§ãã ïŒéèŠãªããšã¯ãAPIãåãããŒã¿ãæ£ããåºåããããšã§ãïŒ
ATMèšèšæŠç¥
ATMã¹ããŒããã·ã³ã®äœæ¥èšç»ãäŒããããã«ããã³ãŒããªããã®çãäŒæ¢ããšããããšæããŸãã 以äžã®å³ã«åŸã£ãŠå®è¡ããŸãã
3ã€ã®éããããã¯ã¯ãç°ãªããµãŒããŒç¶æ ãè¡šããŸãã ç¢å°ã¯ãããç¶æ ããå¥ã®ç¶æ ã«ç§»è¡ããããã«å¿ èŠãªã¢ã¯ã·ã§ã³ã瀺ããŠããŸãã
gen_fsmã®åæå
ATMãèµ·åããã«ã¯ãgen_serverãšåãstart_linkã¡ãœããã䜿çšããŸãã ãã ããåæåã¯å°ãç°ãªããŸãã
initïŒ[]ïŒ-> {OKãç¡èš±å¯ã誰ã}ã
gen_fsmã®init / 1ã¡ãœããã¯
{ok, StateName, StateData}
ãè¿ãå¿ èŠããããŸãã StateNameã¯ãµãŒããŒã®åæç¶æ ãStateDataã¯ãµãŒããŒã®åæç¶æ ïŒããŒã¿ïŒã§ãã ãã®ã±ãŒã¹ã§ã¯ãç¡èš±å¯ã®ç¶æ ã§éå§ããããŒã¿ã¯
nobody
èšå®ãããŸãã ç¶æ ïŒããŒã¿ïŒã¯äœæ¥ããŠããã¢ã«ãŠã³ãã®ååã«ãªããããæåã¯äœããããŸããã Erlangã«ã¯null / nil / nothingã®ããŒã¿åããããŸããã代ããã«ãäŸãã°èª°ãããªãã®ã§ãéåžžã¯è©±ãã¢ãã ã䜿çšãããŸãã
ã¢ã«ãŠã³ãèªèšŒ
次ã«ãATMã®èªèšŒAPIãå®è£ ããå¿ èŠããããŸãã ãŸããAPIå®çŸ©ïŒ
æ¿èªïŒååãPINïŒ-> gen_fsmïŒsync_send_eventïŒïŒSERVERã{authorizeãNameãPIN}ïŒã
sync_send_eventã¡ãœããã¯ãgen_serverã¢ãžã¥ãŒã«ã®åŒã³åºãã¡ãœãããšåçã§ãã ãµãŒããŒã®çŸåšã®ç¶æ ïŒæåã®åŒæ°ïŒã«ã¡ãã»ãŒãžïŒ2çªç®ã®åŒæ°ïŒãéä¿¡ããŸãã ãããã£ãŠããã®ã¡ãã»ãŒãžã®ãã³ãã©ãŒãäœæããå¿ èŠããããŸãã
æªæ¿èªïŒ{authorizeãNameãPin}ã_FromãStateïŒ-> ã±ãŒã¹eb_serverïŒã®æ¿èªïŒååããã³ïŒ OK-> {è¿ä¿¡ãOKãæ¿èªæžã¿ãåå}; {ãšã©ãŒãçç±}-> {è¿ä¿¡ã{ãšã©ãŒãçç±}ãäžæ£ãç¶æ } çµãã; äžæ£ïŒ_Eventã_FromãStateïŒ-> è¿ä¿¡= {ãšã©ãŒãç¡å¹ãªã¡ãã»ãŒãž}ã {è¿ä¿¡ãè¿ä¿¡ãæªæ¿èªãå·}ã
ãã®é¢æ°ã¯ããµãŒããŒãç¡èš±å¯ã®ç¶æ ã«ãããšãã«ã¡ãã»ãŒãžãåä¿¡ããå¿ èŠããããããç¡èš±å¯ãšåŒã°ããŸãã ã¿ãã
{authorize, Name, Pin}
ãåŠçããeb_serverãµãŒããŒã«ãã£ãŠãšã¯ã¹ããŒããããAPIã¡ãœããã䜿çšããŠãŠãŒã¶ãŒãèªèšŒããããã«ããµã³ãã«ãšæ¯èŒããŸãã
ãŠãŒã¶ãŒåãšPINãæ£ããå Žåãã¯ã©ã€ã¢ã³ãã«
ok
ãéä¿¡
ok
ãŸãã å¿ç圢åŒïŒ
{reply, Response, NewStateName, NewStateData}
圢åŒã«åŸã£ãŠãç¶æ ãèš±å¯ã«å€æŽããã¢ã«ãŠã³ãåãç¶æ ïŒããŒã¿ïŒã«ä¿åããŸãã
ã¢ã«ãŠã³ãæ å ±ãééã£ãŠããå Žåããšã©ãŒããã³ãšã©ãŒã®åå ãå¿çãšããŠéä¿¡ããŸããç¶æ ãšæ¡ä»¶ïŒããŒã¿ïŒã¯å€æŽãããŸããã
æåŸã«ãå¥ã®ãã£ãããªãŒã«é¢æ°ãå®è£ ããŸãã åžžã«ãããè¡ãå¿ èŠããããŸããã ããã§ã¯ç¹ã«éèŠã§ã ããªããªããç¶æ ã¯ä»ã®ç¶æ ã«å®ãŠãããã¡ãã»ãŒãžãåä¿¡ã§ããããã§ãã äŸïŒäœããã®çç±ã§ã誰ããæªæŸéã®ç¶æ ã§é éããããšãããšã©ããªããŸããïŒ ãšã©ãŒã¡ãã»ãŒãžãéãè¿ãã«ã¯ããã£ãããªãŒã«ã¡ãœãããå¿ èŠã§ãã
å ¥é
æ¿èªç¶æ ã«å ¥ããšããã«ããŠãŒã¶ãŒã¯èªåã®éè¡å£åº§ããå ¥éãŸãã¯åŒãåºããè¡ããŸãã ãµãŒããŒãžã®éåæåŒã³åºãã䜿çšããŠãããžãããå®è£ ããŸãã ç¹°ãè¿ããŸãããããã¯ããŸãå®å šã§ã¯ãããŸãããå ¥éãæåãããã©ããã¯ãŸã£ãããã§ãã¯ããŸããããéè¡ã¯åœç©ãªã®ã§ãå¿ããŠããŸããŸãã ;ïŒ
ãããã£ãŠãæåã¯APIã§ãïŒ
%% ------------------------------------------------ -------------------- %%é¢æ°ïŒdepositïŒAmountïŒ-> ok %%説æïŒçŸåšæ¿èªãããŠããç¹å®ã®éé¡ãå ¥éããŸã %%ã¢ã«ãŠã³ãã %% ------------------------------------------------ -------------------- ãããžããïŒéé¡ïŒ-> gen_fsmïŒsend_eventïŒïŒSERVERã{depositãAmount}ïŒã
ç°¡åã§ããä»åã¯ãsync_send_eventã®ä»£ããã«
send_event/2
ã¡ãœããã䜿çšã
send_event/2
ã ãµãŒããŒã«éåæåŒã³åºããéä¿¡ããŸãã ãããŠä»ããã³ãã©ãŒ...
æ¿èªæžã¿ïŒ{depositãAmount}ãStateïŒ-> eb_serverïŒdepositïŒå·ãéé¡ïŒã {next_stateãthank_youãStateã5000}; æ¿èªæžã¿ïŒ_EventãStateïŒ-> {next_stateãauthorizedãState}ã
ç¹°ãè¿ããŸããããã¹ãŠãéåžžã«ç°¡åã§ãã ãã®ã¡ãœããã¯ãæ å ±ãåã«eb_serverã¢ãžã¥ãŒã«ã®depositã¡ãœããã«ãªãã€ã¬ã¯ãããŸãããã®ã¡ãœããã¯ããã§ãã¯å šäœãå®è¡ããŸãã ãã ããdepositã¡ãœããã®æ»ãå€ã«ã¯ç°åžžããããŸãïŒ ç¶æ ãthank_youã«å€ããã ãã§ãªããæåŸã«ãã®çªå·ã5000ãããããŸãã ããã¯åãªãã¿ã€ã ã¢ãŠãã§ãã 5000ããªç§ïŒ5ç§ïŒä»¥å ã«ã¡ãã»ãŒãžãåä¿¡ãããªãå Žåã
-
ãçŸåšã®ç¶æ ã«éä¿¡ãããŸãã
ã³ãã«ã¯æ¬¡ã®ãããã¯ã«ç§ãã¡ãå°ããŸã...
çããããããšãïŒãæ¡ä»¶
ATMã䜿çšããå€ãã®ïŒãŸãã¯ãã¹ãŠã®ïŒäººã ã¯ãçãé衚瀺ãããå°ããªãããããšãïŒãç»é¢ãããããšãç¥ã£ãŠããŸãã å®éãå®è£ ã§ã¯ãã®ç»é¢ããªããŠãå®å šã«å®è¡ã§ããŸããgen_fsmã«ã¿ã€ã ã¢ãŠãã®ããæ©èœã衚瀺ãããã£ãã ãã§ãã 5000ããªç§åŸããŸãã¯ã¡ãã»ãŒãžãåä¿¡ãããªãå Žåãç¶æ ããç¡èš±å¯ãã«æ»ãã®ã§ãATMã¯æ¬¡ã®ãŠãŒã¶ãŒã§åã³éå§ã§ããŸãã ã³ãŒãã¯æ¬¡ã®ãšããã§ãã
thank_youïŒã¿ã€ã ã¢ãŠãã_StateïŒ-> {next_stateãç¡èš±å¯ãç¡äºº}; thank_youïŒ_Eventã_StateïŒ-> {next_stateãç¡èš±å¯ãç¡äºº}ã
泚ïŒèšç·Žãåããç®ã§ã¯ãäž¡æ¹ã®æ¹æ³ãåçã§ãããæåã®ãµã³ãã«ã¯äžèŠã§ããããšãããããŸãã 確ãã«ãæåã®ãµã³ãã«ãå«ããŠãã¿ãŠããŠããæãŸããããã«ããŸããã
ãããŠãããã«çŸåšå®æããeb_atm.erlã®ããŒãžã§ã³ããããŸãã
ã¢ã«ãŠã³ããããéãåŒãåºã
ç¹°ãè¿ããŸããããéãåŒãåºãæ¹æ³ã®éçºã¯èªè ã®ããã®æŒç¿ãšããŠæ®ããŠãããŸãã å¿ èŠã«å¿ããŠãã®ããºã«ãå®è£ ã§ããŸãïŒ ããªããæ¬åœã«ãéãåãããšã確èªããŠãã ãã;ïŒ
ããã¯ãåŒãåºãã¡ã«ããºã ãå®è£ ããåŸã®eb_atm.erlã®ç§ã®ããŒãžã§ã³ã§ã ã æäœãæ£åžžã«å®äºãããšããã·ã³ãã¿ã€ã ã¢ãŠãã§thank_youç¶æ ã«ç§»è¡ããããšã«æ³šæããŠãã ããã
ãäœããã£ã³ã»ã«ããªãããã¿ã³
ã³ã³ãã¥ãŒã¿ãŒã®æ倧ã®åé¡ã®1ã€ã¯ããã¹ãŠãäžæãã[ãã£ã³ã»ã«]ãã¿ã³ããªãããšã§ãã ãããŠãã³ã³ãã¥ãŒã¿ãŒã®é»æºãªããã¿ã³ããã®ã¿ã¹ã¯ã«å¯Ÿå¿ããŠããããšã¯æ¿ç¥ããŠããŸãããErlybank ATMã®ãŠãŒã¶ãŒã¯ãã®ãããªæ©äŒã奪ãããŠããŸãã ãããã£ãŠãçŸåšã®ç¶æ ã«é¢ä¿ãªãããã¹ãŠã®ãã©ã³ã¶ã¯ã·ã§ã³ããã£ã³ã»ã«ããcancelã¡ãœãããå®è£ ããŸãããã
ãããã©ã®ããã«å®è£ ããŸããïŒ äžè¬ã«ããã®èšäºã®æ å ±ã«åºã¥ããŠãcancelã¡ãœããã䜿çšããŠ
cancel
ã¡ãã»ãŒãžãéä¿¡ããããšããå§ãããŸãã 次ã«ãåç¶æ ã§ããããåŠçãã
unauthorized
ç¶æ ã«æ»ããŸãã
æ©ç¥ã«å¯ãã§ããŸãããæ£ãããããŸããããããã¯ããªãã®ããã§ã¯ãããŸããïŒ ãµãŒããŒã®ç¶æ ã«é¢ä¿ãªãããµãŒããŒã«ã¡ãã»ãŒãžãéä¿¡ãã
gen_fsm:send_all_state_event/2
ã¡ãœãããããããšã瀺ããŸããã§ããïŒãŸãã¯ãç°¡åã«èª¬æããªãã£ããããããŸããïŒã ã³ãŒããã¯ãªãŒã³ã«ä¿ã€ããã«äœ¿çšããŸãã
APIïŒ
%% ------------------------------------------------ -------------------- %%æ©èœïŒãã£ã³ã»ã«/ 0 %%説æïŒç¶æ ã«é¢ä¿ãªãATMãã©ã³ã¶ã¯ã·ã§ã³ããã£ã³ã»ã«ããŸãã %% ------------------------------------------------ -------------------- ãã£ã³ã»ã«ïŒïŒ-> gen_fsmïŒsend_all_state_eventïŒïŒSERVERããã£ã³ã»ã«ïŒã
ãã®ã¡ãã»ãŒãžã¯ã以äžã«æ¡åŒµãã
handle_event/3
éä¿¡ãããŸãã
handle_eventïŒãã£ã³ã»ã«ã_StateNameã_StateïŒ-> {next_stateãç¡èš±å¯ãç¡äºº}; handle_eventïŒ_EventãStateNameãStateïŒ-> {next_stateãStateNameãState}ã
ãã£ã³ã»ã«ã¡ãã»ãŒãžãåä¿¡ããå ŽåããµãŒããŒã¯ç¶æ ãç¡èš±å¯ã«ãé£çµ¡å ïŒããŒã¿ïŒã誰ã«ãå€æããŸããïŒæ°ããATMïŒ
ãã€ãã®ããã«ãeb_atm.erlã®çŸåšã®ããŒãžã§ã³ã¯ããã§èŠãããšãã§ããŸã ã
çµã³ã®ã¡ã¢
ãã®èšäºã§ã¯ã gen_fsmã䜿çšããŠã ã¹ããŒããã·ã³äžã«æ§ç¯ãããç°¡åãªATMã·ã¹ãã ãäœæããæ¹æ³ã瀺ããŸãã ã ããŸããŸãªç¶æ ã®ã¡ãã»ãŒãžãåŠçããæ¹æ³ãç¶æ ãå€æŽããæ¹æ³ãã¿ã€ã ã¢ãŠãã«ãã£ãŠç¶æ ãå€æŽããæ¹æ³ãããã³ãã¹ãŠã«ã¡ãã»ãŒãžãéä¿¡ããæ¹æ³ã瀺ããŸããã
ãã ããã·ã¹ãã ã«ã¯ãŸã ããã€ãã®ãããŒãããããããããä¿®æ£ããæ©äŒãæ®ããŠãããŸãã å¿ èŠã«å¿ããŠã2ã€ã®ã¿ã¹ã¯ãçšæããŸããã ç§ãä¿¡ããŠãããªãã¯ããããå®è¡ããããšãã§ããŸãïŒ
- é éæäœã«ãšã©ãŒãã§ãã¯ãè¿œå ããŸãã åžžã«ãokãã§ã¯ãªã
{ok, Balance}
{error, Reason}
ããã³{ok, Balance}
è¿ãããã«ã{error, Reason}
ã - ATMã«æ®é«ãã§ãã¯æ©èœãè¿œå ããŸãã èš±å¯ãããç¶æ ã§ã®ã¿äœ¿çšå¯èœã§ããããã©ã³ã¶ã¯ã·ã§ã³ãå®äºããŠã¯ãªããŸããã ããã¯ã圌女ãç¶æ ãthank_youã«å€æããªãããšãæå³ããŸãã ããã¯ãéåžžãæ®é«ã確èªãã人ããèªåã®å£åº§ã«åŒãåºãããããéãå ¥ããããšæãããã§ãã
æŒç¿ã®ããã2ã€ã®æ©èœã¯ä»åŸäœ¿çšãããŸããã䜿çšããå Žåã¯ãããã«åçãæ²èŒããŸããã ããããæ©èœãããããšã§ãã¹ãã§ããŸãïŒ :)
ãããã®èšäºã®ç¬¬2éšã¯å®äºããŠããŸãã 3çªç®ã®èšäºã¯ã»ãŒæºåãã§ããŠãããæ°æ¥äžã«å ¬éãããŸãã 圌女ã¯gen_eventãããã¯ã«ã€ããŠèª¬æããŸãã 楜ããããã«ãgen_eventã䜿çšããŠErlybankã«è¿œå ãããã®ã«ã€ããŠèããŠã¿ãŠãã ããã ïŒD
Erlang / OTPã®ãããã®çŽ¹ä»èšäºããç§ãããããæžãã®ã楜ããã§ããã®ãšåãããã楜ããã§ãããããšãé¡ã£ãŠããŸãã ãæ¯æŽãšå¹žéãããããšãããããŸããïŒ