Hi,
Will showed me today at Devoxx that there's the pipeTo mechanism to do
blocking code in actors at a different thread, so the actor stays non
blocking. The code I came up looks like this. It would be very nice if you
could take a look and tell me if I'm doing something obviously wrong:
object MyActor {
def props = Props[MyActor]
case class InputMessage()
case class MyActorResult(data)
}
class HeartbeatProcessingActor extends Actor {
lazy val otherActor1: ActorRef =
context.system.actorOf(otherActor1.props, "process-events1")
lazy val otherActor2: ActorRef =
context.system.actorOf(otherActor2.props, "process-events2")
lazy val otherActor3: ActorRef =
context.system.actorOf(otherActor3.props, "process-events3")
override def receive = {
case x : MyActorResult =>
otherActor1 ! x
otherActor2 ! x
otherActor3 ! x
case x: InputMessage => {
val primaryDBExecutionContext: ExecutionContext =
context.system.dispatchers.lookup("akka.actor.primary-db-execution-context")
import akka.pattern.pipe
import play.api.Play.current // I need this somehow for
DB.withTransaction
val f = new PipeableFuture(Future {
val immutableSerialMap: Map[String, Long] = DB.withTransaction({
implicit conn =>
// do some blocking JDBC IO and fetch results
immutableSerialMap
})
// TODO specify return value of future that gets piped to
myself
MyActorResult(immutableSerialMap)
}
(primaryDBExecutionContext))
(primaryDBExecutionContext)
.pipeTo(context.self)
}
}
}
Questions:
1. Is this code correct in respect to not blocking the akka-thread-pool ?
2. the wrapping of Future with PipeableFuture looks strange.. is this
correct
3. passing the _same_ explicit execution context to both the inner future
as well as the PipeableFuture looks strange.. is this correct?
4. I know, its a Play-thing, but do you see any problem with the "import
play.api.Play.current" ?
Thanks,
Dominik
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.