使用 Props 初始化 actor

Initializing actor with Props

我有以下 FSM

public class ActorOnFsm {
    public static enum State {
    FirstState,
    SecondState,
    ThirdState,
    FourthState
    }

    public static final class ServiceData {

    }


    public class ActorFSM extends AbstractFSM<State, ServiceData> { 
    {
        startWith(FirstState, new ServiceData());
        when(FirstState,
            matchEvent(SomeMessage.class,
                ServiceData.class,
                (powerOn, noData) ->
            goTo(SecondState)
            .replying(SecondState))
            );


        when(SecondState,
            matchEvent(SomeOtherMessage.class,
                ServiceData.class,
                (powerOn, noData) ->
            goTo(ThirdState)
            .replying(ThirdState))
            );

        when(FirstState,
            matchEvent(soemErrorMessage.class,
                ServiceData.class,
                (powerOn, noData) ->
            goTo(FourthState)
            .replying(FourthState))
            );

        initialize();
    }



    }
}

我这样初始化actor

final Props 道具 = Props.create(ActorOnFsm.class); 最终 ActorRef underTest = system.actorOf(props);

这给出了一个错误“unknown actor creator [ActorOnFsm] 线上

final Props props = Props.create(ActorOnFsm.class);

初始化这个 actor 的正确方法是什么?

我也尝试更改 class 以扩展 AbstractLogging 但结果相同

我也试过创建一个空的构造函数,但结果相同

尝试在 props 中发送状态和数据,但仍然出现相同的错误

    final Props props = Props.create(DeployerOnFsm.class, state, data);

你应该传递给Props工厂的class是ActorFSM,它在ActorOnFsm:

中定义
final Props props = Props.create(ActorOnFsm.ActorFSM.class);

但是,将内部 class 传递给 Props 工厂可能会出现问题。将 ActorFSM 设为 top-level class 更为常规,在这种情况下,对 Props 的调用将更改为:

final Props props = Props.create(ActorFSM.class);

此外,您的状态转换中似乎有错别字:

when(FirstState,
    matchEvent(soemErrorMessage.class,
              // ^

据推测,您打算写 SomeErrorMessage.class 而不是 soemErrorMessage.class