用道具初始化演员 [英] Initializing actor with Props

查看:122
本文介绍了用道具初始化演员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下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 <中定义/ code>:

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.

这篇关于用道具初始化演员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆