diff options
author | Denny <dennybritz@gmail.com> | 2012-09-11 16:51:08 -0700 |
---|---|---|
committer | Denny <dennybritz@gmail.com> | 2012-09-11 16:51:08 -0700 |
commit | 24b9b373149e5523fd620019f7e8ee2341fbce24 (patch) | |
tree | b91326c111237afecffb035404755e37b4658045 | |
parent | 31c53e917d2cba54f485abec56e4f66726d2a732 (diff) | |
download | spark-24b9b373149e5523fd620019f7e8ee2341fbce24.tar.gz spark-24b9b373149e5523fd620019f7e8ee2341fbce24.tar.bz2 spark-24b9b373149e5523fd620019f7e8ee2341fbce24.zip |
Subclass URLClassLoader instead of using reflection
-rw-r--r-- | core/src/main/scala/spark/executor/Executor.scala | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/core/src/main/scala/spark/executor/Executor.scala b/core/src/main/scala/spark/executor/Executor.scala index 2d53c7a6ad..371db08da3 100644 --- a/core/src/main/scala/spark/executor/Executor.scala +++ b/core/src/main/scala/spark/executor/Executor.scala @@ -17,7 +17,7 @@ import java.nio.ByteBuffer * The Mesos executor for Spark. */ class Executor extends Logging { - var urlClassLoader : URLClassLoader = null + var urlClassLoader : ExecutorURLClassLoader = null var threadPool: ExecutorService = null var env: SparkEnv = null @@ -104,7 +104,7 @@ class Executor extends Logging { * Create a ClassLoader for use in tasks, adding any JARs specified by the user or any classes * created by the interpreter to the search path */ - private def createClassLoader(): URLClassLoader = { + private def createClassLoader(): ExecutorURLClassLoader = { var loader = this.getClass().getClassLoader() @@ -132,23 +132,24 @@ class Executor extends Logging { } } - return new URLClassLoader(Array(), loader) + return new ExecutorURLClassLoader(Array(), loader) } def updateClassLoader() { val currentURLs = urlClassLoader.getURLs() - val urlSet = jarSet.keySet.map { x => new File(x.split("/").last).toURI.toURL } - - // For abstraction reasons the addURL method in URLClassLoader is protected. - // We'll save us the hassle of sublassing here and use relfection instead. - val m = classOf[URLClassLoader].getDeclaredMethod("addURL", classOf[URL]) - m.setAccessible(true) urlSet.filterNot(currentURLs.contains(_)).foreach { url => logInfo("Adding " + url + " to the class loader.") - m.invoke(urlClassLoader, url) + urlClassLoader.addURL(url) } } + // The addURL method in URLClassLoader is protected. We subclass it to make it accessible. + class ExecutorURLClassLoader(urls : Array[URL], parent : ClassLoader) extends URLClassLoader(urls, parent) { + override def addURL(url: URL) { + super.addURL(url) + } + } + } |