- 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;
- }
+
+ void dispatch(final Connection conn) throws Exception {
+ new Thread(tg, new Runnable() { public void run() {
+ String local = conn.getLocalAddress() + ":" + conn.getLocalPort();
+ String remote = conn.getRemoteHostname() + ":" + conn.getRemotePort();
+ try {
+ Class c = findListener();
+ if (c == null) throw new RuntimeException("couldn't find listener");
+ Log.info("["+local+"]", "connection from " + remote + " => " + c.getName());
+ Log.clearnotes();
+ final ClassLoader cl = getClassLoader();
+ Thread.currentThread().setContextClassLoader(cl);
+ 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();