Scala-Lagom-Scheduler Problem | How to invoke Scheduler using eager singleton?


(Yash Bhardwaj) #1

Scala-Lagom-Scheduler Problem | How to invoke Scheduler using eager singleton.

I’m trying to invoke a scheduler asEagerSingleton, like:

class LMSActor extends Actor {
  override def receive: Receive = {
    case LMSActorInvoke => println("\n\nSome Statement!\n\n")

object LMSActor {
  def props: Props = Props(new LMSActor)

  case object LMSActorInvoke


class LFScheduler {

  implicit val system: ActorSystem = ActorSystem("LMSActorSystem")
  implicit val materializer: ActorMaterializer = ActorMaterializer()
  implicit val executionContext: ExecutionContextExecutor = system.dispatcher

  implicit val timeout: Timeout = 3.minute

  val concurrency = Runtime.getRuntime.availableProcessors() * 10
  val lmsActor = system.actorOf(RoundRobinPool(concurrency).props(LMSActor.props), "LMS Actor")
  val lmsScheduler = system.scheduler.schedule(2.seconds, 4.seconds)(lmsActor ? LMSActorInvoke)

object LFScheduler extends LFScheduler

class LFLMSLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication = new 
    LFLMSApplication(context) {
    override def serviceLocator: ServiceLocator = NoServiceLocator

  override def loadDevMode(context: LagomApplicationContext): LagomApplication = new 
    LFLMSApplication(context) with LagomDevModeComponents

    override def describeService = Some(readDescriptor[LFLMSService])


class LFServiceModule extends AbstractModule {
  override def configure() = {

In application.conf:

play.application.loader = com.lf.lflms.impl.LFLMSLoader
play.application.module = com.lf.lflms.impl.LFServiceModule

As per my understanding LFServiceModule should load as eager singleton and should invoke the scheduler. But it’s not working. Tried to explore more into documentation but couldn’t get any good references. I don’t know what’s wrong.

(Yash Bhardwaj) #2
abstract class WelcomeApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with AhcWSComponents {

  // Bind the service that this server provides
  override lazy val lagomServer = serverFor[LFLMSService](wire[LFLMSServiceImpl])


Worked! additional Module is not required.