EDIT: Exception relating to serialising / deserialising Akka Actor remains after forEach is confirmed to be executing. I'm learning Akka and encountering this serialisation issue, I'm quite new to Akka and finding it quite difficult to figure out how best to approach a solution.
I have a class where the actorSystem and actor is created, that class calls a method in another class, I'd like to use my actor in that other class. So far I've tried:
Class a:
-create actor
-classB.methodX(actor)
Class b:
-methodX(actorRef)
--actorRef! message
currently the message from class b does not get sent whereas the class A ones do, this is making me think that I either need to instantiate a new Actor with the ActorRef that I'm passing in or, it's completely wrong.
I understand that the system needs to be present on all nodes but I'm unsure how to do that.
Edit: Code Snippets:
ClassA:
private val system = ActorSystem("System")
private val metricActor= system.actorOf(Props(new MetricActor("metrics")), name = "metrics")
metricActor ! message works fine
writeFiles(metricActor) //writeFiles is in another class
writeFiles(actor: ActorRef) {
f.forEach(v => {
actor ! message // this doesn't seem to work
})
}
Edited to provide more code.
full example of classB as it were
def writeFiles(bucket: String, filesToWrite: RDD[(String, String)], actor:ActorRef): Unit =
filesToWrite.foreachPartition(f => {
f.foreach(v => {
try {
//actor ! ProcessSingleItem(MetricItem("File Created"))
logger.debug(s"Writing file:")
writeFile()
}
catch {
case e: Exception =>
//actor ! ProcessSingleItem(CloudWatchMetricItem("File create failure"))
logger.error("Error creating file", e)
}
})
})