StateTimeout not working with Akka FSM in java


#1

I am trying to build an Akka actor FSM in java that times out after a certain time if it remains in the Idle state. I am using this (https://doc.akka.io/docs/akka/2.5/fsm.html) as a reference. Below is the sample code that I am using

public class TestActorFSM extends AbstractLoggingFSM<State, Data> {
{
    startWith(Idle, Uninitialized);

    when(Idle, Duration.create(10, SECONDS),
        matchEventEquals(StateTimeout(), Todo.class,
            (event, todo) -> {
                log().info("Timeout received");
                return goTo(Expired);
            }));

    initialize();
}

Actor is instantiated in Idle state and if it stays in that state for 10 seconds it should go to expired state. After 10 seconds, I do receive an event but it wouldn’t go into the handler and throws a warning with below message. “unhandled event StateTimeout in state Idle”

Can anyone please explain, what am i doing wrong here?


(Johan Andrén) #2

The second parameter to matchEventEquals is matched against the current state, which means the Uninitialized instance would have to be an instance of Todo for that match to succeed, I’m guessing it isn’t.