Created
December 31, 2012 02:08
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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