KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > spice > netserve > connection > handlers > ManagedRequestHandler


1 package org.codehaus.spice.netserve.connection.handlers;
2
3 import java.net.Socket JavaDoc;
4 import org.codehaus.spice.netserve.connection.RequestHandler;
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 JavaDoc socket )
23         throws Exception JavaDoc
24     {
25         final RequestHandler 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 RequestHandler
41      */

42     protected abstract RequestHandler aquireHandler( Socket JavaDoc socket );
43
44     /**
45      * Release the underlying handler.
46      *
47      * @param handler the handler
48      */

49     protected abstract void releaseHandler( RequestHandler handler );
50 }
51
Popular Tags