Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@johanandren
Last active April 28, 2017 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johanandren/7d01d19211867df0c308ba5fb1294162 to your computer and use it in GitHub Desktop.
Save johanandren/7d01d19211867df0c308ba5fb1294162 to your computer and use it in GitHub Desktop.
Trying to reproduce a problem with FSM
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