15. Instance A Instance B
2.call B’s method
Actorでないとき
1.call A’s method1
3.return value
Main
4.call A’s method2
ごめん、めっちゃ時
間かかってるじゃあ待つわ
method2の処理は?
すいません、まだBからレ
スポンス返ってこなく
て・・
Instance Bの遅延が全体に波及して
いる
16. Actor A Actor B
2.send message
Actorであるとき
1.send message1
3.send back response
Main
4.send message2
ごめん、めっちゃ時
間かかってる知らん
message2の処理は?
message1の処理終わった
んで、すぐやります!
Actor Bの遅延をActor B内に閉じ込めている。
(“4 send message2” の処理の影響がでない)
これはまあFutureでも解決できる
17. Instance A Instance B
2.call B’s method
Actorでないとき
1.call A’s method1
3.return value
Main
4.call A’s method2
エラー出たので死に
ます・・
その影響で俺
も・・
じゃあ俺も・・
Instance Bの遅延が全体に波及して
いる
18. Actor A Actor B
2.send message
Actorであるとき
1.send message1
3.send back response
Main
4.send message2
エラー出たので死に
ます!知らん
message2の処理は?
message1の処理終わった
んで、すぐやります!
Actor Bでの障害をActor B内に閉じ込
めれる (4の処理に影響が出ない)
Actor Bに親アクターがいるとき、親
アクターがクラッシュ時の挙動を決
定できる (Let it crashの16ページ目か
ら)
ActorLogging, ScalaLogging
などで、どのアクターでどん
なエラーが出たのかは記録で
きる 詳細
20. Instance A
Instance E
1. call E’s update method
Actorでないとき
Instance B DB
2. update by A’s request
1.call E’s update method
Instance C
1.call E’s update method
2. update by B’s request
2. update by C’s request
そんないっぺんにいっぱい来られて
も無理。
21. Actor A
Actor E
1. send update message
Actorであるとき
Actor B DB
2. update by A’s message
1.send update message
Actor C
1.send update message
3. update by B’s message
4. update by C’s message
一つずつくるから、負荷も安心
※デッドロックの心配もなし
Actor間は非同期なので、Actor Eにメ
ッセージが溜まっても他のActorには
関係なし
UnboundedPriorityMailboxを使用する
ことでメッセージの優先度も設定可
能 詳細
25. RemoteActor
IP: 192.168.33.20
val system = ActorSystem(“my-system”)
val actor = system.actorOf(Props[MyActor], “my-
actor”)
application.conf
{
/*他の設定も本当は書く*/
remote {
hostname = “192.168.33.20”
port = 2552
}
}
IP: 192.168.33.21
val system = ActorSystem(“my-system”)
val path = “akka.tcp://my-
system@192.168.33.20:2552/user/my-actor”
//ActorSystem名、host, port, Actor名でActorの
ユニークなアドレスを指定
val actor = system.actorSelection(path)
//↑ で別サーバーにあるMyActorの参照を得た。
actor ! “message”
//↑ で別サーバーにあるMyActorにメッセージを
投げている。