Skip to content

Instantly share code, notes, and snippets.

@f81
Created March 6, 2014 03:06
Show Gist options
  • Save f81/9381499 to your computer and use it in GitHub Desktop.
Save f81/9381499 to your computer and use it in GitHub Desktop.
第20章:Scalaでアクター! ref: http://qiita.com/f81@github/items/55b83d7f4104b1a4dfac
import akka.actor.ActorSystem
import akka.actor.Props
import akka.actor.Actor
import akka.routing.RoundRobinRouter
object ActorSample {
def main(args: Array[String]): Unit = {
val system = ActorSystem("helloSystem")
val router = system.actorOf(Props[HelloActor].withRouter(RoundRobinRouter(4)))
router ! "Hello"
system.shutdown
}
}
class HelloActor extends Actor {
def receive = {
case "Hello" => println("Hello World!!")
case _ => println("Bad World!!")
}
}
$ git clone https://github.com/f81/actor_sample.git
actor_sample $ tree
.
├── LICENSE
├── README.md
├── build
├── build.gradle
└── src
├── main
│ ├── resources
│ └── scala
│ └── ActorSample.scala
└── test
├── resources
└── scala
$ cd actor_sample
$ gradle run
:compileJava UP-TO-DATE
:compileScala
:processResources UP-TO-DATE
:classes
:run
Hello World!!
BUILD SUCCESSFUL
Total time: 11.639 secs
router ! "Hello"
val system = ActorSystem("helloSystem")
val router = system.actorOf(Props[HelloActor].withRouter(RoundRobinRouter(4)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment