在 class Actors.FileObserverActor 上找不到参数的匹配构造函数
No matching constructor found on class Actors.FileObserverActor for arguments
我正在尝试在 play frmework 中使用 akka actors 来实现 websocket。
HomeController.scala
def socket = WebSocket.accept[String, String] { request =>
ActorFlow.actorRef(out => FileObserverActor.props(out))
}
Actors/FileUploaderActor.scala
class FileUploaderActor extends Actor{
override def receive: Receive = {
case UploadFile(billerId, filename, subCategory, count, dueDate) =>
val fileOberverActor = ActorSystem().actorOf(Props[FileObserverActor])
val billerData = BillerFileUploadMetaData(billerId,filename,count,"ACTIVE",
new java.sql.Timestamp(new java.util.Date().getTime),subCategory,dueDate)
val sparkSession = SparkContextHelper.sparkSession;
import sparkSession.implicits._
val rdd = sparkSession.sparkContext.parallelize(Seq(billerData))
val df = rdd.toDF()
df.write.format("org.apache.spark.sql.cassandra").options(Map("keyspace" -> "billerplatform_schema", "table" -> "biller_file_uploads")).mode(SaveMode.Append).save
fileOberverActor ! FileUploaded(filename, count)
}
}
Actors/FileObserverActor.scala
class FileObserverActor(out: ActorRef) extends Actor{
def receive = {
case FileUploaded(fileName, totalRecords) =>
out ! ("Got the file " + fileName)
}
}
object FileObserverActor{
def props(out: ActorRef) = Props(new FileObserverActor(out))
}
获取跟踪:
java.lang.IllegalArgumentException: no matching constructor found on class Actors.FileObserverActor for arguments []
at akka.util.Reflect$.error(Reflect.scala:81)
at akka.util.Reflect$.findConstructor(Reflect.scala:105)
at akka.actor.NoArgsReflectConstructor.<init>(IndirectActorProducer.scala:103)
at akka.actor.IndirectActorProducer$.apply(IndirectActorProducer.scala:60)
at akka.actor.Props.producer(Props.scala:131)
at akka.actor.Props.<init>(Props.scala:144)
at akka.actor.Props$.apply(Props.scala:86)
at Actors.FileUploaderActor$$anonfun$receive.applyOrElse(FileUploaderActor.scala:15)
at akka.actor.Actor$class.aroundReceive(Actor.scala:497)
at Actors.FileUploaderActor.aroundReceive(FileUploaderActor.scala:10)
这是在 FileUploaderActor 中创建 actor 实例的问题吗?你能帮我调试这个问题吗?
编辑:
我为 "FileObserverActor" 创建了一个伴随对象,因为它需要通过 websocket 在控制器和 FileObserverActor 之间建立连接,
def socket = WebSocket.accept[String, String] { request =>
ActorFlow.actorRef(out => FileObserverActor.props(out))
}
现在我还想从 "FileUploadActor" 向 "FileObserverActor" 发送消息,但是我无法从 "FileUploadActor" 创建实例,因为 "FileObserverActor" 是用 [=38 参数化的=] 用于 websocket 连接。现在如何从 "FileUploadActor" 向 "FileObserverActor" 发送消息?
正如错误消息所指出的那样,它期待 FileObserverActor
的无参数构造函数,但未找到。鉴于您在创建 FileObserverActor
时需要 out: ActorRef
,请考虑在创建它时传递引用。
违规行在 Actors/FileUploaderActor.scala
val fileOberverActor = ActorSystem().actorOf(Props[FileObserverActor])
您可能想将其更改为
val fileOberverActor = ActorSystem().actorOf(FileObserverActor.props(outActorRef))
有关更多信息,请查看 Akka 中有关 Props 的官方文档。
我正在尝试在 play frmework 中使用 akka actors 来实现 websocket。
HomeController.scala
def socket = WebSocket.accept[String, String] { request =>
ActorFlow.actorRef(out => FileObserverActor.props(out))
}
Actors/FileUploaderActor.scala
class FileUploaderActor extends Actor{
override def receive: Receive = {
case UploadFile(billerId, filename, subCategory, count, dueDate) =>
val fileOberverActor = ActorSystem().actorOf(Props[FileObserverActor])
val billerData = BillerFileUploadMetaData(billerId,filename,count,"ACTIVE",
new java.sql.Timestamp(new java.util.Date().getTime),subCategory,dueDate)
val sparkSession = SparkContextHelper.sparkSession;
import sparkSession.implicits._
val rdd = sparkSession.sparkContext.parallelize(Seq(billerData))
val df = rdd.toDF()
df.write.format("org.apache.spark.sql.cassandra").options(Map("keyspace" -> "billerplatform_schema", "table" -> "biller_file_uploads")).mode(SaveMode.Append).save
fileOberverActor ! FileUploaded(filename, count)
}
}
Actors/FileObserverActor.scala
class FileObserverActor(out: ActorRef) extends Actor{
def receive = {
case FileUploaded(fileName, totalRecords) =>
out ! ("Got the file " + fileName)
}
}
object FileObserverActor{
def props(out: ActorRef) = Props(new FileObserverActor(out))
}
获取跟踪:
java.lang.IllegalArgumentException: no matching constructor found on class Actors.FileObserverActor for arguments []
at akka.util.Reflect$.error(Reflect.scala:81)
at akka.util.Reflect$.findConstructor(Reflect.scala:105)
at akka.actor.NoArgsReflectConstructor.<init>(IndirectActorProducer.scala:103)
at akka.actor.IndirectActorProducer$.apply(IndirectActorProducer.scala:60)
at akka.actor.Props.producer(Props.scala:131)
at akka.actor.Props.<init>(Props.scala:144)
at akka.actor.Props$.apply(Props.scala:86)
at Actors.FileUploaderActor$$anonfun$receive.applyOrElse(FileUploaderActor.scala:15)
at akka.actor.Actor$class.aroundReceive(Actor.scala:497)
at Actors.FileUploaderActor.aroundReceive(FileUploaderActor.scala:10)
这是在 FileUploaderActor 中创建 actor 实例的问题吗?你能帮我调试这个问题吗?
编辑: 我为 "FileObserverActor" 创建了一个伴随对象,因为它需要通过 websocket 在控制器和 FileObserverActor 之间建立连接,
def socket = WebSocket.accept[String, String] { request =>
ActorFlow.actorRef(out => FileObserverActor.props(out))
}
现在我还想从 "FileUploadActor" 向 "FileObserverActor" 发送消息,但是我无法从 "FileUploadActor" 创建实例,因为 "FileObserverActor" 是用 [=38 参数化的=] 用于 websocket 连接。现在如何从 "FileUploadActor" 向 "FileObserverActor" 发送消息?
正如错误消息所指出的那样,它期待 FileObserverActor
的无参数构造函数,但未找到。鉴于您在创建 FileObserverActor
时需要 out: ActorRef
,请考虑在创建它时传递引用。
违规行在 Actors/FileUploaderActor.scala
val fileOberverActor = ActorSystem().actorOf(Props[FileObserverActor])
您可能想将其更改为
val fileOberverActor = ActorSystem().actorOf(FileObserverActor.props(outActorRef))
有关更多信息,请查看 Akka 中有关 Props 的官方文档。