Your SlideShare is downloading. ×
0
FINITESTATEMACHINES
(FSM)
WITHAKKAACTORS
WRITINGANDUNITTESTING'EM
"LIGHTNINGTALK"BYPRASANNAKUMAR
WHATISFSM?
whenaprogramisinastateSandan
eventEoccursthendoanactionAand
changetoanotherstateS1
Iftheabovesoundstootheoritic...
IMAGINEATRAFFICSIGNAL
hopeyoucouldunderstand!!!
WHYDOWENEEDFSM?
ATLEASTFORUS...
ModelandExecuteRules(weareusingit!!!)
Simulations
Automatabasedprogramming
WHYTHISPRESENTATION
IwanttolearnFSM
"FSM"FROMAKKAPERSPECTIVE
State
Data
MessagestotheactorisanalogoustoEvents
Actorabstractionitself
sealedtraitFSMSignal
case...
LET'SMODELFSM
//state-
sealedtraitFSMSignal
caseobjectRedSignalextendsFSMSignal
caseobjectYellowSignalextendsFSMSignal
cas...
ACTORCODE
classSignalChangeFSMActorextendsActorwithFSM[FSMSignal,SignalColorData]{
//initialstateofFSM
startWith(RedSignal...
CONTD...
when(GreenSignal){
caseEvent(ChangeSignal,_)=>goto(RedSignal)
caseEvent(RetainSignal,_)=> stay
}
onTransition{
ca...
UNITTESTINGFSMACTORSWITH
classFSMActorTest(as:ActorSystem)extendsTestKit(as)
withImplicitSender
withWordSpecLike
withMatch...
valfsmRef=TestFSMRef(newSignalChangeFSMActor)
defthis()=this(ActorSystem("FSMActorSystem"))
"OursignalemulatingFSMActor"mu...
SESSIONTAKEAWAY
Code:-https://github.com/prassee/FSMExperiment
HOWIMADETHISPRESENTATION?
HTML5
CSS3
Presentation:-reveal.js
Imagescourtesy:-googleimagesearch:)
ThispresentationisCCLlice...
THANKS:)
Upcoming SlideShare
Loading in...5
×

Akka fsm presentation

258

Published on

akka fsm talk given on Glassbeam

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
258
On Slideshare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
3
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Akka fsm presentation"

  1. 1. FINITESTATEMACHINES (FSM) WITHAKKAACTORS WRITINGANDUNITTESTING'EM "LIGHTNINGTALK"BYPRASANNAKUMAR
  2. 2. WHATISFSM? whenaprogramisinastateSandan eventEoccursthendoanactionAand changetoanotherstateS1 Iftheabovesoundstootheoriticaltounderstand....
  3. 3. IMAGINEATRAFFICSIGNAL hopeyoucouldunderstand!!!
  4. 4. WHYDOWENEEDFSM? ATLEASTFORUS... ModelandExecuteRules(weareusingit!!!) Simulations Automatabasedprogramming
  5. 5. WHYTHISPRESENTATION IwanttolearnFSM
  6. 6. "FSM"FROMAKKAPERSPECTIVE State Data MessagestotheactorisanalogoustoEvents Actorabstractionitself sealedtraitFSMSignal caseclassSignalColorData classSignalChangeFSMActorextendsActor withFSM[FSMSignal,SignalColorData]{ ..... }
  7. 7. LET'SMODELFSM //state- sealedtraitFSMSignal caseobjectRedSignalextendsFSMSignal caseobjectYellowSignalextendsFSMSignal caseobjectGreenSignalextendsFSMSignal //data caseclassSignalColorData //event caseobjectChangeSignal caseobjectRetainSignal
  8. 8. ACTORCODE classSignalChangeFSMActorextendsActorwithFSM[FSMSignal,SignalColorData]{ //initialstateofFSM startWith(RedSignal,SignalColorData()) when(RedSignal){ caseEvent(ChangeSignal,_)=>goto(YellowSignal) caseEvent(RetainSignal,_)=>stay } when(YellowSignal){ caseEvent(ChangeSignal,_)=>goto(GreenSignal) caseEvent(RetainSignal,_)=> stay }
  9. 9. CONTD... when(GreenSignal){ caseEvent(ChangeSignal,_)=>goto(RedSignal) caseEvent(RetainSignal,_)=> stay } onTransition{ caseRedSignal->YellowSignal=>println("Changingfromredtoyellowsignal-getr caseYellowSignal->GreenSignal=>println("Changingfromyellowtogreensignal-w caseGreenSignal->RedSignal=>println("Changingfromgreentoredsignal-stop!! } initialize }
  10. 10. UNITTESTINGFSMACTORSWITH classFSMActorTest(as:ActorSystem)extendsTestKit(as) withImplicitSender withWordSpecLike withMatchers withBeforeAndAfterAll{ //allourtestcases }
  11. 11. valfsmRef=TestFSMRef(newSignalChangeFSMActor) defthis()=this(ActorSystem("FSMActorSystem")) "OursignalemulatingFSMActor"must{ "beredatinitialstage"in{ assert(fsmRef.stateName==RedSignal) assert(fsmRef.stateData==SignalColorData()) } "changetoyellowafterAlternateColoureventoccured"in{ fsmRef!ChangeSignal//sendaneventtoFSM assert(fsmRef.stateName==YellowSignal) assert(fsmRef.stateData==SignalColorData()) } "changetogreenafterAlternateColoureventoccured"in{ fsmRef!ChangeSignal assert(fsmRef.stateName==GreenSignal) assert(fsmRef.stateData==SignalColorData()) } "retainshouldnotchangethefsmstate"in{ fsmRef!RetainSignal assert(fsmRef.stateName==GreenSignal) assert(fsmRef.stateData==SignalColorData()) } } overridedefafterAll={ println("trafficisclearnow-obeytrafficrules") }
  12. 12. SESSIONTAKEAWAY Code:-https://github.com/prassee/FSMExperiment
  13. 13. HOWIMADETHISPRESENTATION? HTML5 CSS3 Presentation:-reveal.js Imagescourtesy:-googleimagesearch:) ThispresentationisCCLlicensed-feelfreetomodify
  14. 14. THANKS:)
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×