arranged for per-host classloaders
authoradam <adam@megacz.com>
Thu, 24 Mar 2005 11:14:08 +0000 (11:14 +0000)
committeradam <adam@megacz.com>
Thu, 24 Mar 2005 11:14:08 +0000 (11:14 +0000)
darcs-hash:20050324111408-5007d-3e7f1903396e51bcd94860ada91d3186853ed290.gz

src/org/ibex/jinetd/Host.java
src/org/ibex/jinetd/Main.java
src/org/ibex/jinetd/Port.java
src/org/ibex/jinetd/TreeClassLoader.java

index 1a3dd3e..8df789f 100644 (file)
@@ -6,26 +6,44 @@ package org.ibex.jinetd;
 import org.ibex.util.*;
 import java.io.*;
 import java.util.*;
+import java.net.*;
 import java.lang.reflect.*;
 
-public class Host extends File {
+public class Host extends TreeClassLoader {
 
-    final String hostname;
-    public Host(String path, String hostname) { super(path); this.hostname = hostname; }
+    public final String hostname;
+    public final String path;
 
-    public void changed(File f) { }
-        /*
-        super.changed(w);
-        Log.debug(this, "changed(" + w + ")");
+    private static final Hashtable hosts = new Hashtable();
+    private static boolean initted = false;
+
+    public static Host getHost(String hostname) { return (Host)hosts.get(hostname); }
+    public static Enumeration enumerateHosts() { return hosts.elements(); }
+
+    public Host(String path, String hostname, ClassLoader pcl) {
+        super(new File(path + File.separatorChar + "WEB-INF"), pcl);
+        this.hostname = hostname;
+        this.path = path;
+    }
+
+    public static void init() {
+        if (initted) return;
+        initted = true;
+        init(org.ibex.jinetd.Main.ROOT + "/host", "", 0, Main.getRootClassLoader());
+    }
+    public static void init(String path, String host, int depth, ClassLoader pcl) {
         try {
-            ClassLoader cl = getClassLoader();
-            if (cl == null) return;
-            Class c = cl.loadClass("Main");
-            if (c == null) return;
-            Method m = c.getMethod("main", new Class[] { });
-            m.invoke(null, new Object[] { });
-        } catch (Exception e) {
-            Log.warn(this, e);
+            InetAddress.getByName(host);
+            String pad = "";
+            while(pad.length() + host.length() < 30) pad += " ";
+            Log.info(Main.class, pad + host + " => " + path);
+            hosts.put(host, pcl = new Host(path, host, pcl));
+        } catch (UnknownHostException e) {
+            if (depth >= 3) return;
         }
-        */
+        String[] subdirs = new File(path).list();
+        for(int i=0; i<subdirs.length; i++)
+            init(path + File.separatorChar + subdirs[i], host.equals("") ? subdirs[i] : subdirs[i]+"."+host, depth+1, pcl);
+    }
+
 }
index 037527e..cdbba4b 100644 (file)
@@ -69,6 +69,14 @@ public class Main {
         System.exit(0);
     }
 
+    private static TreeClassLoader rootClassLoader;
+    public static TreeClassLoader getRootClassLoader() {
+        if (rootClassLoader==null)
+            rootClassLoader = new TreeClassLoader(new File(ROOT + File.separatorChar + "lib"),
+                                                  Main.class.getClassLoader());
+        return rootClassLoader;
+    }
+
     public static void main(String[] s) throws Exception {
         init();
         Root root = new Root(ROOT);
index ad0331c..e6cc043 100644 (file)
@@ -28,7 +28,7 @@ public class Port extends TreeClassLoader {
     }
 
     void spawn(InetAddress bindTo, int port) { new PortThread(bindTo, port).start(); }
-    private static final ClassLoader parentLoader = Port.class.getClassLoader();
+    private static final ClassLoader parentLoader = Main.getRootClassLoader();
     private Port(String path, InetAddress bindTo, int port, ThreadPool tp) { 
         super(new File(path), parentLoader);
         this.bindTo = bindTo; this.port = port; this.tp = tp; }
index 20d2d84..d7b4f5e 100644 (file)
@@ -19,7 +19,6 @@ public class TreeClassLoader extends URLClassLoader {
 
     public TreeClassLoader(File root, ClassLoader parent) {
         super(new URL[] { }, parent);
-       System.out.println("TreeClassLoader("+root.getAbsolutePath()+")");
         this.root = root;
         this.lib = new File(root.getAbsolutePath() + File.separatorChar + "lib");
     }