Packages

t

play.api.libs.concurrent

AkkaGuiceSupport

trait AkkaGuiceSupport extends AnyRef

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")
  }
}

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

class MyController @Inject() (@Named("myActor") myActor: ActorRef, val controllerComponents: ControllerComponents)
    extends BaseController {
  ...
}
Self Type
AkkaGuiceSupport with AbstractModule
Source
AkkaGuiceSupport.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. AkkaGuiceSupport
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def bindActor[T <: Actor](name: String, props: (Props) ⇒ Props = identity)(implicit arg0: ClassTag[T]): Unit

    Bind an actor.

    Bind an actor.

    This will cause the actor to be instantiated by Guice, allowing it to be dependency injected itself. It will bind the returned ActorRef for the actor will be bound, qualified with the passed in name, so that it can be injected into other components.

    T

    The class that implements the actor.

    name

    The name of the actor.

    props

    A function to provide props for the actor. The props passed in will just describe how to create the actor, this function can be used to provide additional configuration such as router and dispatcher configuration.

  6. def bindActorFactory[ActorClass <: Actor, FactoryClass](implicit arg0: ClassTag[ActorClass], arg1: ClassTag[FactoryClass]): Unit

    Bind an actor factory.

    Bind an actor factory.

    This is useful for when you want to have child actors injected, and want to pass parameters into them, as well as have Guice provide some of the parameters. It is intended to be used with Guice's AssistedInject feature.

    Let's say you have an actor that looks like this:

    class MyChildActor @Inject() (db: Database, @Assisted id: String) extends Actor {
      ...
    }

    So db should be injected, while id should be passed. Now, define a trait that takes the id, and returns the actor:

    trait MyChildActorFactory {
      def apply(id: String): Actor
    }

    Now you can use this method to bind the child actor in your module:

    class MyModule extends AbstractModule with AkkaGuiceSupport {
      def configure = {
        bindActorFactory[MyChildActor, MyChildActorFactory]
      }
    }

    Now, when you want an actor to instantiate this as a child actor, inject MyChildActorFactory:

    class MyActor @Inject() (myChildActorFactory: MyChildActorFactory) extends Actor with InjectedActorSupport {
    
      def receive {
        case CreateChildActor(id) =>
          val child: ActorRef = injectedChild(myChildActorFactory(id), id)
          sender() ! child
      }
    }
    ActorClass

    The class that implements the actor that the factory creates

    FactoryClass

    The class of the actor factory

  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  8. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  12. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  13. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  17. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  18. def toString(): String
    Definition Classes
    AnyRef → Any
  19. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()

Inherited from AnyRef

Inherited from Any

Ungrouped