| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||

java.lang.Objectorg.xsocket.connection.BlockingConnectionPool
public final class BlockingConnectionPool
A blocking connection pool implementation.  
 
 
 This class is thread safe 
 
  // create a unbound connection pool 
  BlockingConnectionPool pool = new BlockingConnectionPool();
  IBlockingConnection con = null;
  try {
     // retrieve a connection (if no connection is in pool, a new one will be created)
     con = pool.getBlockingConnection(host, port);
     con.write("Hello");
     ...
     // always close the connection! (the connection will be returned into the connection pool)
     con.close();
        } catch (IOException e) {
     if (con != null) {
        try {
          // if the connection is invalid -> destroy it (it will not return into the pool)
          pool.destroy(con);
        } catch (Exception ignore) { }
     }
  }
 
| Field Summary | 
|---|
| Fields inherited from interface org.xsocket.connection.IConnectionPool | 
|---|
| DEFAULT_CREATION_TIMEOUT_MILLIS, DEFAULT_IDLE_TIMEOUT_MILLIS, DEFAULT_LIFE_TIMEOUT_MILLIS, DEFAULT_MAX_ACTIVE, DEFAULT_MAX_ACTIVE_PER_SERVER, DEFAULT_MAX_IDLE, DEFAULT_MAX_WAIT_MILLIS, DEFAULT_MAX_WAITING | 
| Constructor Summary | |
|---|---|
| BlockingConnectionPool()constructor | |
| BlockingConnectionPool(SSLContext sslContext)constructor | |
| Method Summary | |
|---|---|
|  void | addListener(ILifeCycle listener)adds a listener | 
|  void | close() | 
|  void | destroy(IBlockingConnection resource) | 
|  List<String> | getActiveConnectionInfos()get a info list about the active connections | 
|  IBlockingConnection | getBlockingConnection(InetAddress address,
                      int port)get a pool connection for the given address. | 
|  IBlockingConnection | getBlockingConnection(InetAddress address,
                      int port,
                      boolean isSSL)get a pool connection for the given address. | 
|  IBlockingConnection | getBlockingConnection(InetAddress address,
                      int port,
                      int connectTimeoutMillis)get a pool connection for the given address. | 
|  IBlockingConnection | getBlockingConnection(InetAddress address,
                      int port,
                      int connectTimeoutMillis,
                      boolean isSSL)get a pool connection for the given address. | 
|  IBlockingConnection | getBlockingConnection(String host,
                      int port)get a pool connection for the given address. | 
|  IBlockingConnection | getBlockingConnection(String host,
                      int port,
                      boolean isSSL)get a pool connection for the given address. | 
|  IBlockingConnection | getBlockingConnection(String host,
                      int port,
                      int connectTimeoutMillis)get a pool connection for the given address. | 
|  IBlockingConnection | getBlockingConnection(String host,
                      int port,
                      int connectTimeoutMillis,
                      boolean isSSL)get a pool connection for the given address. | 
|  List<String> | getIdleConnectionInfos()get a info list about the idle connections | 
|  int | getMaxActive()return the number of max active resources | 
|  int | getMaxActivePerServer()return the number of max active resources per server | 
|  int | getMaxIdle()get the number of max idling resources | 
|  int | getNumActive()get the current number of the active resources | 
|  int | getNumCreated()get the number of the created resources | 
|  int | getNumCreationError()get the number of the creation errors | 
|  int | getNumDestroyed()get the number of the destroyed resources | 
|  int | getNumIdle()get the current number of idling resources | 
|  int | getNumPendingGet()get the current number of pending get operations to retrieve a resource | 
|  int | getNumTimeoutPooledMaxIdleTime()get the number of timeouts caused by the pool idle timeout | 
|  int | getNumTimeoutPooledMaxLifeTime()get the number of timeouts caused by the pool life timeout | 
|  int | getPooledMaxIdleTimeMillis()get the idle time out | 
|  int | getPooledMaxLifeTimeMillis()get the life timeout of a resource | 
|  boolean | isOpen()returns true, is pool is open | 
|  boolean | removeListener(ILifeCycle listener)removes a listener | 
|  void | setMaxActive(int maxActive)set the number of max active resources | 
|  void | setMaxActivePerServer(int maxActivePerServer)set the number of max active resources per server | 
|  void | setMaxIdle(int maxIdle)set the number of max idling resources | 
|  void | setPooledMaxIdleTimeMillis(int idleTimeoutMillis)set the idle time out of a resource within the pool | 
|  void | setPooledMaxLifeTimeMillis(int lifeTimeoutMillis)set the life timeout of a resource | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Constructor Detail | 
|---|
public BlockingConnectionPool()
public BlockingConnectionPool(SSLContext sslContext)
sslContext - the ssl context or null if ssl should not be used| Method Detail | 
|---|
public boolean isOpen()
isOpen in interface IConnectionPool
public IBlockingConnection getBlockingConnection(String host,
                                                 int port)
                                          throws IOException,
                                                 SocketTimeoutException,
                                                 MaxConnectionsExceededException
host - the server addressport - the server port
SocketTimeoutException - if the wait timeout has been reached (this will only been thrown if wait time has been set)
IOException - if an exception occurs
MaxConnectionsExceededException - if the max number of active connections (per server) is reached
public IBlockingConnection getBlockingConnection(String host,
                                                 int port,
                                                 boolean isSSL)
                                          throws IOException,
                                                 SocketTimeoutException,
                                                 MaxConnectionsExceededException
host - the server addressport - the server portisSSL - true, if ssl connection
SocketTimeoutException - if the wait timeout has been reached (this will only been thrown if wait time has been set)
IOException - if an exception occur
MaxConnectionsExceededException - if the max number of active connections (per server) is reached
public IBlockingConnection getBlockingConnection(String host,
                                                 int port,
                                                 int connectTimeoutMillis)
                                          throws IOException,
                                                 SocketTimeoutException,
                                                 MaxConnectionsExceededException
host - the server addressport - the server portconnectTimeoutMillis - the connection timeout
SocketTimeoutException - if the wait timeout has been reached (this will only been thrown if wait time has been set)
IOException - if an exception occurs
MaxConnectionsExceededException - if the max number of active connections (per server) is reached
public IBlockingConnection getBlockingConnection(String host,
                                                 int port,
                                                 int connectTimeoutMillis,
                                                 boolean isSSL)
                                          throws IOException,
                                                 SocketTimeoutException,
                                                 MaxConnectionsExceededException
host - the server addressport - the server portconnectTimeoutMillis - the connection timeoutisSSL - true, if ssl connection
SocketTimeoutException - if the wait timeout has been reached (this will only been thrown if wait time has been set)
IOException - if an exception occurs
MaxConnectionsExceededException - if the max number of active connections (per server) is reached
public IBlockingConnection getBlockingConnection(InetAddress address,
                                                 int port)
                                          throws IOException,
                                                 SocketTimeoutException,
                                                 MaxConnectionsExceededException
address - the server addressport - the server port
SocketTimeoutException - if the wait timeout has been reached (this will only been thrown if wait time has been set)
IOException - if an exception occurs
MaxConnectionsExceededException - if the max number of active connections (per server) is reached
public IBlockingConnection getBlockingConnection(InetAddress address,
                                                 int port,
                                                 boolean isSSL)
                                          throws IOException,
                                                 SocketTimeoutException,
                                                 MaxConnectionsExceededException
address - the server addressport - the server portisSSL - true, if ssl connection
SocketTimeoutException - if the wait timeout has been reached (this will only been thrown if wait time has been set)
IOException - if an exception occurs
MaxConnectionsExceededException - if the max number of active connections (per server) is reached
public IBlockingConnection getBlockingConnection(InetAddress address,
                                                 int port,
                                                 int connectTimeoutMillis)
                                          throws IOException,
                                                 SocketTimeoutException,
                                                 MaxConnectionsExceededException
address - the server addressport - the server portconnectTimeoutMillis - the connection timeout
SocketTimeoutException - if the wait timeout has been reached (this will only been thrown if wait time has been set)
IOException - if an exception occurs
MaxConnectionsExceededException - if the max number of active connections (per server) is reached
public IBlockingConnection getBlockingConnection(InetAddress address,
                                                 int port,
                                                 int connectTimeoutMillis,
                                                 boolean isSSL)
                                          throws IOException,
                                                 SocketTimeoutException,
                                                 MaxConnectionsExceededException
address - the server addressport - the server portconnectTimeoutMillis - the connection timeoutisSSL - true, if ssl connection
SocketTimeoutException - if the wait timeout has been reached (this will only been thrown if wait time has been set)
IOException - if an exception occurs
MaxConnectionsExceededException - if the max number of active connections (per server) is reachedpublic void addListener(ILifeCycle listener)
addListener in interface IConnectionPoollistener - the listener to addpublic boolean removeListener(ILifeCycle listener)
removeListener in interface IConnectionPoollistener - the listener to remove
public int getPooledMaxIdleTimeMillis()
getPooledMaxIdleTimeMillis in interface IConnectionPoolpublic void setPooledMaxIdleTimeMillis(int idleTimeoutMillis)
setPooledMaxIdleTimeMillis in interface IConnectionPoolidleTimeoutMillis - the idle time outpublic int getPooledMaxLifeTimeMillis()
getPooledMaxLifeTimeMillis in interface IConnectionPoolpublic void setPooledMaxLifeTimeMillis(int lifeTimeoutMillis)
setPooledMaxLifeTimeMillis in interface IConnectionPoolpublic int getMaxActive()
getMaxActive in interface IConnectionPoolpublic void setMaxActive(int maxActive)
setMaxActive in interface IConnectionPoolmaxActive - the number of max active resourcespublic void setMaxActivePerServer(int maxActivePerServer)
setMaxActivePerServer in interface IConnectionPoolpublic int getMaxActivePerServer()
getMaxActivePerServer in interface IConnectionPoolpublic int getMaxIdle()
getMaxIdle in interface IConnectionPoolpublic void setMaxIdle(int maxIdle)
setMaxIdle in interface IConnectionPoolpublic int getNumActive()
getNumActive in interface IConnectionPoolpublic int getNumIdle()
getNumIdle in interface IConnectionPoolpublic List<String> getActiveConnectionInfos()
getActiveConnectionInfos in interface IConnectionPoolpublic List<String> getIdleConnectionInfos()
getIdleConnectionInfos in interface IConnectionPoolpublic int getNumCreated()
getNumCreated in interface IConnectionPoolpublic int getNumCreationError()
public int getNumDestroyed()
getNumDestroyed in interface IConnectionPoolpublic int getNumTimeoutPooledMaxIdleTime()
getNumTimeoutPooledMaxIdleTime in interface IConnectionPoolpublic int getNumTimeoutPooledMaxLifeTime()
getNumTimeoutPooledMaxLifeTime in interface IConnectionPoolpublic int getNumPendingGet()
public void close()
close in interface Closeable
public void destroy(IBlockingConnection resource)
             throws IOException
IOException| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||