Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import akka.actor.{ ActorRef, ActorSystem, Props, Actor, Inbox }
- class HotSwapActor extends Actor {
- import context._
- def one: PartialFunction[Any, Unit] = {
- case "foo" => sender ! "I am One!"; become(two)
- }
- def two: PartialFunction[Any, Unit] = {
- case "foo" => sender ! "I am Two"; become(three)
- }
- def three: PartialFunction[Any, Unit] = {
- case "foo" => sender ! "I am Three"; unbecome
- }
- def receive = {
- case "foo" => sender ! "I am recieve and becomes one"; become(one)
- case "bar" => sender ! "I am recieve";
- }
- }
- class OtherActor extends Actor {
- val system = ActorSystem()
- val actor = system.actorOf(Props[HotSwapActor])
- def receive = {
- case "start" =>
- actor ! "foo" //nop
- actor ! "foo" //one
- actor ! "foo" //two
- actor ! "foo" //three
- actor ! "foo"
- case a @ _ => println(a)
- }
- }
- object HotSwapMain extends App {
- val system = ActorSystem()
- val actor = system.actorOf(Props[OtherActor])
- actor ! "start"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement