01: package org.codehaus.spice.netserve.connection.handlers;
02:
03: import java.net.Socket;
04: import org.codehaus.spice.netserve.connection.RequestHandler;
05:
06: /**
07: * A handler that allows user to handle ConnectionHandlers.
08: * Subclasses may pool or create transient handlers etc.
09: */
10: public abstract class ManagedRequestHandler extends
11: AbstractRequestHandler {
12: /**
13: * Actually handle the request.
14: * Assume that the caller will gracefully
15: * handle unexpected exceptions and shutdown
16: * the socket when this method returns.
17: *
18: * @param socket the socket
19: * @throws Exception if an erro roccurs
20: */
21: protected void doPerformRequest(final Socket socket)
22: throws Exception {
23: final RequestHandler handler = aquireHandler(socket);
24: try {
25: handler.handleConnection(socket);
26: } finally {
27: releaseHandler(handler);
28: }
29: }
30:
31: /**
32: * Retrieve the underlying handler.
33: *
34: * @param socket the socket
35: * @return the RequestHandler
36: */
37: protected abstract RequestHandler aquireHandler(Socket socket);
38:
39: /**
40: * Release the underlying handler.
41: *
42: * @param handler the handler
43: */
44: protected abstract void releaseHandler(RequestHandler handler);
45: }
|