Defines the actors behavior.
Defines the actors behavior. Unlike akka.actor.Actor#receive, this one is typed in its first parameter.
Wraps a total receiver function and returns it as a TypedReceive.
Wraps a total receiver function and returns it as a TypedReceive. Use this to get exhaustiveness checking for your receive block.
// error: match may not be exhaustive. It would fail on the following inputs: None class ExampleActor extends TypedActor.Of[Option[String]] { def typedReceive: TypedReceive = Total { case Some("foo") ⇒ } }
Builds final receive out of sub-receives if this TypedActor is for a Union message type.
Builds final receive out of sub-receives if this TypedActor is for a Union message type. This mirrors a Total receive, i.e. you must provide all cases.
class ExampleActor extends TypedActor.Of[Foo | Bar | Baz] { def typedReceive: TypedReceive = TotalUnion .on[Foo]{ case Foo() => println("foo") } .on[Bar]{ case Bar() => println("bar") } .on[Bax]{ case Bax() => println("bax") } .apply } }
Builds final receive out of sub-receives if this TypedActor is for a Union message type.
Builds final receive out of sub-receives if this TypedActor is for a Union message type. This mirrors a TypedReceive, i.e. you must not cover all cases.
class ExampleActor extends TypedActor.Of[Foo | Bar | Baz] { def typedReceive: TypedReceive = Union .on[Foo]{ case Foo() => println("foo") } .on[Bar]{ case Bar() => println("bar") } .apply } }
Wraps an untyped receiver and returns it as a TypedReceive.
Wraps an untyped receiver and returns it as a TypedReceive. Use this to match for messages that are outside of your protocol, e.g. akka.actor.Terminated.
class ExampleActor extends TypedActor.Of[ExampleMessage] { def typedReceive: TypedReceive = Untyped { case Terminated(ref) => println(s"$$ref terminated") } }
TypedActor
s delegate to typedReceive.
TypedActor
s delegate to typedReceive.
Typed variant of context.become
.
Typed variant of self.
context.become
for a given subtype if this actor is of a union type.
Wraps a typed receive and returns it as an untyped receive.
Wraps a typed receive and returns it as an untyped receive. Use this only if you have to mix with other traits that override receive, where you need to repeat the implementation of this typed actors default receive method.
TypedActor base trait that should be extended by to create a typed Actor. This actor is designed to only receive one type of message in its lifetime. Typically, this is some ADT/sealed trait that defines the protocol for this actor.
The message type is defined by extending TypedActor.Of:
The
TypedActor
is just a regular actor, but if offers some methods that help you stay within the defined typed contract. TypedActor#typedSelf is the alternative to akka.actor.Actor.self to get the typed ActorRef for this actor. TypedActor#typedBecome is the alternative tocontext.become
to check the receiving type while changing behavior. You can get exhausitveness checking for your receive block if you use TypedActor#Total as a wrapper around your receive block.If you must go back to untyped land, use the TypedActor#Untyped wrapper.
akka.actor.Actor for more about Actors in general.