package concurrent
- Alphabetic
- Public
- Protected
Type Members
- 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
objectdefining the actor message(s) and behavior(s); 2. Define theMessagetype with actor message class; 3. Annotate with Provides the "create" method that returns the (possibly just initial) Behavior of the actor; 4. Use thebindTypedActorin PekkoGuiceSupport, passing theobjectas 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 PekkoGuiceSupport { override def configure() = { bindTypedActor(classOf[ConfiguredActor], "configured-actor") } }
Messageis a type member rather than a type parameter is because you can't define, using the example above,GetConfiginside the object and also have the object extendActorModule[ConfiguredActor.GetConfig].- Annotations
- @ApiMayChange()
- See also
https://pekko.apache.org/docs/pekko/1.0/typed/style-guide.html#functional-versus-object-oriented-style
- trait PekkoGuiceSupport extends AnyRef
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 PekkoGuiceSupport { 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 { ... }
- final class TypedActorRefProvider[T] extends Provider[ActorRef[T]]
A singleton Provider of the typed
ActorRef[T]resulting from spawning an actor with theBehavior[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 theBehavior[T]in dependency scope and the given name, in the ActorSystem in dependency scope.- T
The class of the messages the typed actor can handle.
- Annotations
- @Singleton() @ApiMayChange()
Value Members
- object ActorModule
The companion object to hold ActorModule's ActorModule.Aux type alias.
The companion object to hold ActorModule's ActorModule.Aux type alias.
- Annotations
- @ApiMayChange()