2011-04-09 19:55:46 -06:00
|
|
|
|
Guice Integration
|
|
|
|
|
|
=================
|
|
|
|
|
|
|
2011-04-23 08:11:31 +02:00
|
|
|
|
All Typed Actors support dependency injection using `Guice <http://code.google.com/p/google-guice/>`_ annotations (such as ‘@Inject’ etc.).
|
2011-04-09 19:55:46 -06:00
|
|
|
|
The ‘TypedActorManager’ class understands Guice and will do the wiring for you.
|
|
|
|
|
|
|
|
|
|
|
|
External Guice modules
|
|
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
|
|
|
|
You can also plug in external Guice modules and have not-actors wired up as part of the configuration.
|
|
|
|
|
|
Here is an example:
|
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: java
|
|
|
|
|
|
|
|
|
|
|
|
import static akka.config.Supervision.*;
|
|
|
|
|
|
import static akka.config.SupervisorConfig.*;
|
|
|
|
|
|
|
|
|
|
|
|
TypedActorConfigurator manager = new TypedActorConfigurator();
|
|
|
|
|
|
|
|
|
|
|
|
manager.configure(
|
2011-09-28 14:08:04 +02:00
|
|
|
|
new AllForOneStrategy(new Class[]{Exception.class}, 3, 1000),
|
2011-04-09 19:55:46 -06:00
|
|
|
|
new SuperviseTypedActor[] {
|
|
|
|
|
|
new SuperviseTypedActor(
|
|
|
|
|
|
Foo.class,
|
|
|
|
|
|
FooImpl.class,
|
|
|
|
|
|
temporary(),
|
|
|
|
|
|
1000),
|
|
|
|
|
|
new SuperviseTypedActor(
|
|
|
|
|
|
Bar.class,
|
|
|
|
|
|
BarImpl.class,
|
|
|
|
|
|
permanent(),
|
|
|
|
|
|
1000)
|
|
|
|
|
|
})
|
|
|
|
|
|
.addExternalGuiceModule(new AbstractModule() {
|
|
|
|
|
|
protected void configure() {
|
|
|
|
|
|
bind(Ext.class).to(ExtImpl.class).in(Scopes.SINGLETON);
|
|
|
|
|
|
}})
|
|
|
|
|
|
.configure()
|
|
|
|
|
|
.inject()
|
|
|
|
|
|
.supervise();
|
|
|
|
|
|
|
|
|
|
|
|
Retrieve the external Guice dependency
|
|
|
|
|
|
--------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
The external dependency can be retrieved like this:
|
2011-05-09 17:52:30 +02:00
|
|
|
|
|
|
|
|
|
|
.. code-block:: java
|
|
|
|
|
|
|
|
|
|
|
|
Ext ext = manager.getExternalDependency(Ext.class);
|
|
|
|
|
|
|