01: package net.matuschek.http.connection;
02:
03: /*********************************************
04: Copyright (c) 2001 by Daniel Matuschek
05: *********************************************/
06:
07: import java.io.IOException;
08: import java.net.InetAddress;
09:
10: /**
11: * This class implements an connection pool for HTTP TCP connections.
12: * Actually, it doesn't pool, but this will be implemented in the next
13: * time.
14: *
15: * @author Daniel Matuschek
16: * @version $Id: HttpConnectionPool.java,v 1.4 2001/04/20 16:12:42 matuschd Exp $
17: */
18: public abstract class HttpConnectionPool {
19:
20: /** default timeout in milliseconds (60 seconds) */
21: private static int DEFAULT_TIMEOUT = 60000;
22:
23: /** the HttpConnections */
24: HttpConnection connections[];
25:
26: /** TCP socket timeout (for connect and read/write) */
27: int connectionTimeout = DEFAULT_TIMEOUT;
28:
29: /**
30: * Creates a new HTTP connection pool
31: *
32: * @param maxConnections maximal number of open connections
33: */
34: public HttpConnectionPool(int maxConnections) {
35: connections = new HttpConnection[maxConnections];
36: }
37:
38: /**
39: * Sets the timeout for the HTTP connections
40: * @param connectionTimeout timeout in milliseconds
41: */
42: public void setConnectionTimeout(int connectionTimeout) {
43: this .connectionTimeout = connectionTimeout;
44: }
45:
46: /**
47: * Gets the timeout for the HTTP connections
48: * @return timeout in milliseconds
49: */
50: public int getConnectionTimeout() {
51: return this .connectionTimeout;
52: }
53:
54: /**
55: * Gets a connection to the given server and port. Opens a new
56: * connection or uses a connection from the pool if there is one
57: * for this address/port combination
58: *
59: * @param address the IP address to connect to
60: * @param port the port to connect to (usually 80 for HTTP)
61: * @return a HttpConnection object
62: * @exception IOException if the TCP socket connection could
63: * not be established or all slots are used
64: */
65: public abstract HttpConnection getConnection(InetAddress addr,
66: int port) throws IOException;
67:
68: /**
69: * Gives back the given HttpConnection to the pool
70: */
71: public abstract void giveback(HttpConnection conn);
72: }
|