I'm trying to create an actor in Java Play Framework (2.5.10) for running periodic tasks. When my application runs, however, I get the error No implementation for akka.actor.ActorRef was bound (detailed error messages provided later in this post). I'm sure the mistake is pretty basic, but I'm new to the whole actors thing and am having trouble figuring it out.
Here's the class (root-level Module.java) that binds the scheduler class and the actor:
public class Module extends AbstractModule implements AkkaGuiceSupport {
@Override
public void configure() {
// Use the system clock as the default implementation of Clock
bind(Clock.class).toInstance(Clock.systemDefaultZone());
// Ask Guice to create an instance of ApplicationTimer when the
// application starts.
bind(ApplicationTimer.class).asEagerSingleton();
// Set AtomicCounter as the implementation for Counter.
bind(Counter.class).to(AtomicCounter.class);
// bind the ECWID data importer
bind(ImportScheduler.class).asEagerSingleton();
bindActor(UserImportActor.class, UserImportActor.ACTOR_NAME);
}
}
The scheduler class:
@Singleton
public class ImportScheduler {
@Inject
public ImportScheduler(final ActorSystem actorSystem, final ActorRef UserImportActor) {
actorSystem.scheduler().schedule(
Duration.create(1, TimeUnit.SECONDS),
Duration.create(1, TimeUnit.SECONDS),
UserImportActor,
0,
actorSystem.dispatcher(),
UserImportActor
);
}
}
And finally, the actor class:
public class UserImportActor extends UntypedActor {
public static final String ACTOR_NAME = "user_import_actor";
@Override
public void onReceive(Object message){
Logger.info("The user import actor was called!");
}
}
When the application runs, here's the error that I see (the full error is too long - I think the first few lines will suffice):
! @72bagdfd4 - Internal server error, for (GET) [/] ->
play.api.UnexpectedException: Unexpected exception[CreationException: Unable to create injector, see the following errors:
1) No implementation for akka.actor.ActorRef was bound.
while locating akka.actor.ActorRef
for parameter 1 at services.ecwid.db.ImportScheduler.<init>(ImportScheduler.java:12)
at Module.configure(Module.java:34) (via modules: com.google.inject.util.Modules$OverrideModule -> Module)
Any idea what I'm missing?