Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having problems with Akka 2.1.2 Scheduler ('system' not recognized)

Tags:

scala

akka

I'm trying to get a very simple recurring function loop running, according to these samples:

http://doc.akka.io/docs/akka/2.1.2/scala/scheduler.html

The code:

import akka.actor.Actor
import akka.actor.Props
import scala.concurrent.duration._

object Main extends Application {
  val system = akka.actor.ActorSystem("system")    // this was missing!
  import system.dispatcher

  system.scheduler.schedule( 0 milliseconds, (10*1000) milliseconds, {
    println( "click!" )
  })
}

I get (sbt):

> .../src/Main.scala:34: not found: value system [error]       import
> system.dispatcher [error]              ^ [error]
> .../src/Main.scala:36: not found: value system [error]      
> system.scheduler.schedule( 0 milliseconds /*initial delay*/,
> (entry.secs*1000) milliseconds /*delay between*/, { [error]       ^

Where is the system supposed to be coming from?

Addendum:

I'm having the code within a 'main()' function, and I haven't inherited anything from Actor or ActorSystem. The point is I'd like to schedule functions but no go into actors with this. Is the framework thinking I must derive from something (if so, it kind-of should say it?).

like image 671
akauppi Avatar asked Mar 28 '13 14:03

akauppi


1 Answers

It looks like missing of following expression before import system.dispatcher:

val system = akka.actor.ActorSystem("system")
like image 125
Andriy Plokhotnyuk Avatar answered Nov 16 '22 21:11

Andriy Plokhotnyuk