1 package org.jcomponent.netserve.connection.handlers;
2
3 import java.net.Socket;
4 import org.jcomponent.netserve.connection.ConnectionHandler;
5
6 /***
7 * A handler that allows user to handle ConnectionHandlers.
8 * Subclasses may pool or create transient handlers etc.
9 */
10 public abstract class ManagedRequestHandler
11 extends AbstractRequestHandler
12 {
13 /***
14 * Actually handle the request.
15 * Assume that the caller will gracefully
16 * handle unexpected exceptions and shutdown
17 * the socket when this method returns.
18 *
19 * @param socket the socket
20 * @throws Exception if an erro roccurs
21 */
22 protected void doPerformRequest( final Socket socket )
23 throws Exception
24 {
25 final ConnectionHandler handler = aquireHandler( socket );
26 try
27 {
28 handler.handleConnection( socket );
29 }
30 finally
31 {
32 releaseHandler( handler );
33 }
34 }
35
36 /***
37 * Retrieve the underlying handler.
38 *
39 * @param socket the socket
40 * @return the ConnectionHandler
41 */
42 protected abstract ConnectionHandler aquireHandler( Socket socket );
43
44 /***
45 * Release the underlying handler.
46 *
47 * @param handler the handler
48 */
49 protected abstract void releaseHandler( ConnectionHandler handler );
50 }
This page was automatically generated by Maven