Here is my test code,written based on the scala akka example from documentation 2.0.4 mentioned on their website. On excuting the example,the Eclipse throuws error stating "Could not find or load main class " error message. Sorry about the cross positing,but i could not fiind any solution to this issue anywhere.
Eclipse version: Eclipse IDE for Java Developers 2.0.2.20140224-0000 ( Kepler Service Release 2 )
Scala IDE plugin version : Scala IDE for Eclipse 3.0.3.v-2_10-201403271605-8d2c756
Scala version:2.10.3
Akka jar version : akka-actor_2.10-2.1.4
import akka.actor.Actor
import akka.actor.ActorRef
import scala.collection.mutable.ListBuffer
import akka.actor.Props
import akka.routing.RoundRobinRouter
import akka.actor.ActorSystem
object AkaObj extends App{
process()
sealed trait PiMessage
case class Work(value:String) extends PiMessage
case class printComp(valu:String)extends PiMessage
case object Start extends PiMessage
case class ListObj(cont:Seq[String]) extends PiMessage
class Worker extends Actor{
def receive()={
case Work(value:String)=>
println(value)
sender ! printComp(value)
}
}
class Master(listener: ActorRef) extends Actor{
val nrOfWorkers = 10
var counter = 0
var lis = ListBuffer[String]()
val workerRouter = context.actorOf(
Props[Worker].withRouter(RoundRobinRouter(nrOfWorkers)), name = "workerRouter")
def receive()={
//handle message
case Start=>workerRouter ! Work("Start now " + System.currentTimeMillis())
case printComp(value:String)=> {
counter+=1
lis.append(counter+"-"+value)
if(counter >=10)
listener ! ListObj(lis.toSeq)
// Stops this actor and all its supervised children
context.stop(self)
}
}
}
class Listener extends Actor{
def receive()={
case ListObj(cont:Seq[String])=>
println("Completed " +cont)
context.system.shutdown()
}
}
def process(){
// Create an Akka system
val system = ActorSystem("PiSystem")
// create the result listener, which will print the result and shutdown the system
val listener = system.actorOf(Props[Listener], name = "listener")
// create the master
val master = system.actorOf(Props(new Master(listener)),
name = "master")
// start the calculation
master ! Start
}
}