From: Leif M. <lei...@ta...> - 2003-10-15 10:07:56
|
I would like to be able to subclass the actual Connection classes used by Jetty. This is necessary to be able to implement some profiling hooks used by my application. I was able to very easily implement this by simply adding createConnection methods to the various Listener implementations. It is then possible to extend the Listener and override the connection implementation. I have attached a patch that implements this. If it could be added for the next release, I would appreciate it. The modified files include: /src/org/mortbay/http/SocketListener.java /src/org/mortbay/http/ajp/AJP13Listener.java Thanks in advance. Leif cvs diff -u SocketListener.java Index: SocketListener.java =================================================================== RCS file: /cvsroot/jetty/Jetty/src/org/mortbay/http/SocketListener.java,v retrieving revision 1.31 diff -u -r1.31 SocketListener.java --- SocketListener.java 5 Oct 2003 23:46:21 -0000 1.31 +++ SocketListener.java 15 Oct 2003 10:05:48 -0000 @@ -175,12 +175,7 @@ public void handleConnection(Socket socket) throws IOException { - HttpConnection connection = - new HttpConnection(this, - socket.getInetAddress(), - socket.getInputStream(), - socket.getOutputStream(), - socket); + HttpConnection connection = createConnection(socket); try { @@ -202,6 +197,21 @@ } connection.handle(); + } + + /* ------------------------------------------------------------ */ + /** Create an HttpConnection instance. This method can be used to + * override the connection instance. + * @param socket The underlying socket. + */ + protected HttpConnection createConnection(Socket socket) + throws IOException + { + return new HttpConnection(this, + socket.getInetAddress(), + socket.getInputStream(), + socket.getOutputStream(), + socket); } /* ------------------------------------------------------------ */ cvs diff -u AJP13Listener.java Index: AJP13Listener.java =================================================================== RCS file: /cvsroot/jetty/Jetty/src/org/mortbay/http/ajp/AJP13Listener.java,v retrieving revision 1.15 diff -u -r1.15 AJP13Listener.java --- AJP13Listener.java 18 Sep 2003 13:29:22 -0000 1.15 +++ AJP13Listener.java 15 Oct 2003 10:06:48 -0000 @@ -196,14 +196,24 @@ // Handle the connection socket.setTcpNoDelay(true); socket.setSoTimeout(getMaxIdleTimeMs()); - AJP13Connection connection= - new AJP13Connection(this, - socket.getInputStream(), - socket.getOutputStream(), - socket, - getBufferSize()); + AJP13Connection connection = createConnection(socket); try{connection.handle();} finally{connection.destroy();} + } + + /* ------------------------------------------------------------ */ + /** Create an AJP13Connection instance. This method can be used to + * override the connection instance. + * @param socket The underlying socket. + */ + protected AJP13Connection createConnection(Socket socket) + throws IOException + { + return new AJP13Connection(this, + socket.getInputStream(), + socket.getOutputStream(), + socket, + getBufferSize()); } /* ------------------------------------------------------------ */ |