Actor as Singleton and Application not started error

343 views
Skip to first unread message

Sergey Dashko

unread,
Nov 11, 2015, 10:13:37 PM11/11/15
to play-framework
I created module to use my actor as singleton:

class ActorsModule extends AbstractModule with AkkaGuiceSupport {
  def configure() = {
    bind(classOf[MessageInit]).asEagerSingleton()
    bind(classOf[Actors]).asEagerSingleton()
    @Provides
    @Named("manager-actor")
    def managerActor(actors: Actors): ActorRef = actors.manager
  }
}

@Singleton
class Actors @Inject() (system: ActorSystem) {
  val manager = system.actorOf(ManagerActor.props)
}

@Singleton
class MessageInit @Inject()(actorSystem: ActorSystem,
                            @Named("manager-actor") managerActor: ActorRef) {
  println("Starting messages...")
  managerActor ! "start"
}

Now whenever application start I've got error "
akka.actor.OneForOneStrategy - There is no started application
akka.actor.ActorInitializationException: exception during creation
Caused by: java.lang.RuntimeException: There is no started application
"

What is wrong with my code? I need help.

Regards,
Sergey

Sergey Dashko

unread,
Nov 13, 2015, 11:01:00 PM11/13/15
to play-framework
Ok, seams I have found the cause. It's because of usage play.api.Play.current.configuration in Actor.
How it is possible to fix this?

Regards,
Sergey

четверг, 12 ноября 2015 г., 5:13:37 UTC+2 пользователь Sergey Dashko написал:

Anand Krishnan

unread,
Jul 23, 2016, 4:52:40 PM7/23/16
to play-framework
Hi Sergey

Did you get a work around for this issue? If so can you pls share it?

Thank you
Anand

Greg Methvin

unread,
Jul 24, 2016, 3:43:53 AM7/24/16
to play-framework
The solution is not to use Play.current. Eager singletons are eagerly instantiated, meaning the component will be initialized before the app is necessarily initialized, so the global static reference the the application won't be set. Inject the configuration using DI, or manually pass it to the constructor of your actor. (See the documentation for some examples.)

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/b356b033-7903-4558-80a1-79aaab641f6f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Greg Methvin
Senior Software Engineer

Reply all
Reply to author
Forward
0 new messages