title: Autonomous AKKA actor calling receive actively
body: <p>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.</p>
  
  <p>In scala's actors, I could have a pattern like this:</p>
  
  <pre><code>class MyActor extends Actor{
  
    override def act(){
      val x = expensiveFunc()
      friend ! x
      val y = receive {
        case Answer(a) =&gt; println(a)
      }
    }
  
  }
  </code></pre>
  
  <p>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? </p>
  
  <hr>
  
  <p><strong>EDIT</strong> 
  I guess it's fair to give complete insight into my problem. </p>
  
  <p>I need to create a SPMD program using actors. This means I need to be able to define behaviour for the actors which is <strong>not</strong> only reactive i.e. I need to be able to implement <strong>act()</strong> like in the old scala actors.
  Furthermore, I need to explicitly call <strong>receive(p:PartialFunction[T,U])</strong> like I could do in the old scala actors.</p>
  
  <p>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 (<a href="http://en.wikipedia.org/wiki/Hollywood_principle" rel="nofollow">http://en.wikipedia.org/wiki/Hollywood_principle</a>) that AKKA seems to adopt.</p>
  
  <p><strong>EDIT2</strong>
  I believe the active receive problem might be solved with become/unbecome as something like this:</p>
  
  <pre><code>  import context._
    def receive(p:PartialFunction[Any,Unit]){
      become(p)
      receive()
      unbecome()
    }
  </code></pre>
  
  <p>However, this requires that nested calls to receive are allowed. There is a chance that I can emulate the <strong>act</strong> method by simply sending a message like:</p>
  
  <pre><code>case class Act(b: ()=&gt; Unit) extends Serializable
  </code></pre>
  
  <p>Which then encapsulates the behaviour I would like my actor to perform.</p>