{"action":"created","issue":{"url":"https://api.github.com/repos/statefulj/statefulj/issues/6","labels_url":"https://api.github.com/repos/statefulj/statefulj/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/statefulj/statefulj/issues/6/comments","events_url":"https://api.github.com/repos/statefulj/statefulj/issues/6/events","html_url":"https://github.com/statefulj/statefulj/issues/6","id":66958622,"number":6,"title":"Need help to use StatefulJ FSM","user":{"login":"domiq44","id":3637474,"avatar_url":"https://avatars.githubusercontent.com/u/3637474?v=3","gravatar_id":"","url":"https://api.github.com/users/domiq44","html_url":"https://github.com/domiq44","followers_url":"https://api.github.com/users/domiq44/followers","following_url":"https://api.github.com/users/domiq44/following{/other_user}","gists_url":"https://api.github.com/users/domiq44/gists{/gist_id}","starred_url":"https://api.github.com/users/domiq44/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/domiq44/subscriptions","organizations_url":"https://api.github.com/users/domiq44/orgs","repos_url":"https://api.github.com/users/domiq44/repos","events_url":"https://api.github.com/users/domiq44/events{/privacy}","received_events_url":"https://api.github.com/users/domiq44/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-04-07T18:17:39Z","updated_at":"2015-04-09T06:11:52Z","closed_at":null,"body":"Hi all,\r\n\r\nI would like to use StatefulJ FSM.\r\nBut example is light.\r\n\r\nI usually use Libero from iMatix, and I want to try to implement one testcase from it with StatefulJ FSM.\r\nHere is the sample (Example of Controlling a Telephone) : http://legacy.imatix.com/html/libero/lrintr3.htm\r\nI think it would be possible but I do not understand how !.\r\n\r\nCan anyone can help me doing that?\r\nThanks.\r\n\r\n```java\r\n\t\t// Events\r\n\t\t//\r\n\t\tString ok = \"Ok\";\r\n\t\tString error = \"Error\";\r\n\t\tString offhook = \"Offhook\";\r\n\t\tString onhook = \"Onhook\";\r\n\t\tString request = \"Request\";\r\n\t\tString digit = \"Digit\";\r\n\t\tString wholeNumber = \"Whole Number\";\r\n\t\tString accept = \"Accept\";\r\n\t\tString busy = \"Busy\";\r\n\t\tString reject = \"Reject\";\r\n\t\tString answer = \"Answer\";\r\n\t\tString release = \"Release\";\r\n\r\n\t\t// States\r\n\t\t//\r\n\t\tfinal State<Foo> afterInit = new StateImpl<Foo>(\"After-Init\");\r\n\t\tfinal State<Foo> idle = new StateImpl<Foo>(\"Idle\");\r\n\t\tfinal State<Foo> terminated = new StateImpl<Foo>(\"Terminated\", true);\r\n\r\n\t\t// Actions\r\n\t\t//\r\n\t\tAction<Foo> waitForIncomingMessage = new HelloAction(\"Wait-For-Incoming-Message\");\r\n\t\tAction<Foo> terminateTheProgram = new HelloAction(\"Terminate-The-Program\");\r\n\r\n\t\t/* Deterministic Transitions */\r\n\r\n\t\tafterInit.addTransition(ok, idle, waitForIncomingMessage);\r\n\t\tafterInit.addTransition(error, terminated, terminateTheProgram);\r\n\r\n\t\t// In-Memory Persister\r\n\t\t//\r\n\t\tList<State<Foo>> states = new LinkedList<State<Foo>>();\r\n\t\tstates.add(afterInit);\r\n\t\tstates.add(idle);\r\n\t\tstates.add(terminated);\r\n\r\n\t\tMemoryPersisterImpl<Foo> persister = new MemoryPersisterImpl<Foo>(states, afterInit);\r\n```"},"comment":{"url":"https://api.github.com/repos/statefulj/statefulj/issues/comments/91124857","html_url":"https://github.com/statefulj/statefulj/issues/6#issuecomment-91124857","issue_url":"https://api.github.com/repos/statefulj/statefulj/issues/6","id":91124857,"user":{"login":"statefulj","id":8726019,"avatar_url":"https://avatars.githubusercontent.com/u/8726019?v=3","gravatar_id":"","url":"https://api.github.com/users/statefulj","html_url":"https://github.com/statefulj","followers_url":"https://api.github.com/users/statefulj/followers","following_url":"https://api.github.com/users/statefulj/following{/other_user}","gists_url":"https://api.github.com/users/statefulj/gists{/gist_id}","starred_url":"https://api.github.com/users/statefulj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/statefulj/subscriptions","organizations_url":"https://api.github.com/users/statefulj/orgs","repos_url":"https://api.github.com/users/statefulj/repos","events_url":"https://api.github.com/users/statefulj/events{/privacy}","received_events_url":"https://api.github.com/users/statefulj/received_events","type":"User","site_admin":false},"created_at":"2015-04-09T06:11:52Z","updated_at":"2015-04-09T06:11:52Z","body":"You seem to be heading in the right direction - I included an example of building out more of the model:\r\n\r\n  ``` java\r\nfinal State<Foo> dialingFirst = new StateImpl<Foo>(\"Dialing-First\");\r\n\r\n  Action startDialTone = new StartDialToneAction();  // Implements Action\r\n  Action resetDialTone = new ResetDialToneAction();  // Implements Action\r\n  Action waitForIncomingMsg = new WaitForIncomingMsg();  // Implements Action\r\n  Action dialCompositeAction = new CompositeActionImpl(Arrays.asList(new Action[] {\r\n     startDialTone,\r\n     resetDialTone,\r\n     waitForIncomingMsg\r\n  }));\r\n\r\n  idle.addTransition(offhook, dialingFirst, dialCompositeAction);\r\n```\r\n\r\nAfter you're done with defining the states, events, actions and transitions - you just set up your persister (which you have done correctly), then setup your FSM and then call it with foo object.  Like so:\r\n\r\n``` java\r\nfinal FSM<Foo> fsm = new FSM<Foo>(persister);\r\n\r\nFoo foo = new Foo();\r\n\r\nState<Foo> state = fsm.onEvent(foo, ok); // After-Init/Ok -> Idle/waitForIncomingMessage\r\n```\r\n\r\nIf you want to see more examples, checkout:\r\n\r\nhttps://github.com/statefulj/statefulj/blob/master/statefulj-fsm/src/test/java/org/statefulj/fsm/FSMTest.java\r\n\r\n"}}