用道具初始化演员

编程入门 行业动态 更新时间:2024-10-25 04:17:57
本文介绍了用道具初始化演员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下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(); } } }

我像这样初始化演员

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

final Props props = Props.create(ActorOnFsm.class); final ActorRef underTest = system.actorOf(props);

这会产生错误 未知的演员创建​​者[ActorOnFsm]

This gives an error " unknown actor creator [ActorOnFsm] on the line

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

初始化该参与者的正确方法是什么?

Wht is the correct way to initialize this actor?

我还尝试过更改类以扩展AbstractLogging但结果相同

I also tried changing the class to extend AbstractLogging but same result

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

I also tried creating an empty constructor but same result

尝试发送道具中的状态和数据,但仍然收到相同的错误

Tried sending the state and data in the props but still get the same error

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

推荐答案

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

The class that you should pass to the Props factory is ActorFSM, which is defined inside ActorOnFsm:

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

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

However, there may be issues with passing an inner class to the Props factory. It would be more conventional to make ActorFSM a top-level class, in which case the call to Props would change to:

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

此外,您似乎在状态转换之一中有错字:

Also, you appear to have a typo in one of your state transitions:

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

大概是您打算编写 SomeErrorMessage.class 而不是 soemErrorMessage。类。

Presumably, you intended to write SomeErrorMessage.class instead of soemErrorMessage.class.

更多推荐

用道具初始化演员

本文发布于:2023-11-25 12:12:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629700.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初始化   道具   演员

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!