Skip to content

Instantly share code, notes, and snippets.

@sheenobu
Created December 31, 2012 02:08
Show Gist options
  • Select an option

  • Save sheenobu/4416840 to your computer and use it in GitHub Desktop.

Select an option

Save sheenobu/4416840 to your computer and use it in GitHub Desktop.
Akka/Scala Simple console Actor using scala-lang jline and a recursive actor.
import akka.actor._
import scala.tools.jline._
import scala.tools.jline.console._
import scala.tools.jline.console.completer._
class Console(actor:ActorRef) extends Actor {
val consoleReader = new ConsoleReader()
consoleReader.addCompleter(new StringsCompleter("quit")) // tab completion
def receive = {
case "start" =>
var userinput = consoleReader.readLine("console > ").trim() // input
self ! (userinput match {
case "quit" => "stop" // Stop recursion
case _ =>
println("Unknown command %s".format(userinput))
"start" // Recursive
})
case "stop" => actor ! "stop" // send stop signal to specified actor
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment