KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > matuschek > http > connection > HttpConnectionPool


1 package net.matuschek.http.connection;
2
3 /*********************************************
4     Copyright (c) 2001 by Daniel Matuschek
5 *********************************************/

6
7 import java.io.IOException JavaDoc;
8 import java.net.InetAddress JavaDoc;
9
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   /**
40    * Sets the timeout for the HTTP connections
41    * @param connectionTimeout timeout in milliseconds
42    */

43   public void setConnectionTimeout(int connectionTimeout) {
44     this.connectionTimeout = connectionTimeout;
45   }
46
47   
48   /**
49    * Gets the timeout for the HTTP connections
50    * @return timeout in milliseconds
51    */

52   public int getConnectionTimeout() {
53     return this.connectionTimeout;
54   }
55   
56
57   /**
58    * Gets a connection to the given server and port. Opens a new
59    * connection or uses a connection from the pool if there is one
60    * for this address/port combination
61    *
62    * @param address the IP address to connect to
63    * @param port the port to connect to (usually 80 for HTTP)
64    * @return a HttpConnection object
65    * @exception IOException if the TCP socket connection could
66    * not be established or all slots are used
67    */

68   public abstract HttpConnection
69     getConnection(InetAddress JavaDoc addr, int port)
70     throws IOException JavaDoc ;
71
72
73   /**
74    * Gives back the given HttpConnection to the pool
75    */

76   public abstract void giveback(HttpConnection conn);
77 }
78
Popular Tags