|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectphp.java.servlet.ConnectionPool
public class ConnectionPool
A connection pool. Example:
ConnectionPool pool = new ConnectionPool("127.0.0.1", 8080, 20, 5000, new ConnectionPool.Factory());
ConnectionPool.Connection conn = pool.openConnection();
InputStream in = conn.getInputStream();
OutputStream out = conn.getOutputStream();
...
in.close();
out.close();
...
pool.destroy();
Instead of using delegation (decorator pattern), it is possible to pass a factory
which may create custom In- and OutputStreams. Example:
new ConnectionPool(..., new ConnectionPool.Factory() {
public InputStream getInputStream() {
return new ConnectionPool.DefaultInputStream() {
...
}
}
}
| Nested Class Summary | |
|---|---|
static class |
ConnectionPool.ConnectException
Thrown when the server is not available anymore |
class |
ConnectionPool.Connection
Represents the connection kept by the pool. |
static class |
ConnectionPool.ConnectionException
Thrown when an IO exception occurs |
static class |
ConnectionPool.DefaultInputStream
Default InputStream used by the connection pool. |
static class |
ConnectionPool.DefaultOutputStream
Default OutputStream used by the connection pool. |
static class |
ConnectionPool.Factory
In-/OutputStream factory. |
| Constructor Summary | |
|---|---|
ConnectionPool(java.lang.String host,
int port,
int limit,
int maxRequests,
ConnectionPool.Factory factory)
Create a new connection pool. |
|
| Method Summary | |
|---|---|
void |
destroy()
Destroy the connection pool. |
ConnectionPool.Connection |
openConnection()
Opens a connection to the back end. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ConnectionPool(java.lang.String host,
int port,
int limit,
int maxRequests,
ConnectionPool.Factory factory)
throws ConnectionPool.ConnectException
host - The hostport - The port numberlimit - The max. number of physical connectionsfactory - A factory for creating In- and OutputStreams.
ConnectionPool.ConnectExceptionConnectionPool.Factory| Method Detail |
|---|
public ConnectionPool.Connection openConnection()
throws java.lang.InterruptedException,
ConnectionPool.ConnectException,
java.net.SocketException
UnknownHostException
java.lang.InterruptedException
java.net.SocketException
java.io.IOException
ConnectionPool.ConnectExceptionpublic void destroy()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||