Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import akka.actor._
- // import akka.actor.Actor
- // import akka.actor.ActorSystem
- // import akka.actor.Props
- // 1. >
- class Player(msg: String) extends Actor {
- var max = 4
- def receive = {
- case (from: ActorRef) => {
- if (max > 0) {
- max -= 1
- println(msg)
- from ! self
- } else {
- context.stop(self) //zakończenie działania aktora, nie kończy działania systemu Akka
- context.system.terminate //wyłączłem, żeby drugie zad. działało
- }
- }
- }
- }
- // < 1.
- object Main {
- def main(args: Array[String]) {
- // ActorSystem is a heavy object: create only one per application
- val ourSystem = ActorSystem("MySystem")
- // 1. >
- // val ping = ourSystem.actorOf(Props[classOf[Player], "ping"))
- // val pong = ourSystem.actorOf(Props[classOf[Player], "pong")) //poleceany na wykładzie, ale ma ograniczenia i nie działa
- val ping = ourSystem.actorOf(Props(new Player("PING")))
- val pong = ourSystem.actorOf(Props(new Player("pong")))
- ping ! pong
- // < 1.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement