play.api.libs.concurrent

Members list

Type members

Classlikes

trait ActorModule extends AbstractModule

Facilitates runtime dependency injection of "functional programming"-style actor behaviors.

Facilitates runtime dependency injection of "functional programming"-style actor behaviors.

  1. Mix this trait into the object defining the actor message(s) and behavior(s);
  2. Define the Message type with actor message class;
  3. Annotate with Provides the "create" method that returns the (possibly just initial) Behavior of the actor;
  4. Use the bindTypedActor in AkkaGuiceSupport, passing the object as the actor module.

For example:

 object ConfiguredActor extends ActorModule {
   type Message = GetConfig

   final case class GetConfig(replyTo: ActorRef[String])

   @Provides def apply(configuration: Configuration): Behavior[GetConfig] = {
     // TODO: Define ConfiguredActor's behavior using the injected configuration.
     Behaviors.empty
   }
 }

 final class AppModule extends AbstractModule with AkkaGuiceSupport {
   override def configure() = {
     bindTypedActor(classOf[ConfiguredActor], "configured-actor")
   }
 }

Message is a type member rather than a type parameter is because you can't define, using the example above, GetConfig inside the object and also have the object extend ActorModule[ConfiguredActor.GetConfig].

Attributes

See also
Companion
object
Supertypes
class AbstractModule
trait Module
class Object
trait Matchable
class Any

The companion object to hold ActorModule's ActorModule.Aux type alias.

The companion object to hold ActorModule's ActorModule.Aux type alias.

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type

Support for binding actors with Guice.

Support for binding actors with Guice.

Mix this trait in with a Guice AbstractModule to get convenient support for binding actors. For example:

 class MyModule extends AbstractModule with AkkaGuiceSupport {
   def configure = {
     bindActor[MyActor]("myActor")
     bindTypedActor(HelloActor(), "hello-actor")
   }
 }

Then to use the above actor in your application, add a qualified injected dependency, like so:

 class MyController @Inject() (
     @Named("myActor") myActor: ActorRef,
     helloActor: ActorRef[HelloActor.SayHello],
     val controllerComponents: ControllerComponents,
 ) extends BaseController {
   ...
 }

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
AbstractModule
@Singleton @ApiMayChange
final class TypedActorRefProvider[T](val name: String)(implicit evidence$1: ClassTag[T]) extends Provider[ActorRef[T]]

A singleton Provider of the typed ActorRef[T] resulting from spawning an actor with the Behavior[T] in dependency scope and the given name, in the ActorSystem in dependency scope.

A singleton Provider of the typed ActorRef[T] resulting from spawning an actor with the Behavior[T] in dependency scope and the given name, in the ActorSystem in dependency scope.

Type parameters

T

The class of the messages the typed actor can handle.

Value parameters

name

the name to use when spawning the typed actor.

Attributes

Supertypes
trait Provider[ActorRef[T]]
trait Provider[ActorRef[T]]
class Object
trait Matchable
class Any