KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > winstone > Listener


1 /*
2  * Copyright 2003-2006 Rick Knowles <winstone-devel at lists sourceforge net>
3  * Distributed under the terms of either:
4  * - the common development and distribution license (CDDL), v1.0; or
5  * - the GNU Lesser General Public License, v2.1 or later
6  */

7 package winstone;
8
9 import java.io.IOException JavaDoc;
10 import java.io.InputStream JavaDoc;
11 import java.io.OutputStream JavaDoc;
12 import java.net.Socket JavaDoc;
13 import java.net.SocketException JavaDoc;
14
15 /**
16  * Interface that defines the necessary methods for being a connection listener
17  * within winstone.
18  *
19  * @author <a HREF="mailto:rick_knowles@hotmail.com">Rick Knowles</a>
20  */

21 public interface Listener {
22     /**
23      * Interrupts the listener thread. This will trigger a listener shutdown
24      * once the so timeout has passed.
25      */

26     public void destroy();
27     
28     /**
29      * After the listener is loaded and initialized, this starts the thread
30      */

31     public boolean start();
32
33     /**
34      * Called by the request handler thread, because it needs specific setup
35      * code for this connection's protocol (ie construction of request/response
36      * objects, in/out streams, etc). The iAmFirst variable identifies whether or
37      * not this is the initial request on on this socket (ie a keep alive or
38      * a first-time accept)
39      */

40     public void allocateRequestResponse(Socket JavaDoc socket, InputStream JavaDoc inSocket,
41             OutputStream JavaDoc outSocket, RequestHandlerThread handler,
42             boolean iAmFirst) throws SocketException JavaDoc, IOException JavaDoc;
43
44     /**
45      * Called by the request handler thread, because it needs specific shutdown
46      * code for this connection's protocol (ie releasing input/output streams,
47      * etc).
48      */

49     public void deallocateRequestResponse(RequestHandlerThread handler,
50             WinstoneRequest req, WinstoneResponse rsp,
51             WinstoneInputStream inData, WinstoneOutputStream outData)
52             throws IOException JavaDoc;
53
54     /**
55      * Called by the request handler thread, because it needs specific shutdown
56      * code for this connection's protocol if the keep-alive period expires (ie
57      * closing sockets, etc).The iAmFirst variable identifies whether or
58      * not this is the initial request on on this socket (ie a keep alive or
59      * a first-time accept)
60      */

61     public String JavaDoc parseURI(RequestHandlerThread handler, WinstoneRequest req,
62             WinstoneResponse rsp, WinstoneInputStream inData, Socket JavaDoc socket,
63             boolean iAmFirst) throws IOException JavaDoc;
64
65     /**
66      * Called by the request handler thread, because it needs specific shutdown
67      * code for this connection's protocol if the keep-alive period expires (ie
68      * closing sockets, etc).
69      */

70     public void releaseSocket(Socket JavaDoc socket, InputStream JavaDoc inSocket,
71             OutputStream JavaDoc outSocket) throws IOException JavaDoc;
72
73     /**
74      * Tries to wait for extra requests on the same socket. If any are found
75      * before the timeout expires, it exits with a true, indicating a new
76      * request is waiting. If the timeout expires, return a false, instructing
77      * the handler thread to begin shutting down the socket and relase itself.
78      */

79     public boolean processKeepAlive(WinstoneRequest request,
80             WinstoneResponse response, InputStream JavaDoc inSocket)
81             throws IOException JavaDoc, InterruptedException JavaDoc;
82 }
83
Popular Tags