Moved ClassServer out of repl packaged and renamed it to HttpServer.

This commit is contained in:
Matei Zaharia 2010-10-15 19:04:18 -07:00
parent a768cf417b
commit ecb1af576e
2 changed files with 12 additions and 12 deletions

View file

@ -1,4 +1,4 @@
package spark.repl package spark
import java.io.File import java.io.File
import java.net.InetAddress import java.net.InetAddress
@ -8,22 +8,20 @@ import org.eclipse.jetty.server.handler.DefaultHandler
import org.eclipse.jetty.server.handler.HandlerList import org.eclipse.jetty.server.handler.HandlerList
import org.eclipse.jetty.server.handler.ResourceHandler import org.eclipse.jetty.server.handler.ResourceHandler
import spark.Logging
/** /**
* Exception type thrown by ClassServer when it is in the wrong state * Exception type thrown by HttpServer when it is in the wrong state
* for an operation. * for an operation.
*/ */
class ServerStateException(message: String) extends Exception(message) class ServerStateException(message: String) extends Exception(message)
/** /**
* An HTTP server used by the interpreter to allow worker nodes to access * An HTTP server for static content used to allow worker nodes to access JARs
* class files created as the user types in lines of code. This is just a * added to SparkContext as well as classes created by the interpreter when
* wrapper around a Jetty embedded HTTP server. * the user types in code. This is just a wrapper around a Jetty server.
*/ */
class ClassServer(classDir: File) extends Logging { class HttpServer(resourceBase: File) extends Logging {
private var server: Server = null private var server: Server = null
private var port: Int = -1 private var port: Int = -1
@ -33,13 +31,13 @@ class ClassServer(classDir: File) extends Logging {
} else { } else {
server = new Server(0) server = new Server(0)
val resHandler = new ResourceHandler val resHandler = new ResourceHandler
resHandler.setResourceBase(classDir.getAbsolutePath) resHandler.setResourceBase(resourceBase.getAbsolutePath)
val handlerList = new HandlerList val handlerList = new HandlerList
handlerList.setHandlers(Array(resHandler, new DefaultHandler)) handlerList.setHandlers(Array(resHandler, new DefaultHandler))
server.setHandler(handlerList) server.setHandler(handlerList)
server.start() server.start()
port = server.getConnectors()(0).getLocalPort() port = server.getConnectors()(0).getLocalPort()
logDebug("ClassServer started at " + uri) logDebug("HttpServer started at " + uri)
} }
} }

View file

@ -36,6 +36,8 @@ import scala.tools.nsc.{ InterpreterResults => IR }
import interpreter._ import interpreter._
import SparkInterpreter._ import SparkInterpreter._
import spark.HttpServer
/** <p> /** <p>
* An interpreter for Scala code. * An interpreter for Scala code.
* </p> * </p>
@ -120,14 +122,14 @@ class SparkInterpreter(val settings: Settings, out: PrintWriter) {
val virtualDirectory = new PlainFile(outputDir) val virtualDirectory = new PlainFile(outputDir)
/** Jetty server that will serve our classes to worker nodes */ /** Jetty server that will serve our classes to worker nodes */
val classServer = new ClassServer(outputDir) val classServer = new HttpServer(outputDir)
// Start the classServer and store its URI in a spark system property // Start the classServer and store its URI in a spark system property
// (which will be passed to executors so that they can connect to it) // (which will be passed to executors so that they can connect to it)
classServer.start() classServer.start()
System.setProperty("spark.repl.class.uri", classServer.uri) System.setProperty("spark.repl.class.uri", classServer.uri)
if (SPARK_DEBUG_REPL) { if (SPARK_DEBUG_REPL) {
println("ClassServer started, URI = " + classServer.uri) println("Class server started, URI = " + classServer.uri)
} }
/** reporter */ /** reporter */