https://github.com/jokester/wa-akka-typed-actor-demo
https://github.com/jokester/wa-akka-typed-actor-demo
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/jokester/wa-akka-typed-actor-demo
- Owner: jokester
- Created: 2020-01-15T05:04:36.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-15T05:05:02.000Z (over 5 years ago)
- Last Synced: 2025-03-23T23:41:26.879Z (about 2 months ago)
- Language: Scala
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# wa-typed-actor-demo
## Reading
### what is an actor?
https://doc.akka.io/docs/akka/current/general/actors.html
### akka actor (scala API)
- `Behavior[T]`
- `ActorRef[T]`
- `ActorSystem[T]`T: メッセージタイプ。ActorSystemにおいて、Tは「ルートActorのメッセージタイプ」
## First Example
https://doc.akka.io/docs/akka/current/typed/actors.html#first-example
- HelloWorldMain
- HelloWorld
- HelloWorldActor## A More Complicated Example
- https://doc.akka.io/docs/akka/current/typed/actors.html#a-more-complex-example
## Compared to akka-(nontyped)-actor
### Actor definition
```
class SomeActor(props) extends akka.actor.Actor {
override def receive(message: Any): Unit = {
...
}
}=>
abstract class akka.typed.Behavior[T]
1. "functional style"
constructed by Behaviors.* (
2. "OOP style"
class SomeBehavior(context: ActorContext[T]) extends AbstractBehavior[T](context) {
def onMessage(message: T): Behavior[T] = {
???
}
}
``````
type Actor.Receive = PartialFunction[Any, Unit]context.become(nextReceive: Receive)
=>
return a different Behavior[T] object
```### Actor creation
```
akka.actor.ActorContext#actorOf(props): akka.ActorRef=>
TypedActorContext#spawn(behavior: Behavior[T]): akka.typed.ActorRef[T]
```### ActorSystem
```
akka.ActorSystem(): akka.ActorSystem=>
akka.typed.ActorSystem(behavior: Behavior[T]): akka.typed.ActorSystem[T]
- explicit root actor
- `class typed.ActorSystem[T] extends typed.ActorRef[T]`
```