A sample for you. Here Tokenizer takes seq of items to parse and gives them out to Parser to do the parsing. Parser than reports back results to the Tokenizer.
import akka.actor._
import com.typesafe.config.ConfigFactory
case object Go
case object Done
case object GoAway
class Tokenizer(items: Seq[String]) extends Actor {
val kid = context.actorOf(Props[Parser])
var tokens: List[String] = List.empty
override def receive: akka.actor.Actor.Receive = {
case Go => // start process
items.foreach(kid ! _)
kid ! GoAway
case Done => // report results
println(tokens.mkString(":"))
self ! PoisonPill // shut down
case s: String => // data from kid
tokens = s :: tokens
}
}
class Parser extends Actor {
override def receive: Receive = {
case GoAway =>
sender ! Done
self ! PoisonPill // or context.stop(self)
case s: String =>
s.split("\\.").foreach(sender ! _)
}
}
object G extends App {
val config = ConfigFactory.parseString("" +
"akka.loglevel=DEBUG\n" +
"akka.debug.lifecycle=on\n" +
"akka.debug.receive=on\n" +
"akka.debug.event-stream=on\n" +
"akka.debug.unhandled=on\n" +
""
)
val system = ActorSystem("mine", config)
val doer = system.actorOf(Props(new Tokenizer(Seq("191.168.1.1", "192.168.1.2"))))
doer ! Go
system.shutdown()
system.awaitTermination()
}