This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Dynamic ending searching path of URLClassLoader of a remote actor

No replies
Jiansen
Joined: 2011-04-27,
User offline. Last seen 1 year 10 weeks ago.

We were told that JVM load classes "on demand". Therefore it should
be possible to extend the searching path of a classloader on the fly.
In following code, I attempted to simulate this in an actor model.

class myActor extends Actor{

private object myClassLoader(port:Int, name: Symbol) extends
URLClassLoader(Array(), getClass().getClassLoader()){
override def addURL(url:URL) {
super.addURL(url)
}
}

def act() {
RemoteActor.classLoader = myClassLoader
//myClassLoader.addURL(new URL("file:///home/jiansen/Desktop/
scalatest/client/"))
alive(port)
register(name, self)

loop(
react {
case URLClassPath(url) => {
myClassLoader.addURL(url)
println("new URL added to class path: "+url)
}
...
}
)
}
}

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland