| 
 | ||||||||||
| 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 | |
|---|---|
| protected static int | MAX_SIZE | 
| protected static int | MAX_TIMEOUT | 
| protected static long | MIN_CHECKPERIOD_MILLIS | 
| 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_IDLE, DEFAULT_MAX_WAIT_MILLIS | 
| Constructor Summary | |
|---|---|
| NonBlockingConnectionPool()constructor | |
| NonBlockingConnectionPool(SSLContext sslContext)constructor | |
| Method Summary | |
|---|---|
|  void | addListener(ILifeCycle listener)adds a listener | 
|  void | close() | 
| static void | destroy(INonBlockingConnection connection) | 
|  List<String> | getActiveConnectionInfos()get a info list about the active connections | 
|  long | getCreationMaxWaitMillis()get the max waiting by retrieving a resource | 
|  List<String> | getIdleConnectionInfos()get a info list about the idle connections | 
|  int | getMaxActive()return the number of max active resources | 
|  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,
                         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,
                         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(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 | getNumTimeoutConnectionIdle() | 
|  int | getNumTimeoutConnectionLifetime() | 
|  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 | setCreationMaxWaitMillis(long maxWaitMillis)set the max waiting by retrieving a resource | 
|  void | setMaxActive(int maxActive)set the number of max active resources | 
|  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 | 
| Field Detail | 
|---|
protected static final long MIN_CHECKPERIOD_MILLIS
protected static final int MAX_SIZE
protected static final int MAX_TIMEOUT
| 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
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
public INonBlockingConnection getNonBlockingConnection(String host,
                                                       int port,
                                                       boolean isSSL)
                                                throws IOException,
                                                       SocketTimeoutException
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
public INonBlockingConnection getNonBlockingConnection(String host,
                                                       int port,
                                                       int connectTimeoutMillis)
                                                throws IOException,
                                                       SocketTimeoutException
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
public INonBlockingConnection getNonBlockingConnection(String host,
                                                       int port,
                                                       int connectTimeoutMillis,
                                                       boolean isSSL)
                                                throws IOException,
                                                       SocketTimeoutException
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
public INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port)
                                                throws IOException,
                                                       SocketTimeoutException
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
public INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port,
                                                       boolean isSSL)
                                                throws IOException,
                                                       SocketTimeoutException
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
public INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port,
                                                       int connectTimeoutMillis)
                                                throws IOException,
                                                       SocketTimeoutException
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
public INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port,
                                                       int connectTimeoutMillis,
                                                       boolean isSSL)
                                                throws IOException,
                                                       SocketTimeoutException
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
public INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port,
                                                       IHandler appHandler)
                                                throws IOException,
                                                       SocketTimeoutException
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
public INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port,
                                                       IHandler appHandler,
                                                       boolean isSSL)
                                                throws IOException,
                                                       SocketTimeoutException
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
public INonBlockingConnection getNonBlockingConnection(String host,
                                                       int port,
                                                       IHandler appHandler)
                                                throws IOException,
                                                       SocketTimeoutException
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
public INonBlockingConnection getNonBlockingConnection(String host,
                                                       int port,
                                                       IHandler appHandler,
                                                       boolean isSSL)
                                                throws IOException,
                                                       SocketTimeoutException
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
public INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port,
                                                       IHandler appHandler,
                                                       int connectTimeoutMillis)
                                                throws IOException,
                                                       SocketTimeoutException
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
public INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port,
                                                       IHandler appHandler,
                                                       int connectTimeoutMillis,
                                                       boolean isSSL)
                                                throws IOException,
                                                       SocketTimeoutException
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
public INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port,
                                                       IHandler appHandler,
                                                       Executor workerPool,
                                                       int connectTimeoutMillis)
                                                throws IOException,
                                                       SocketTimeoutException
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
public INonBlockingConnection getNonBlockingConnection(InetAddress address,
                                                       int port,
                                                       IHandler appHandler,
                                                       Executor workerPool,
                                                       int connectTimeoutMillis,
                                                       boolean isSSL)
                                                throws IOException,
                                                       SocketTimeoutException
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 occurspublic boolean isOpen()
isOpen in interface IConnectionPoolpublic 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 void setMaxActive(int maxActive)
setMaxActive in interface IConnectionPoolmaxActive - the number of max active resourcespublic long getCreationMaxWaitMillis()
getCreationMaxWaitMillis in interface IConnectionPoolpublic void setCreationMaxWaitMillis(long maxWaitMillis)
setCreationMaxWaitMillis in interface IConnectionPoolmaxWaitMillis - the max waiting by retrieving a resourcepublic int getMaxIdle()
getMaxIdle in interface IConnectionPoolpublic void setMaxIdle(int maxIdle)
setMaxIdle in interface IConnectionPoolpublic int getNumActive()
getNumActive in interface IConnectionPoolpublic 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 getNumTimeoutConnectionLifetime()
public int getNumTimeoutConnectionIdle()
public 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 final void close()
close in interface Closeablepublic String toString()
toString in class Object| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||