|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.emory.mathcs.util.net.ConnectionPool
Manages a pool of socket connections to a single network endpoint. Pooling enables reusing connections for multiple, unrelated data transfers, and it can be used to implement certain connection-based protocols like HTTP 1.1. Additionally, pooling can aid in controlling network load - limiting the maximum pool size causes excessive connection requests to be enqueued at the client side.
The endpoint is represented by a host name and a port number, as well as by an optional client socket factory, specified at the construction time. Client requests connections, use them, then return them to the pool. Clients should not close the socket associated with the connection or use the socket after returning connection to the pool. Upon a request for connection, the pool first tries to return a pre-existing idle one, creating a new connection only if none is available. Request may block if pool size limit is reached and all connections are in use. After being returned to the pool, if connection idles for longer than its expiration timeout, it is closed.
Example:
ConnectionPool pool = new ConnectionPool(host, port); ... Connection conn = pool.getConnection(); Socket socket = conn.getSocket(); try { socket.getOutputStream().write(0x00); ... conn.returnToPool(); } catch (IOException e) { conn.close(); }
Constructor Summary | |
ConnectionPool(java.lang.String hostName,
int port)
Creates a connection pool for a specified endpoint, using a default TCP/IP socket factory, a default expiration timeout of 15 s, and a default capacity of 10 connections. |
|
ConnectionPool(java.lang.String hostName,
int port,
long expirationTimeout,
int capacity)
Creates a connection pool for a specified endpoint, using specified expiration timeout and capacity and a default TCP/IP socket factory. |
|
ConnectionPool(java.lang.String hostName,
int port,
java.rmi.server.RMIClientSocketFactory socketFactory)
Creates a connection pool for a specified endpoint, using specified socket factory and a default expiration timeout of 15 s and a default capacity of 10 connections. |
|
ConnectionPool(java.lang.String hostName,
int port,
java.rmi.server.RMIClientSocketFactory socketFactory,
long expirationTimeout,
int capacity)
Creates a connection pool for a specified endpoint, using specified socket factory, expiration timeout, and capacity. |
Method Summary | |
Connection |
getConnection()
Requests a connection from the pool. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ConnectionPool(java.lang.String hostName, int port)
hostName
- remote host nameport
- remote portpublic ConnectionPool(java.lang.String hostName, int port, java.rmi.server.RMIClientSocketFactory socketFactory)
hostName
- remote host nameport
- remote portsocketFactory
- socket factory to use when creating new connectionspublic ConnectionPool(java.lang.String hostName, int port, long expirationTimeout, int capacity)
hostName
- remote host nameport
- remote portexpirationTimeout
- maximum connection idle timecapacity
- maximum number of active connectionspublic ConnectionPool(java.lang.String hostName, int port, java.rmi.server.RMIClientSocketFactory socketFactory, long expirationTimeout, int capacity)
hostName
- remote host nameport
- remote portsocketFactory
- socket factory to use when creating new connectionsexpirationTimeout
- maximum connection idle timecapacity
- maximum number of active connectionsMethod Detail |
public Connection getConnection() throws java.io.IOException, java.lang.InterruptedException
java.io.IOException
- if I/O error occurs
java.lang.InterruptedException
- if interrupted while waiting for
a connection
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |