Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import akka.actor._
- import akka.pattern.ask
- import akka.util.Timeout
- import scala.concurrent.duration.DurationLong
- object Main {
- implicit val timeout: Timeout = 5.seconds
- def main(arguments: Array[String]): Unit = {
- val system = ActorSystem()
- system.actorOf(Props(classOf[FooActor]), name = "foo")
- system.actorOf(Props(classOf[FooActor], "argument"), name = "bar")
- }
- class FooActor(foo: String) extends Actor {
- override def receive: Receive = {
- case BarMessage(bar) if bar % 2 == 0 => sender() ! BarMessage(bar / 2)
- case BarMessage(bar) => sender() ? BarMessage(bar - 1)
- }
- }
- object FooActor {
- def props(foo: String): Props = Props(new FooActor(foo))
- }
- case class BarMessage(bar: Int)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement