AKKA:无法使用自定义邮箱配置定义Actor

disbfnqx  于 2023-10-18  发布在  其他
关注(0)|答案(1)|浏览(177)

我是新的akka,并试图做以下简单的例子:

public static void main(String[] args){
        Config cf = ConfigFactory.parseString(" bounded-mailbox {\n"
            + "  mailbox-type = \"akka.dispatch.NonBlockingBoundedMailbox\"\n"
            + "  mailbox-capacity = 1000\n"
            + "}");
        ActorSystem system = ActorSystem.create("MySystem", cf); ActorRef                  
        myActor = system.actorOf(Props.create(MyActor.class).withMailbox("bounded-mailbox"), "myactor");
        for(int index = 0; index<=100; index++) {
            myActor.tell(index, myActor.noSender());
        }
        try {
            Thread.sleep(120000);
        }catch (Exception exc){}
   }

MyActor.class -是一个简单的actor类,用于打印接收到的消息。
当我运行这个时,我得到以下错误:

Caused by: java.lang.IllegalArgumentException: Cannot instantiate MailboxType [akka.dispatch.NonBlockingBoundedMailbox], defined in [bounded-mailbox], make sure it has a public constructor with [akka.actor.ActorSystem.Settings, com.typesafe.config.Config] parameters
    at akka.dispatch.Mailboxes$$anonfun$1.applyOrElse(Mailboxes.scala:197)
    at akka.dispatch.Mailboxes$$anonfun$1.applyOrElse(Mailboxes.scala:195)
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:33)
    at scala.util.Failure$$anonfun$recover$1.apply(Try.scala:185)
    at scala.util.Try$.apply(Try.scala:161)
    at scala.util.Failure.recover(Try.scala:185)
    at akka.dispatch.Mailboxes.lookupConfigurator(Mailboxes.scala:195)
    at akka.dispatch.Mailboxes.lookup(Mailboxes.scala:78)
    at akka.dispatch.Mailboxes.getMailboxType(Mailboxes.scala:154)
    at akka.actor.LocalActorRefProvider.actorOf(ActorRefProvider.scala:717)
    ... 10 more

有什么想法吗?我正在运行与akka-actor_2.10 -2.3.7

8ljdwjyq

8ljdwjyq1#

mailbox-type = \"akka.dispatch.NonBlockingBoundedMailbox\"\n"

我觉得你的剧本应该改成

mailbox-type = "your.package.name.the mailbox'class  name"

相关问题