casualjim
1/3/2012 - 9:24 AM

gistfile1.scala

package testing

import akka.actor._

object Main {

  def main(args: Array[String]) {  

    val sys1 = ActorSystem("first")
    val sys2 = ActorSystem("second")

    sys1.actorOf(Props(new Actor {
      def receive = {
        case m => {
          println("The first actor received")
          println(m)
          println("from: %s".format(sender))
          sender ! ('reply, m)
        }
      }
    }), "tester")

    sys2.actorOf(Props(new Actor {
      def receive = {
        case 'send => {
          println("Sending a message")
          val a = context.system.actorFor("akka://first/user/tester") 
          println("to: %s".format(a))
          a ! "The message"
        }
        case ('reply, m) => {
          println("The second actor received")
          println(m)
          sys1.shutdown
          sys2.shutdown
        }
      }
    }), "tester") 

    println("using sys1")
    sys1.actorFor("akka://first/user/tester") ! "A message using sys1"

    println("using sys2")
    sys2.actorFor("akka://first/user/tester") ! "A message using sys2"

    println("using the actor")
    sys2.actorFor("/user/tester") ! 'send
     
  }
}