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

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

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

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

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

  1. 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
  2. at akka.dispatch.Mailboxes$$anonfun$1.applyOrElse(Mailboxes.scala:197)
  3. at akka.dispatch.Mailboxes$$anonfun$1.applyOrElse(Mailboxes.scala:195)
  4. at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:33)
  5. at scala.util.Failure$$anonfun$recover$1.apply(Try.scala:185)
  6. at scala.util.Try$.apply(Try.scala:161)
  7. at scala.util.Failure.recover(Try.scala:185)
  8. at akka.dispatch.Mailboxes.lookupConfigurator(Mailboxes.scala:195)
  9. at akka.dispatch.Mailboxes.lookup(Mailboxes.scala:78)
  10. at akka.dispatch.Mailboxes.getMailboxType(Mailboxes.scala:154)
  11. at akka.actor.LocalActorRefProvider.actorOf(ActorRefProvider.scala:717)
  12. ... 10 more

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

8ljdwjyq

8ljdwjyq1#

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

我觉得你的剧本应该改成

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

相关问题