01: /*
02: * Copyright 2003-2006 Rick Knowles <winstone-devel at lists sourceforge net>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: */
07: package winstone;
08:
09: import java.io.IOException;
10: import java.io.InputStream;
11: import java.io.OutputStream;
12: import java.net.Socket;
13: import java.net.SocketException;
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 socket,
41: InputStream inSocket, OutputStream outSocket,
42: RequestHandlerThread handler, boolean iAmFirst)
43: throws SocketException, IOException;
44:
45: /**
46: * Called by the request handler thread, because it needs specific shutdown
47: * code for this connection's protocol (ie releasing input/output streams,
48: * etc).
49: */
50: public void deallocateRequestResponse(RequestHandlerThread handler,
51: WinstoneRequest req, WinstoneResponse rsp,
52: WinstoneInputStream inData, WinstoneOutputStream outData)
53: throws IOException;
54:
55: /**
56: * Called by the request handler thread, because it needs specific shutdown
57: * code for this connection's protocol if the keep-alive period expires (ie
58: * closing sockets, etc).The iAmFirst variable identifies whether or
59: * not this is the initial request on on this socket (ie a keep alive or
60: * a first-time accept)
61: */
62: public String parseURI(RequestHandlerThread handler,
63: WinstoneRequest req, WinstoneResponse rsp,
64: WinstoneInputStream inData, Socket socket, boolean iAmFirst)
65: throws IOException;
66:
67: /**
68: * Called by the request handler thread, because it needs specific shutdown
69: * code for this connection's protocol if the keep-alive period expires (ie
70: * closing sockets, etc).
71: */
72: public void releaseSocket(Socket socket, InputStream inSocket,
73: OutputStream outSocket) throws IOException;
74:
75: /**
76: * Tries to wait for extra requests on the same socket. If any are found
77: * before the timeout expires, it exits with a true, indicating a new
78: * request is waiting. If the timeout expires, return a false, instructing
79: * the handler thread to begin shutting down the socket and relase itself.
80: */
81: public boolean processKeepAlive(WinstoneRequest request,
82: WinstoneResponse response, InputStream inSocket)
83: throws IOException, InterruptedException;
84: }
|