gpt4 book ai didi

java - 使用 Props 初始化 actor

转载 作者:行者123 更新时间:2023-12-02 11:28:49 24 4
gpt4 key购买 nike

我有以下 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

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

这会产生错误“未知的 Actor 创建​​者[ActorOnFsm]上线了

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

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

我也尝试更改类来扩展 AbstractLogging 但结果相同

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

尝试在 Prop 中发送状态和数据,但仍然得到相同的错误

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

最佳答案

您应该传递给 Props 工厂的类是 ActorFSM,它在 ActorOnFsm 中定义:

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

但是,将内部类传递给 Props 工厂可能会出现问题。将 ActorFSM 设为顶级类更为传统,在这种情况下,对 Props 的调用将更改为:

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

此外,您的状态转换之一似乎存在拼写错误:

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

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

关于java - 使用 Props 初始化 actor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49425464/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com