Last active
April 28, 2017 16:00
-
-
Save johanandren/7d01d19211867df0c308ba5fb1294162 to your computer and use it in GitHub Desktop.
Trying to reproduce a problem with FSM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.actor.*; | |
public class FSMTestActor extends AbstractFSM<String, String> { | |
public final static String A = "A"; | |
static class Event { | |
public final int n; | |
public Event(int n) { | |
this.n = n; | |
} | |
} | |
{ | |
when(A, | |
matchEvent( | |
Event.class, | |
(event, state) -> event.n == 1, | |
(event, state) -> { | |
System.out.println("matchEvent, with event.n = 1"); | |
return stay(); | |
}).event( | |
Event.class, | |
(event, state) -> event.n == 2, | |
(event, state) -> { | |
System.out.println("event with predicate, with event.n = " + event.n); | |
return stay(); | |
} | |
).event( | |
Event.class, | |
(event, state) -> { | |
System.out.println("event without predicate, with event.n = " + event.n); | |
return stay(); | |
} | |
) | |
); | |
startWith(A, "state"); | |
} | |
public static void main(String[] args) { | |
ActorSystem system = ActorSystem.create(); | |
ActorRef ref = system.actorOf(Props.create(FSMTestActor.class)); | |
ref.tell(new Event(1), ActorRef.noSender()); | |
ref.tell(new Event(2), ActorRef.noSender()); | |
ref.tell(new Event(3), ActorRef.noSender()); | |
ref.tell(new Event(4), ActorRef.noSender()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment