Skip to content
Snippets Groups Projects
Commit 24b9b373 authored by Denny's avatar Denny
Browse files

Subclass URLClassLoader instead of using reflection

parent 31c53e91
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ import java.nio.ByteBuffer ...@@ -17,7 +17,7 @@ import java.nio.ByteBuffer
* The Mesos executor for Spark. * The Mesos executor for Spark.
*/ */
class Executor extends Logging { class Executor extends Logging {
var urlClassLoader : URLClassLoader = null var urlClassLoader : ExecutorURLClassLoader = null
var threadPool: ExecutorService = null var threadPool: ExecutorService = null
var env: SparkEnv = null var env: SparkEnv = null
...@@ -104,7 +104,7 @@ class Executor extends Logging { ...@@ -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 * 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 * created by the interpreter to the search path
*/ */
private def createClassLoader(): URLClassLoader = { private def createClassLoader(): ExecutorURLClassLoader = {
var loader = this.getClass().getClassLoader() var loader = this.getClass().getClassLoader()
...@@ -132,23 +132,24 @@ class Executor extends Logging { ...@@ -132,23 +132,24 @@ class Executor extends Logging {
} }
} }
return new URLClassLoader(Array(), loader) return new ExecutorURLClassLoader(Array(), loader)
} }
def updateClassLoader() { def updateClassLoader() {
val currentURLs = urlClassLoader.getURLs() val currentURLs = urlClassLoader.getURLs()
val urlSet = jarSet.keySet.map { x => new File(x.split("/").last).toURI.toURL } 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 => urlSet.filterNot(currentURLs.contains(_)).foreach { url =>
logInfo("Adding " + url + " to the class loader.") 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)
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment