- getClassLoader();
- String[] list = list();
- for(int i=0; i<list.length; i++) {
- if (!list[i].endsWith(".jar")) continue;
- //Log.warn(this, "checking " + (this.path + File.separatorChar + list[i]));
- File f = new File(this.path + File.separatorChar + list[i]);
- ZipInputStream zis = new ZipInputStream(new FileInputStream(f));
- for(ZipEntry ze = zis.getNextEntry(); ze != null; ze = zis.getNextEntry()) {
- String name = ze.getName();
- if (name.endsWith(".class"))
- dispatch(conn, name.substring(0, name.length() - ".class".length()).replace('/', '.'));
- }
- }
- check(conn, new File(getAbsolutePath() + File.separatorChar + "BIN"));
- }
-
- void check(Connection conn, File f) throws Exception {
- //Log.warn(this, "check(" + f.getAbsolutePath() + ")");
- if (!f.exists()) return;
- if (!f.isDirectory()) {
- if (!f.getAbsolutePath().endsWith(".class")) return;
- String name = f.getAbsolutePath().substring(getAbsolutePath().length() + 5);
- name = name.substring(0, name.length() - ".class".length()).replace(File.separatorChar, '.');
- dispatch(conn, name);
- } else {
- String[] list = f.list();
- for(int i=0; i<list.length; i++) check(conn, new File(f.getAbsolutePath() + File.separatorChar + list[i]));
- }
- }
- void dispatch(final Connection conn, String name) throws Exception {
- //Log.info(this, "attempting class " + name);
- try {
- Class c = getClassLoader().loadClass(name);
- if (c != null) {
- if (Listener.class.isAssignableFrom(c)) {
- Log.error(this, "dispatching connection on port " + port + " to " +
- c.getName());
- final Listener l = (Listener)c.newInstance();
- new Thread() { public void run() {
- Log.clearnotes();
- try {
- l.accept(conn);
- } catch (Exception e) {
- Log.error(l.getClass(), "Listener threw exception");
- Log.error(l.getClass(), e);
- } finally {
- conn.close();
- }
- } }.start();
- return;
- }
+ tp.appendTask(new Runnable() { public void run() {
+ String local = conn.getLocalAddress() + ":" + conn.getLocalPort();
+ String remote = conn.getRemoteHostname() + ":" + conn.getRemotePort();
+ try {
+ // FIXME FIXME
+ Class c = loadClass("org.ibex.mail.Main");
+ if (c == null) throw new RuntimeException("couldn't find listener");
+ Log.info("["+local+"]", "connection from " + remote + " => " + c.getName() + ":"+conn.getLocalPort());
+ Log.clearnotes();
+ Thread.currentThread().setContextClassLoader(Port.this);
+ Listener l = (Listener)c.newInstance();
+ l.accept(conn);
+ } catch (org.ibex.io.Stream.EOF eof) {
+ Log.warn(this, "end of stream reached handling connection from " +
+ conn.getRemoteHostname() + ":" + conn.getRemotePort());
+ } catch (Exception e) {
+ Log.error(this, e);
+ conn.close();
+ } finally {
+ conn.close();