Contenu connexe Similaire à Basics of Akka Similaire à Basics of Akka (20) Basics of Akka3. Akka
is a toolkit
to build
*concurrent,
並行計算したり
*distributed,
分散処理したり
*fault torerant
耐障害性があるような
apps.
4. concurrent
-> Actors
distributed
-> Remoting
fault torerant
-> Supervision
5. concurrent
アクター
-> Actors
distributed
リモートアクター
-> Remoting
fault torerant
監視
-> Supervision
24. Server1 Server2
Remoting
Ditribute across servers
32. case class Pay(amount: Int)
case class Apple()
class Merchant extends Actor {
var gold: Int = 0
def receive = {
case Pay(amount) if amount >= 50 =>
gold += 50
sender ! Apple()
}
}
33. val system = ActorSystem()
val merchant: ActorRef =
system.actorOf(Props(new Merchant))
36. // Wait for the reply
import concurrent.Await
val result: Apple =
Await.result(future, atMost = 10
seconds)
41. val router: ActorRef =
system.actorOf(
Props[Merchant]
.withRouter(
SmallestMailboxRouter(
nrOfInstances = 10
)
),
name = "merchantRouter"
)
47. “Hi!”
“Hi!”
class EchoActor extends Actor {
def receive = {
case <1> =>
sender ! <2>
}
}
48. “Hi!”
“Hi!”
class EchoActor extends Actor {
def receive = {
case msg =>
sender ! msg
}
}
50. Akka is composed
of many tools:
actor, testkit, remote,
cluster, transactor,
agent, zeromq, camel, ...
Just use what you need