Created
March 6, 2014 03:06
-
-
Save f81/9381499 to your computer and use it in GitHub Desktop.
第20章:Scalaでアクター! ref: http://qiita.com/f81@github/items/55b83d7f4104b1a4dfac
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.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!!") | |
} | |
} |
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
$ git clone https://github.com/f81/actor_sample.git |
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
actor_sample $ tree | |
. | |
├── LICENSE | |
├── README.md | |
├── build | |
├── build.gradle | |
└── src | |
├── main | |
│ ├── resources | |
│ └── scala | |
│ └── ActorSample.scala | |
└── test | |
├── resources | |
└── scala |
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
$ 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 |
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
router ! "Hello" |
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
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