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

java.lang.Objectorg.xsocket.connection.NonBlockingConnectionPool
public final class NonBlockingConnectionPool
A connection pool implementation.
 
 This class is thread safe 
 
  // create a unbound connection pool
  NonBlockingConnectionPool pool = new NonBlockingConnectionPool();
  INonBlockingCinnection con = null;
  try {
     // retrieve a connection (if no connection is in pool, a new one will be created)
     con = pool.getNonBlockingConnection(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 | |
|---|---|
| NonBlockingConnectionPool()constructor | |
| NonBlockingConnectionPool(SSLContext sslContext)constructor | |
| Method Summary | |
|---|---|
|  void | addListener(ILifeCycle listener)adds a listener | 
|  void | close() | 
|  void | destroy()destroy the pool by killing idle and active connections | 
| static void | destroy(INonBlockingConnection connection) | 
|  Integer | getAcquireTimeoutMillis()returns the acquire timeout. | 
|  List<String> | getActiveConnectionInfos()get a info list about the active connections | 
|  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 | 
|  INonBlockingConnection | getNonBlockingConnection(InetAddress address,
                         int port)get a pool connection for the given address. | 
|  INonBlockingConnection | getNonBlockingConnection(InetAddress address,
                         int port,
                         boolean isSSL)get a pool connection for the given address. | 
|  INonBlockingConnection | getNonBlockingConnection(InetAddress address,
                         int port,
                         boolean waitForConnect,
                         int connectTimeoutMillis,
                         boolean isSSL)get a pool connection for the given address. | 
|  INonBlockingConnection | getNonBlockingConnection(InetAddress address,
                         int port,
                         IHandler appHandler)get a pool connection for the given address. | 
|  INonBlockingConnection | getNonBlockingConnection(InetAddress address,
                         int port,
                         IHandler appHandler,
                         boolean isSSL)get a pool connection for the given address. | 
|  INonBlockingConnection | getNonBlockingConnection(InetAddress address,
                         int port,
                         IHandler appHandler,
                         boolean waitForConnect,
                         int connectTimeoutMillis)get a pool connection for the given address in an asynchronous wa. | 
|  INonBlockingConnection | getNonBlockingConnection(InetAddress address,
                         int port,
                         IHandler appHandler,
                         boolean waitForConnect,
                         int connectTimeoutMillis,
                         boolean isSSL)get a pool connection for the given address. | 
|  INonBlockingConnection | getNonBlockingConnection(InetAddress address,
                         int port,
                         IHandler appHandler,
                         Executor workerPool,
                         boolean waitForConnect,
                         int connectTimeoutMillis,
                         boolean isSSL)get a pool connection for the given address. | 
|  INonBlockingConnection | getNonBlockingConnection(InetAddress address,
                         int port,
                         IHandler appHandler,
                         Executor workerPool,
                         int connectTimeoutMillis)get a pool connection for the given address. | 
|  INonBlockingConnection | getNonBlockingConnection(InetAddress address,
                         int port,
                         IHandler appHandler,
                         Executor workerPool,
                         int connectTimeoutMillis,
                         boolean isSSL)get a pool connection for the given address. | 
|  INonBlockingConnection | getNonBlockingConnection(InetAddress address,
                         int port,
                         IHandler appHandler,
                         int connectTimeoutMillis)get a pool connection for the given address. | 
|  INonBlockingConnection | getNonBlockingConnection(InetAddress address,
                         int port,
                         IHandler appHandler,
                         int connectTimeoutMillis,
                         boolean isSSL)get a pool connection for the given address. | 
|  INonBlockingConnection | getNonBlockingConnection(InetAddress address,
                         int port,
                         int connectTimeoutMillis)get a pool connection for the given address. | 
|  INonBlockingConnection | getNonBlockingConnection(InetAddress address,
                         int port,
                         int connectTimeoutMillis,
                         boolean isSSL)get a pool connection for the given address. | 
|  INonBlockingConnection | getNonBlockingConnection(InetSocketAddress address)get a pool connection for the given address. | 
|  INonBlockingConnection | getNonBlockingConnection(String host,
                         int port)get a pool connection for the given address. | 
|  INonBlockingConnection | getNonBlockingConnection(String host,
                         int port,
                         boolean isSSL)get a pool connection for the given address. | 
|  INonBlockingConnection | getNonBlockingConnection(String host,
                         int port,
                         IHandler appHandler)get a pool connection for the given address. | 
|  INonBlockingConnection | getNonBlockingConnection(String host,
                         int port,
                         IHandler appHandler,
                         boolean isSSL)get a pool connection for the given address. | 
|  INonBlockingConnection | getNonBlockingConnection(String host,
                         int port,
                         int connectTimeoutMillis)get a pool connection for the given address. | 
|  INonBlockingConnection | getNonBlockingConnection(String host,
                         int port,
                         int connectTimeoutMillis,
                         boolean isSSL)get a pool connection for the given address. | 
|  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 | getNumRejectedConnections() | 
|  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 | 
|  Executor | getWorkerpool()get the worker pool which will be assigned to the connections for call back handling | 
|  boolean | isOpen()returns true, is pool is open | 
|  boolean | removeListener(ILifeCycle listener)removes a listener | 
|  void | setAcquireTimeoutMillis(Integer aquireTimeoutMillis)sets the acquire time out. | 
|  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 | 
|  void | setWorkerpool(Executor workerpool)set the worker pool which will be assigned to the connections for call back handling | 
|  String | toString() | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait | 
| Constructor Detail | 
|---|
public NonBlockingConnectionPool()
public NonBlockingConnectionPool(SSLContext sslContext)
sslContext - the ssl context or null if ssl should not be used| Method Detail | 
|---|
public INonBlockingConnection getNonBlockingConnection(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 INonBlockingConnection getNonBlockingConnection(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 occurs
MaxConnectionsExceededException - if the max number of active connections (per server) is reached
public INonBlockingConnection getNonBlockingConnection(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 INonBlockingConnection getNonBlockingConnection(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 INonBlockingConnection getNonBlockingConnection(InetSocketAddress address)
                                                throws IOException,
                                                       SocketTimeoutException,
                                                       MaxConnectionsExceededException
address - the server address
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 INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port)
                                                throws IOException,
                                                       SocketTimeoutException,
                                                       MaxConnectionsExceededException
address - the server addressport - the sever 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 INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port,
                                                       boolean isSSL)
                                                throws IOException,
                                                       SocketTimeoutException,
                                                       MaxConnectionsExceededException
address - the server addressport - the sever 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 INonBlockingConnection getNonBlockingConnection(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 INonBlockingConnection getNonBlockingConnection(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 reached
public INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port,
                                                       boolean waitForConnect,
                                                       int connectTimeoutMillis,
                                                       boolean isSSL)
                                                throws IOException,
                                                       SocketTimeoutException,
                                                       MaxConnectionsExceededException
address - the server addressport - the server portwaitForConnect - true, if the call should block until the connection is establishedconnectTimeoutMillis - 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 INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port,
                                                       IHandler appHandler)
                                                throws IOException,
                                                       SocketTimeoutException,
                                                       MaxConnectionsExceededException
address - the server addressport - the server portappHandler - the application handler (supported: IConnectHandler, IDisconnectHandler, IDataHandler, IIdleTimeoutHandler and IConnectionTimeoutHandler)
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 INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port,
                                                       IHandler appHandler,
                                                       boolean isSSL)
                                                throws IOException,
                                                       SocketTimeoutException,
                                                       MaxConnectionsExceededException
address - the server addressport - the server portappHandler - the application handler (supported: IConnectHandler, IDisconnectHandler, IDataHandler, IIdleTimeoutHandler and IConnectionTimeoutHandler)isSSL - 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 INonBlockingConnection getNonBlockingConnection(String host,
                                                       int port,
                                                       IHandler appHandler)
                                                throws IOException,
                                                       SocketTimeoutException,
                                                       MaxConnectionsExceededException
host - the server addressport - the server portappHandler - the application handler (supported: IConnectHandler, IDisconnectHandler, IDataHandler, IIdleTimeoutHandler and IConnectionTimeoutHandler)
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 INonBlockingConnection getNonBlockingConnection(String host,
                                                       int port,
                                                       IHandler appHandler,
                                                       boolean isSSL)
                                                throws IOException,
                                                       SocketTimeoutException,
                                                       MaxConnectionsExceededException
host - the server addressport - the server portappHandler - the application handler (supported: IConnectHandler, IDisconnectHandler, IDataHandler, IIdleTimeoutHandler and IConnectionTimeoutHandler)isSSL - 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 INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port,
                                                       IHandler appHandler,
                                                       int connectTimeoutMillis)
                                                throws IOException,
                                                       SocketTimeoutException,
                                                       MaxConnectionsExceededException
address - the server addressport - the server portappHandler - the application handler (supported: IConnectHandler, IDisconnectHandler, IDataHandler, IIdleTimeoutHandler and IConnectionTimeoutHandler)connectTimeoutMillis - the connection creation 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 INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port,
                                                       IHandler appHandler,
                                                       boolean waitForConnect,
                                                       int connectTimeoutMillis)
                                                throws IOException,
                                                       SocketTimeoutException,
                                                       MaxConnectionsExceededException
address - the server addressport - the server portappHandler - the application handler (supported: IConnectHandler, IDisconnectHandler, IDataHandler, IIdleTimeoutHandler and IConnectionTimeoutHandler)waitForConnect - true, if the method should block until the connection is establishedconnectTimeoutMillis - the connection creation 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 INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port,
                                                       IHandler appHandler,
                                                       int connectTimeoutMillis,
                                                       boolean isSSL)
                                                throws IOException,
                                                       SocketTimeoutException,
                                                       MaxConnectionsExceededException
address - the server addressport - the server portappHandler - the application handler (supported: IConnectHandler, IDisconnectHandler, IDataHandler, IIdleTimeoutHandler and IConnectionTimeoutHandler)connectTimeoutMillis - the connection creation 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 INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port,
                                                       IHandler appHandler,
                                                       boolean waitForConnect,
                                                       int connectTimeoutMillis,
                                                       boolean isSSL)
                                                throws IOException,
                                                       SocketTimeoutException,
                                                       MaxConnectionsExceededException
address - the server addressport - the server portappHandler - the application handler (supported: IConnectHandler, IDisconnectHandler, IDataHandler, IIdleTimeoutHandler and IConnectionTimeoutHandler)waitForConnect - true, if the method should block until the connection is establishedconnectTimeoutMillis - the connection creation 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 INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port,
                                                       IHandler appHandler,
                                                       Executor workerPool,
                                                       int connectTimeoutMillis)
                                                throws IOException,
                                                       SocketTimeoutException,
                                                       MaxConnectionsExceededException
address - the server addressport - the sever portappHandler - the application handler (supported: IConnectHandler, IDisconnectHandler, IDataHandler, IIdleTimeoutHandler and ConnectionTimeoutHandler)workerPool - the worker pool to useconnectTimeoutMillis - the connection creation 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 INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port,
                                                       IHandler appHandler,
                                                       Executor workerPool,
                                                       int connectTimeoutMillis,
                                                       boolean isSSL)
                                                throws IOException,
                                                       SocketTimeoutException,
                                                       MaxConnectionsExceededException
address - the server addressport - the sever portappHandler - the application handler (supported: IConnectHandler, IDisconnectHandler, IDataHandler, IIdleTimeoutHandler and ConnectionTimeoutHandler)workerPool - the worker pool to useconnectTimeoutMillis - the connection creation 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 INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port,
                                                       IHandler appHandler,
                                                       Executor workerPool,
                                                       boolean waitForConnect,
                                                       int connectTimeoutMillis,
                                                       boolean isSSL)
                                                throws IOException,
                                                       SocketTimeoutException,
                                                       MaxConnectionsExceededException
address - the server addressport - the sever portappHandler - the application handler (supported: IConnectHandler, IDisconnectHandler, IDataHandler, IIdleTimeoutHandler and ConnectionTimeoutHandler)workerPool - the worker pool to usewaitForConnect - true, if the method should block until the connection is establishedconnectTimeoutMillis - the connection creation 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 boolean isOpen()
isOpen in interface IConnectionPoolpublic void close()
close in interface Closeablepublic void destroy()
public 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 void setWorkerpool(Executor workerpool)
workerpool - the worker poolpublic Executor getWorkerpool()
public int getMaxActive()
getMaxActive in interface IConnectionPoolpublic int getNumRejectedConnections()
public 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 Integer getAcquireTimeoutMillis()
public void setAcquireTimeoutMillis(Integer aquireTimeoutMillis)
aquireTimeoutMillis - the acquire timeout or nullpublic List<String> getActiveConnectionInfos()
IConnectionPool
getActiveConnectionInfos in interface IConnectionPoolpublic List<String> getIdleConnectionInfos()
IConnectionPool
getIdleConnectionInfos in interface IConnectionPoolpublic int getNumIdle()
getNumIdle 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 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 getNumPendingGet()
public static void destroy(INonBlockingConnection connection)
                    throws IOException
IOExceptionpublic String toString()
toString in class Object| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||