From: adam Date: Sun, 20 Mar 2005 22:52:39 +0000 (+0000) Subject: cleanup X-Git-Url: http://git.megacz.com/?p=org.ibex.jinetd.git;a=commitdiff_plain;h=501b9089d3cf777fc417d9bcddba9bc542a086f9 cleanup darcs-hash:20050320225239-5007d-cae2a0eb6d050af575bfcee501752903bc3699a3.gz --- diff --git a/src/org/ibex/jinetd/Host.java b/src/org/ibex/jinetd/Host.java index 1b10beb..1a3dd3e 100644 --- a/src/org/ibex/jinetd/Host.java +++ b/src/org/ibex/jinetd/Host.java @@ -8,14 +8,14 @@ import java.io.*; import java.util.*; import java.lang.reflect.*; -public class Host extends Loader { +public class Host extends File { final String hostname; public Host(String path, String hostname) { super(path); this.hostname = hostname; } - public void changed(Watched w) { - super.changed(w); + public void changed(File f) { } /* + super.changed(w); Log.debug(this, "changed(" + w + ")"); try { ClassLoader cl = getClassLoader(); @@ -28,5 +28,4 @@ public class Host extends Loader { Log.warn(this, e); } */ - } } diff --git a/src/org/ibex/jinetd/Listener.java b/src/org/ibex/jinetd/Listener.java index 7fb4d72..a645cc6 100644 --- a/src/org/ibex/jinetd/Listener.java +++ b/src/org/ibex/jinetd/Listener.java @@ -13,6 +13,7 @@ import org.ibex.io.*; */ public interface Listener { - public void accept(Connection c); + /** returns false if the connection was not handled */ + public boolean accept(Connection c); } diff --git a/src/org/ibex/jinetd/Loader.java b/src/org/ibex/jinetd/Loader.java deleted file mode 100644 index 7f32fd6..0000000 --- a/src/org/ibex/jinetd/Loader.java +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2000-2005 the Contributors, as shown in the revision logs. -// Licensed under the Apache Public Source License 2.0 ("the License"). -// You may not use this file except in compliance with the License. - -package org.ibex.jinetd; -import org.ibex.io.*; -import org.ibex.util.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.net.*; -import java.util.zip.*; - -/** represents a file or directory which is scanned for updates */ -public class Loader extends Watcher { - - public /*synchronized*/ void scan() throws IOException { super.scan(); } - - private final TreeClassLoader classloader; - public synchronized ClassLoader getClassLoader() { return classloader; } - public Loader(String path) { this(path, Loader.class.getClassLoader()); } - public Loader(String path, ClassLoader parent) { super(path); classloader = new TreeClassLoader(this, parent); } - public void changed(Watched w) { /*FIXME*/ } - - private void fill(Vec vec, File dir) { - if (!dir.exists()) return; - if (!dir.isDirectory()) { - if (!dir.getPath().endsWith(".java")) return; - vec.addElement(dir.getAbsolutePath()); - } else { - String[] list = dir.list(); - for(int i=0; i 0) { - Log.warn(this, " annoying threads:"); - Thread[] annoying = new Thread[tg.activeCount()]; - tg.enumerate(annoying, true); - for(int i=0; i " + c.getName()); Log.clearnotes(); - Thread.currentThread().setContextClassLoader(cl); + Thread.currentThread().setContextClassLoader(Port.this); Listener l = (Listener)c.newInstance(); l.accept(conn); } catch (org.ibex.io.Stream.EOF eof) { @@ -68,17 +64,16 @@ public class Port extends Loader { public PortThread(InetAddress bindTo, int port) { this.bindTo = bindTo; this.port = port; } public void run() { try { - Log.warn(this, "Now listening on address " + (bindTo == null ? "all interfaces" : bindTo.toString()) + - ", port " + port); + Log.warn(this, "Now listening on address " + (bindTo==null?"all interfaces":bindTo.toString()) + ", port " + port); ServerSocket ss = bindTo == null ? new ServerSocket(port) : new ServerSocket(port, 0, bindTo); for(Socket s = ss.accept(); ; s = ss.accept()) try { - dispatch(new Connection(s, "megacz.com")); + dispatch(new Connection(s, Main.defaultDomain)); } catch (Exception e) { Log.warn(Port.class, e); } } catch (Exception e) { Log.error(Port.class, e); } catch (Throwable t) { Log.error(this, "serious error, aborting VM"); Log.error(this, t); - Root.reboot(); + Main.reboot(); } } } diff --git a/src/org/ibex/jinetd/Root.java b/src/org/ibex/jinetd/Root.java index 49bcf39..5dd7168 100644 --- a/src/org/ibex/jinetd/Root.java +++ b/src/org/ibex/jinetd/Root.java @@ -8,64 +8,59 @@ import java.io.*; import java.util.*; import java.net.*; -public class Root extends Loader { +public class Root extends Watcher { - public static String root = System.getProperty("jinetd.root", null); - - private final Host host; - private final Watched port; + private final PortDir port; private static final ThreadPool tp = new ThreadPool(10, 100); - public Root(String path) { + public Root(String path) throws IOException { super(path); - host = new Host(path + File.separatorChar + "host", null); + if (!new File(path + File.separatorChar + "host").exists()) new File(path + File.separatorChar + "host").mkdirs(); + if (!new File(path + File.separatorChar + "port").exists()) new File(path + File.separatorChar + "port").mkdirs(); port = new PortDir(path + File.separatorChar + "port"); + watch(path + File.separatorChar + "host"); + watch(path + File.separatorChar + "port"); + scan(); } - public Watched slash(String part) { - if (part.equals("host")) return host; - if (part.equals("port")) return port; - if (part.equals("LIB")) return super.slash(part); - if (part.endsWith(".jar")) return super.slash(part); - return null; - } - - public static void reboot() { - Log.flush(); - System.exit(0); - } - - public void changed(Watched w) { - if (w.part.equals("host")) { - Log.debug(this, "/host changed"); - } else if (w.part.equals("port")) { - Log.debug(this, "/port changed"); - } else if (w.getAbsolutePath().endsWith(".jar")) { + public void changed(File w) throws IOException { + if (w.getName().equals("host")) Log.debug(this, "/host changed"); + else if (w.getName().equals("port")) Log.debug(this, "/port changed"); + /* + else if (w.getAbsolutePath().endsWith(".jar")) { if (w.lastModifiedAtLastScan != -1) { Log.error(this, "jinetd upgraded; bouncing the JVM...."); - reboot(); - } - } else { - Log.debug(this, "unknown directory " + w.part + " changed"); - } + Main.reboot(); + } } + */ + else Log.debug(this, "unknown directory " + w.getAbsolutePath() + " changed"); } - private static class PortDir extends Watched { - public PortDir(String path) { super(path); } - public Watched slash(String part) { + private static class PortDir extends Watcher { + public PortDir(String path) throws IOException { + super(path); + String[] ports = new File(path).list(); + for(int i=0; i 0) { + Log.warn(this, " annoying threads:"); + Thread[] annoying = new Thread[tg.activeCount()]; + tg.enumerate(annoying, true); + for(int i=0; i=0; i--) + ((Watched)(watched.elementAt(i))).scan(); + } + + private class Watched extends File { + long lastModifiedAtLastScan = -1; + public Watched(String s) { super(s); } + public void scan() throws IOException { + // FIXME + //if (!exists()) { Watcher.this.changed(this); Watcher.this.watched.remove(this); return; } + if (lastModifiedAtLastScan != lastModified()) { Watcher.this.changed(this); lastModifiedAtLastScan = lastModified(); } + } + } } diff --git a/src/org/ibex/jinetd/Worker.java b/src/org/ibex/jinetd/Worker.java deleted file mode 100644 index 27c328c..0000000 --- a/src/org/ibex/jinetd/Worker.java +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2000-2005 the Contributors, as shown in the revision logs. -// Licensed under the Apache Public Source License 2.0 ("the License"). -// You may not use this file except in compliance with the License. - -package org.ibex.jinetd; -import org.ibex.util.*; -import org.ibex.io.*; -import java.net.*; -import java.io.*; -import java.util.*; - -public interface Worker { - public void handleRequest(Connection c); -} - - - -