diff options
author | michelou <michelou@epfl.ch> | 2010-12-08 18:28:43 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2010-12-08 18:28:43 +0000 |
commit | 4dbe72f83f7ade1517bad7444009d3d0c8a69bd5 (patch) | |
tree | 73a4ec0fe6c99dea6d0ac033774575f127671769 /test/files/detach-run/actor | |
parent | 6e15632fcbcb8578b30850ee93b3d3d8c9f3e7b9 (diff) | |
download | scala-4dbe72f83f7ade1517bad7444009d3d0c8a69bd5.tar.gz scala-4dbe72f83f7ade1517bad7444009d3d0c8a69bd5.tar.bz2 scala-4dbe72f83f7ade1517bad7444009d3d0c8a69bd5.zip |
minor code updates (detach plugin)
Diffstat (limited to 'test/files/detach-run/actor')
-rw-r--r-- | test/files/detach-run/actor/Client.scala | 4 | ||||
-rw-r--r-- | test/files/detach-run/actor/Server.scala | 9 | ||||
-rw-r--r-- | test/files/detach-run/actor/ServerClassLoader.scala | 154 | ||||
-rw-r--r-- | test/files/detach-run/actor/ServerConsole.scala | 10 | ||||
-rw-r--r-- | test/files/detach-run/actor/actor.scala | 4 |
5 files changed, 21 insertions, 160 deletions
diff --git a/test/files/detach-run/actor/Client.scala b/test/files/detach-run/actor/Client.scala index af1c26ee1b..12573e24d3 100644 --- a/test/files/detach-run/actor/Client.scala +++ b/test/files/detach-run/actor/Client.scala @@ -1,3 +1,7 @@ +/* + * @author Stephane Micheloud + */ + import scala.actors.Actor._, ClientHelper._ import scala.actors.remote._, RemoteActor._ import scala.remoting._, Debug._ diff --git a/test/files/detach-run/actor/Server.scala b/test/files/detach-run/actor/Server.scala index 84df6f5d81..b56d22f744 100644 --- a/test/files/detach-run/actor/Server.scala +++ b/test/files/detach-run/actor/Server.scala @@ -1,6 +1,9 @@ -import scala.actors._, Actor._ -import scala.actors.remote._, RemoteActor._ -import scala.reflect.Manifest +/* + * @author Stephane Micheloud + */ + +import scala.actors.Actor._ +import scala.actors.remote.RemoteActor._ object Server extends ServerConsole { private def computation(f: Int => Int): Int = { diff --git a/test/files/detach-run/actor/ServerClassLoader.scala b/test/files/detach-run/actor/ServerClassLoader.scala deleted file mode 100644 index 3f5d96a1a1..0000000000 --- a/test/files/detach-run/actor/ServerClassLoader.scala +++ /dev/null @@ -1,154 +0,0 @@ -import java.io._ -import java.net.{JarURLConnection, URL, URLClassLoader} - -import scala.remoting.Debug - - private class ServerObjectInputStream(in: InputStream, cl: ClassLoader) - extends ObjectInputStream(in) { - override def resolveClass(cd: ObjectStreamClass): Class[_] = { - println("[ServerObjectInputStream] resolveClass "+cd.getName) - try { - Debug.info("load class "+cd.getName+" from "+cl) - val c = cl.loadClass(cd.getName) - Debug.info("loaded class "+c.getName) - c - } catch { - case cnf: ClassNotFoundException => - Debug.info("resolve class (this) "+cd.getName) - val c = super.resolveClass(cd) - Debug.info("resolve class (super) "+c.getName) - c - } - } - override def resolveProxyClass(interfaces: Array[String]): Class[_] = { - println("[ServerObjectInputStream] resolveProxyClass "+interfaces.toList) - try { - val c = cl.loadClass(interfaces.last) - Debug.info("loaded class "+c.getName) - c - } catch { - case cnf: ClassNotFoundException => - Debug.info("resolve proxy class (this) "+interfaces.last) - val c = super.resolveProxyClass(interfaces) - Debug.info("resolve proxy class (super) "+c.getName) - c - } - } - } -/* - // VARIANT 1 - class ServerClassLoader extends URLClassLoader(urls) { - import scala.reflect.Manifest - def load[A](a: Array[Byte])(implicit expected: Manifest[A]): A = { - val in = new ServerObjectInputStream(new ByteArrayInputStream(a), this) - val found = in.readObject.asInstanceOf[Manifest[_]] - if (! (found <:< expected)) - throw new ClassCastException("type mismatch;"+ - "\n found : "+found+ - "\n required: "+expected) - val o = in.readObject.asInstanceOf[A] - in.close() - o - } - override def findClass(name: String): Class[_] = { - println("[ServerClassLoader] findClass "+name) - val b = loadClassData(name) - if (b != null) defineClass(name, b, 0, b.length) - else super.findClass(name) - } - private def loadClassData(name: String): Array[Byte] = { - println("[ServerClassLoader] loadClassData "+name) - null - } - } - val serverClassLoader = new ServerClassLoader -*/ - -/* - class ServerClassLoader(parent: ClassLoader) extends URLClassLoader(urls, parent) { - import scala.reflect.Manifest - def load[A](a: Array[Byte])(implicit expected: Manifest[A]): A = { - val in = new ServerObjectInputStream(new ByteArrayInputStream(a), this) - val found = in.readObject.asInstanceOf[Manifest[_]] - if (! (found <:< expected)) - throw new ClassCastException("type mismatch;"+ - "\n found : "+found+ - "\n required: "+expected) - val o = in.readObject.asInstanceOf[A] - in.close() - o - } - override def findClass(name: String): Class[_] = { - println("[ServerClassLoader] findClass "+name) - val b = loadClassData(name) - if (b != null) defineClass(name, b, 0, b.length) - else super.findClass(name) - } - private def loadClassData(name: String): Array[Byte] = { - println("[ServerClassLoader] loadClassData "+name) - null - } - } -*/ -class ServerClassLoader(urls: Array[URL], parent: ClassLoader) -extends URLClassLoader(urls, parent) { - - private val cache = new collection.mutable.HashMap[String, Class[_]] - - for (url <- urls) { - val jarurl = new URL("jar:"+url+"!/") - val con = jarurl.openConnection().asInstanceOf[JarURLConnection] - val jar = con.getJarFile - val e = jar.entries - while (e.hasMoreElements) { - val ze = e.nextElement - val path = ze.getName - if (path endsWith ".class") { - val size = ze.getSize - val name = path.replace("/", ".").substring(0, path.length - 6) - cache += name -> this.loadClass(name) - println("[ServerClassLoader] added "+name+" ("+size+")") - } - };
//jar.close() - } - - override def findClass(name: String): Class[_] = { - println("[ServerClassLoader] findClass: name="+name) - cache get name match { - case Some(cl) => - println(name+" cached"); cl - case None => - println(name+" not cached"); super.findClass(name) - } - } - -} - -/* -try { - JarFile jarFile = new JarFile(srcPath); - Enumeration<JarEntry> entries = jarFile.entries(); - String url = "file:" + srcPath; - System.out.println(url); - URLClassLoader classLoader = new URLClassLoader( - new URL[] { new URL(url) }); - while (entries.hasMoreElements()) { - JarEntry jarEntry = (JarEntry) entries - .nextElement(); - String classPath = jarEntry.getName(); - if (classPath.endsWith(".class")) { - String className = classPath.replace("/", ".") - .substring(0, classPath.length() - 6); - try { - Class clazz = classLoader - .loadClass(className); - //Et là, tu fais ce que tu vexu avec la classe - } catch (ClassNotFoundException e1) { - e1.printStackTrace(); - } - } - } -} catch (IOException e1) { - e1.printStackTrace(); -} -*/ diff --git a/test/files/detach-run/actor/ServerConsole.scala b/test/files/detach-run/actor/ServerConsole.scala index f68274e927..d38725ddee 100644 --- a/test/files/detach-run/actor/ServerConsole.scala +++ b/test/files/detach-run/actor/ServerConsole.scala @@ -1,4 +1,8 @@ -import java.io._ +/* + * @author Stephane Micheloud + */ + +import java.io.{BufferedReader, InputStreamReader} import scala.compat.Platform.currentTime import scala.remoting.Debug, Debug._ @@ -15,7 +19,7 @@ trait ServerConsole extends Thread { import java.rmi.server.RMIClassLoader val codebase = System.getProperty("java.rmi.server.codebase") info("[ServerConsole] codebase="+codebase) - RMIClassLoader.getClassLoader(codebase) + RMIClassLoader getClassLoader codebase } private var isTerminated = false @@ -44,7 +48,7 @@ trait ServerConsole extends Thread { } terminate() println("Server exited ("+mkTimeString(currentTime - startTime)+")") - exit(0) + system.exit(0) } protected def trace(msg: String) { diff --git a/test/files/detach-run/actor/actor.scala b/test/files/detach-run/actor/actor.scala index f3ed4c2d26..18a6dc38fd 100644 --- a/test/files/detach-run/actor/actor.scala +++ b/test/files/detach-run/actor/actor.scala @@ -1,3 +1,7 @@ +/* + * @author Stephane Micheloud + */ + object Test { val name = "actor" |