Type-curried creation of Props[A]
to aid the type inference.
Type-curried creation of Props[A]
to aid the type inference.
the message type this actor is receiving
TypedActor base trait that should be extended by to create a typed Actor.
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:
class ExampleActor extends TypeActor.Of[ExampleProtocol] { // ... }
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 to context.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.
// error: match may not be exhaustive. It would fail on the following inputs: None class ExampleActor extends TypedActor { type Message = Option[String] def typedReceive: TypedReceive = Total { case Some("foo") ⇒ } }
If you must go back to untyped land, use the TypedActor#Untyped wrapper.
akka.actor.Actor for more about Actors in general.
Creates a new typed actor as a child of the implicit akka.actor.ActorRefFactory and give it an automatically generated name.
Creates a new typed actor as a child of the implicit akka.actor.ActorRefFactory and give it an automatically generated name.
the message type this actor is receiving
see Props for details on how to obtain a Props
object
the factory to create the actor. Within an actor itself,
this is its context
. For a toplevel actor, you need to
put the ActorSystem
into the implicit scope.
the typed ActorRef[A] for this actor
akka.ConfigurationException
if deployment, dispatcher or
mailbox configuration is wrong
Creates a new typed actor with the given name as a child of the implicit akka.actor.ActorRefFactory.
Creates a new typed actor with the given name as a child of the implicit akka.actor.ActorRefFactory.
the message type this actor is receiving
see Props for details on how to obtain a Props
object
the name of the actor.
must not be null, empty or start with “$”.
If the given name is already in use, an
InvalidActorNameException
is thrown.
the factory to create the actor. Within an actor itself,
this is its context
. For a toplevel actor, you need to
put the ActorSystem
into the implicit scope.
the typed ActorRef[A] for this actor
akka.ConfigurationException
if deployment, dispatcher or
mailbox configuration is wrong
akka.actor.InvalidActorNameException
if the given name is
invalid or already in use
Creates a new typed Props that uses the given akka.actor.Props to create instances of this actor.
Creates a new typed Props that uses the given akka.actor.Props to create instances of this actor.
the message type this actor is receiving
the Props to use
a typed Props to create ActorRef[A]
s for this actor
Creates a new typed Props that uses the given class and constructor arguments to create instances of this actor.
Creates a new typed Props that uses the given class and constructor arguments to create instances of this actor.
Wrapper for akka.actor.Props[T](Class[T], Any*)
.
the message type this actor is receiving
the actor type
the class of this actor
the constructor argumentes of this actor
a typed Props to create ActorRef[A]
s for this actor
Creates a new typed Props that uses the given creator function to create instances of this actor.
Creates a new typed Props that uses the given creator function to create instances of this actor.
CAVEAT: Required mailbox type cannot be detected when using anonymous
mixin composition when creating the instance. For example, the following
will not detect the need for DequeBasedMessageQueueSemantics
as defined
in Stash
:
Props(new Actor with Stash { ... })
Instead you must create a named class that mixin the trait, e.g.
class MyActor extends Actor with Stash
Wrapper for akka.actor.Props[T](=> T)
.
the message type this actor is receiving
the actor type
the thunk that create the new instance of this actor
a typed Props to create ActorRef[A]
s for this actor
Creates a new typed Props that uses the default constructor of the given actor type to create new instances of this actor.
Creates a new typed Props that uses the default constructor of the given actor type to create new instances of this actor.
Wrapper for akka.actor.Props[T]
the message type this actor is receiving
the actor type
a typed Props to create ActorRef[A]
s for this actor
Creates a new typed Props that uses the given class and constructor arguments to create instances of this typed actor.
Creates a new typed Props that uses the given class and constructor arguments to create instances of this typed actor.
The message type is derived from the given actor.
the typed actor
the class of this typed actor
the constructor argumentes of this actor
a typed Props to create ActorRef[A]
s for this actor
Creates a new typed Props that uses the given creator function to create instances of this typed actor.
Creates a new typed Props that uses the given creator function to create instances of this typed actor.
The message type is derived from the given actor.
the typed actor
the thunk that create the new instance of this typed actor
a typed Props to create ActorRef[A]
s for this actor
Props
for some caveat about this constructor.
Creates a new typed Props that uses the default constructor of the given actor to create new instances of this typed actor.
Creates a new typed Props that uses the default constructor of the given actor to create new instances of this typed actor.
The message type is derived from the given actor.
the typed actor
a typed Props to create ActorRef[A]
s for this actor
Type-curried creation of Props[A]
to aid type inference.
Type-curried creation of Props[A]
to aid type inference.
the message type this actor is receiving
a class that created typed Props using one of the above methods
// message gets inferred as Nothing Props(new MyActor): Props[Nothing] // too verbose Props[MyMessage, MyActor](new MyActor): Props[MyMessage] // guided inference PropsOf[MyMessage](new MyActor): Props[MyMessage]
A shapeless-powered, typed variant of the actor/props creation.
A shapeless-powered, typed variant of the actor/props creation.
This is an alternative over constructors, that use the Class[A], Any*
overload to create actors.
You must use TypedActor
s and these actors must be case class
es for
this to work.
Example:
case class ExampleActor(foo: Option[String]) extends TypedActor.Of[String] { def typedReceive: TypedReceive = ??? } // runtime error (IllegalArgumentException: no matching constructor found): val runtimeError: ActorRef[String] = ActorOf(PropsOf[String](classOf[ExampleActor1], "wrong type")) // compiletime error: // found : String("wrong type") :: HNil // required: Option[String] :: HNil val compiletimeError: ActorRef[String] = Typed[ExampleActor2].create("wrong type")
Use apply with the TypedActor
as the type parameter and then call either
create
or props
with the appropriate constructor parameters to create
either an ActorRef or a Props.
Compile-time wrapper for akka.actor.ActorRef to allow for same degree of type-safety on actors without requiring too much changes to the underlying system.
Example: