Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.76 KB | None | 0 0
  1. import akka.actor._
  2. import akka.pattern.ask
  3. import akka.util.Timeout
  4.  
  5. import scala.concurrent.duration.DurationLong
  6.  
  7. object Main {
  8.  
  9.   implicit val timeout: Timeout = 5.seconds
  10.  
  11.   def main(arguments: Array[String]): Unit = {
  12.     val system = ActorSystem()
  13.  
  14.     system.actorOf(Props(classOf[FooActor]), name = "foo")
  15.     system.actorOf(Props(classOf[FooActor], "argument"), name = "bar")
  16.   }
  17.  
  18.   class FooActor(foo: String) extends Actor {
  19.     override def receive: Receive = {
  20.       case BarMessage(bar) if bar % 2 == 0 => sender() ! BarMessage(bar / 2)
  21.       case BarMessage(bar) => sender() ? BarMessage(bar - 1)
  22.     }
  23.   }
  24.  
  25.   object FooActor {
  26.     def props(foo: String): Props = Props(new FooActor(foo))
  27.   }
  28.  
  29.   case class BarMessage(bar: Int)
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement