public interface AkkaGuiceSupport
Mix this interface in with a Guice AbstractModule to get convenient support for binding actors. For example:
public class MyModule extends AbstractModule implements AkkaGuiceSupport { protected void configure() { bindActor(MyActor.class, "myActor"); bindTypedActor(HelloActor.class, "hello-actor"); } }Then to use the above actor in your application, add a qualified injected dependency, like so:
public class MyController extends Controller { @Inject @Named("myActor") ActorRef myActor; @Inject ActorRef<HelloActor.SayHello> helloActor; ... }
Modifier and Type | Method and Description |
---|---|
default <T extends akka.actor.Actor> |
bindActor(java.lang.Class<T> actorClass,
java.lang.String name)
Bind an actor.
|
default <T extends akka.actor.Actor> |
bindActor(java.lang.Class<T> actorClass,
java.lang.String name,
java.util.function.Function<akka.actor.Props,akka.actor.Props> props)
Bind an actor.
|
default <T extends akka.actor.Actor> |
bindActorFactory(java.lang.Class<T> actorClass,
java.lang.Class<?> factoryClass)
Bind an actor factory.
|
default <T> void |
bindTypedActor(java.lang.Class<? extends akka.actor.typed.Behavior<T>> behaviorClass,
java.lang.String name)
Bind a typed actor.
|
default <T extends akka.actor.Actor> void bindActor(java.lang.Class<T> actorClass, java.lang.String name, java.util.function.Function<akka.actor.Props,akka.actor.Props> props)
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 actor type.actorClass
- 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.default <T extends akka.actor.Actor> void bindActor(java.lang.Class<T> actorClass, java.lang.String name)
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 actor type.actorClass
- The class that implements the actor.name
- The name of the actor.default <T extends akka.actor.Actor> void bindActorFactory(java.lang.Class<T> actorClass, java.lang.Class<?> factoryClass)
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.
T
- the actor type.actorClass
- The class that implements the actor.factoryClass
- The factory interface for creating the actor.@ApiMayChange default <T> void bindTypedActor(java.lang.Class<? extends akka.actor.typed.Behavior<T>> behaviorClass, java.lang.String name)
For the given message type T
binds Behavior[T]
to the given Behavior
subclass and ActorRef[T]
to an instance of TypedActorRefProvider
with the given
actor name, so that it can be injected into other components.
Note that, while the name is used when spawning the actor in the ActorSystem
, it is
NOT used as a name qualifier for the binding. This is so that you don't need to use
Named
to qualify all injections of typed actors. Use the underlying
API to create multiple, name-annotated bindings.
T
- The type of the messages the typed actor can handle.behaviorClass
- The Behavior
subclass for the typed actor.name
- The name of the typed actor.