|
@@ -4,7 +4,6 @@ import java.io.{BufferedReader, PipedReader, PipedWriter, StringWriter}
|
|
|
import java.util.concurrent.{BlockingQueue, SynchronousQueue}
|
|
import java.util.concurrent.{BlockingQueue, SynchronousQueue}
|
|
|
|
|
|
|
|
import org.apache.spark.repl.SparkILoop
|
|
import org.apache.spark.repl.SparkILoop
|
|
|
-import org.json4s.jackson.JsonMethods._
|
|
|
|
|
|
|
|
|
|
import scala.concurrent._
|
|
import scala.concurrent._
|
|
|
import scala.tools.nsc.SparkHelper
|
|
import scala.tools.nsc.SparkHelper
|
|
@@ -14,23 +13,29 @@ import scala.tools.nsc.util.ClassPath
|
|
|
class SparkerInterpreter {
|
|
class SparkerInterpreter {
|
|
|
private implicit def executor: ExecutionContext = ExecutionContext.global
|
|
private implicit def executor: ExecutionContext = ExecutionContext.global
|
|
|
|
|
|
|
|
|
|
+ private var running = false;
|
|
|
private val inQueue = new SynchronousQueue[Request]
|
|
private val inQueue = new SynchronousQueue[Request]
|
|
|
-
|
|
|
|
|
private val inWriter = new PipedWriter()
|
|
private val inWriter = new PipedWriter()
|
|
|
|
|
|
|
|
|
|
+ org.apache.spark.repl.Main.interp = new SparkerILoop(
|
|
|
|
|
+ this,
|
|
|
|
|
+ inQueue,
|
|
|
|
|
+ new BufferedReader(new PipedReader(inWriter)),
|
|
|
|
|
+ new StringWriter)
|
|
|
|
|
+
|
|
|
// Launch the real interpreter thread.
|
|
// Launch the real interpreter thread.
|
|
|
private val thread = new Thread {
|
|
private val thread = new Thread {
|
|
|
override def run(): Unit = {
|
|
override def run(): Unit = {
|
|
|
- org.apache.spark.repl.Main.interp = new SparkerILoop(
|
|
|
|
|
- inQueue,
|
|
|
|
|
- new BufferedReader(new PipedReader(inWriter)),
|
|
|
|
|
- new StringWriter)
|
|
|
|
|
val args = Array("-usejavacp")
|
|
val args = Array("-usejavacp")
|
|
|
org.apache.spark.repl.Main.interp.process(args)
|
|
org.apache.spark.repl.Main.interp.process(args)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
thread.start()
|
|
thread.start()
|
|
|
|
|
|
|
|
|
|
+ def statements = {
|
|
|
|
|
+ org.apache.spark.repl.Main.interp.history.asStrings
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
def execute(statement: String): Future[Map[String, String]] = {
|
|
def execute(statement: String): Future[Map[String, String]] = {
|
|
|
val promise = Promise[Map[String, String]]()
|
|
val promise = Promise[Map[String, String]]()
|
|
|
inQueue.put(ExecuteRequest(statement, promise))
|
|
inQueue.put(ExecuteRequest(statement, promise))
|
|
@@ -43,7 +48,7 @@ class SparkerInterpreter {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-class SparkerILoop(inQueue: BlockingQueue[Request], in0: BufferedReader, outString: StringWriter) extends SparkILoop(in0, new JPrintWriter(outString)) {
|
|
|
|
|
|
|
+class SparkerILoop(parent: SparkerInterpreter, inQueue: BlockingQueue[Request], in0: BufferedReader, outString: StringWriter) extends SparkILoop(in0, new JPrintWriter(outString)) {
|
|
|
|
|
|
|
|
class SparkerILoopInterpreter extends SparkILoopInterpreter {
|
|
class SparkerILoopInterpreter extends SparkILoopInterpreter {
|
|
|
outer =>
|
|
outer =>
|