Skip to content

Instantly share code, notes, and snippets.

@dwijnand
Created January 29, 2015 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwijnand/e11ced199f689f3950cd to your computer and use it in GitHub Desktop.
Save dwijnand/e11ced199f689f3950cd to your computer and use it in GitHub Desktop.
import akka.actor.{ Actor, ActorRef, ActorSystem, Props }
import scala.reflect.ClassTag
object CrossActorSystemMessageTest {
def main(args: Array[String]): Unit = {
val fooActorSystem = ActorSystem("foo")
val barActorSystem = ActorSystem("bar")
val foo = fooActorSystem.mkActor("fooActor", new Foo)
val bar = barActorSystem.mkActor("barActor", new Bar(foo))
bar ! ()
fooActorSystem.awaitTermination()
barActorSystem.awaitTermination()
fooActorSystem.shutdown()
barActorSystem.shutdown()
}
class Foo extends Actor {
def receive = {
case "Hi Foo" => println("FUCKING SUCCESS!!")
}
}
class Bar(foo: ActorRef) extends Actor {
def receive = {
case () => foo ! "Hi Foo"
}
}
implicit class ActorSystemW(val actorSystem: ActorSystem) extends AnyVal {
def mkActor[T <: Actor: ClassTag](name: String, creator: => T): ActorRef = actorSystem.actorOf(Props(creator), name)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment