I want to implement advanced communication patterns with akka 2.1. However, akka seems to differ from Scala's actors in a key aspect. Where scala's actors allow me to actively call "receive" and provide a partial function, akka's actors adopt the hollywood "don't call us, we'll call you" principle and let's you only define a receive function statically.
In scala's actors, I could have a pattern like this:
class MyActor extends Actor{
override def act(){
val x = expensiveFunc()
friend ! x
val y = receive {
case Answer(a) => println(a)
}
}
}
Here, I explicitly make calls to receive. The reason for this is that I need autonomous actors that each perform a SPMD program and communicates at specific points in the execution. Is it possible to emulate this pattern using AKKA in a meaningful way?
EDIT I guess it's fair to give complete insight into my problem.
I need to create a SPMD program using actors. This means I need to be able to define behaviour for the actors which is not only reactive i.e. I need to be able to implement act() like in the old scala actors. Furthermore, I need to explicitly call receive(p:PartialFunction[T,U]) like I could do in the old scala actors.
If I can do the above two things, I will be able to port my SPMD program from the old actors to akka actors. I suspect however that it is not possible to implement an act method due to the hollywood-pattern (http://en.wikipedia.org/wiki/Hollywood_principle) that AKKA seems to adopt.
EDIT2 I believe the active receive problem might be solved with become/unbecome as something like this:
import context._
def receive(p:PartialFunction[Any,Unit]){
become(p)
receive()
unbecome()
}
However, this requires that nested calls to receive are allowed. There is a chance that I can emulate the act method by simply sending a message like:
case class Act(b: ()=> Unit) extends Serializable
Which then encapsulates the behaviour I would like my actor to perform.