Created
January 29, 2015 17:23
-
-
Save dwijnand/e11ced199f689f3950cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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