org.apache.http.pool

## Class AbstractConnPool<T,C,E extends PoolEntry<T,C>>

- java.lang.Object
- - org.apache.http.pool.AbstractConnPool<T,C,E>

- Type Parameters:
    `T` - the route type that represents the opposite endpoint of a pooled connection.
    `C` - the connection type.
    `E` - the type of the pool entry containing a pooled connection.
  All Implemented Interfaces:
    ConnPool<T,E>, ConnPoolControl<T>
  Direct Known Subclasses:
    BasicConnPool

      @ThreadSafe
      public abstract class AbstractConnPool<T,C,E extends PoolEntry<T,C>>
      extends Object
      implements ConnPool<T,E>, ConnPoolControl<T>

  Abstract synchronous (blocking) pool of connections.

  Please note that this class does not maintain its own pool of execution `Thread`s. Therefore, one must call `Future.get()` or `Future.get(long, TimeUnit)` method on the `Future` object returned by the `lease(Object, Object, FutureCallback)` method in order for the lease operation to complete.
  Since:
    4.2

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractConnPool(ConnFactory<T,C> connFactory, int defaultMaxPerRoute, int maxTotal)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `closeExpired()` Closes expired connections and evicts them from the pool.
    `void` | `closeIdle(long idletime, TimeUnit tunit)` Closes connections that have been idle longer than the given period of time and evicts them from the pool.
    `protected abstract E` | `createEntry(T route, C conn)` Creates a new entry for the given connection with the given route.
    `protected void` | `enumAvailable(PoolEntryCallback<T,C> callback)` Enumerates all available connections.
    `protected void` | `enumLeased(PoolEntryCallback<T,C> callback)` Enumerates all leased connections.
    `int` | `getDefaultMaxPerRoute()`
    `int` | `getMaxPerRoute(T route)`
    `int` | `getMaxTotal()`
    `PoolStats` | `getStats(T route)`
    `PoolStats` | `getTotalStats()`
    `boolean` | `isShutdown()`
    `Future<E>` | `lease(T route, Object state)` Attempts to lease a connection for the given route and with the given state from the pool.
    `Future<E>` | `lease(T route, Object state, FutureCallback<E> callback)` Attempts to lease a connection for the given route and with the given state from the pool.
    `protected void` | `onLease(E entry)`
    `protected void` | `onRelease(E entry)`
    `void` | `release(E entry, boolean reusable)` Releases the pool entry back to the pool.
    `void` | `setDefaultMaxPerRoute(int max)`
    `void` | `setMaxPerRoute(T route, int max)`
    `void` | `setMaxTotal(int max)`
    `void` | `shutdown()` Shuts down the pool.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### AbstractConnPool

          public AbstractConnPool(ConnFactory<T,C> connFactory,
                          int defaultMaxPerRoute,
                          int maxTotal)

  - ### Method Detail

    - #### createEntry

          protected abstract E createEntry(T route,
                      C conn)

      Creates a new entry for the given connection with the given route.

    - #### onLease

          protected void onLease(E entry)

      Since:
        4.3

    - #### onRelease

          protected void onRelease(E entry)

      Since:
        4.3

    - #### isShutdown

          public boolean isShutdown()

    - #### shutdown

          public void shutdown()
                        throws IOException

      Shuts down the pool.
      Throws:
        `IOException`

    - #### lease

          public Future<E> lease(T route,
                        Object state,
                        FutureCallback<E> callback)

      Attempts to lease a connection for the given route and with the given state from the pool.

      Please note that this class does not maintain its own pool of execution `Thread`s. Therefore, one must call `Future.get()` or `Future.get(long, TimeUnit)` method on the `Future` returned by this method in order for the lease operation to complete.
      Specified by:
        `lease` in interface `ConnPool<T,E extends PoolEntry<T,C>>`
      Parameters:
        `route` - route of the connection.
        `state` - arbitrary object that represents a particular state (usually a security principal or a unique token identifying the user whose credentials have been used while establishing the connection). May be `null`.
        `callback` - operation completion callback.
      Returns:
        future for a leased pool entry.

    - #### lease

          public Future<E> lease(T route,
                        Object state)

      Attempts to lease a connection for the given route and with the given state from the pool.

      Please note that this class does not maintain its own pool of execution `Thread`s. Therefore, one must call `Future.get()` or `Future.get(long, TimeUnit)` method on the `Future` returned by this method in order for the lease operation to complete.
      Parameters:
        `route` - route of the connection.
        `state` - arbitrary object that represents a particular state (usually a security principal or a unique token identifying the user whose credentials have been used while establishing the connection). May be `null`.
      Returns:
        future for a leased pool entry.

    - #### release

          public void release(E entry,
                     boolean reusable)

      Description copied from interface: `ConnPool`
      Releases the pool entry back to the pool.
      Specified by:
        `release` in interface `ConnPool<T,E extends PoolEntry<T,C>>`
      Parameters:
        `entry` - pool entry leased from the pool
        `reusable` - flag indicating whether or not the released connection is in a consistent state and is safe for further use.

    - #### setMaxTotal

          public void setMaxTotal(int max)

      Specified by:
        `setMaxTotal` in interface `ConnPoolControl<T>`

    - #### getMaxTotal

          public int getMaxTotal()

      Specified by:
        `getMaxTotal` in interface `ConnPoolControl<T>`

    - #### setDefaultMaxPerRoute

          public void setDefaultMaxPerRoute(int max)

      Specified by:
        `setDefaultMaxPerRoute` in interface `ConnPoolControl<T>`

    - #### getDefaultMaxPerRoute

          public int getDefaultMaxPerRoute()

      Specified by:
        `getDefaultMaxPerRoute` in interface `ConnPoolControl<T>`

    - #### setMaxPerRoute

          public void setMaxPerRoute(T route,
                            int max)

      Specified by:
        `setMaxPerRoute` in interface `ConnPoolControl<T>`

    - #### getMaxPerRoute

          public int getMaxPerRoute(T route)

      Specified by:
        `getMaxPerRoute` in interface `ConnPoolControl<T>`

    - #### getTotalStats

          public PoolStats getTotalStats()

      Specified by:
        `getTotalStats` in interface `ConnPoolControl<T>`

    - #### getStats

          public PoolStats getStats(T route)

      Specified by:
        `getStats` in interface `ConnPoolControl<T>`

    - #### enumAvailable

          protected void enumAvailable(PoolEntryCallback<T,C> callback)

      Enumerates all available connections.
      Since:
        4.3

    - #### enumLeased

          protected void enumLeased(PoolEntryCallback<T,C> callback)

      Enumerates all leased connections.
      Since:
        4.3

    - #### closeIdle

          public void closeIdle(long idletime,
                       TimeUnit tunit)

      Closes connections that have been idle longer than the given period of time and evicts them from the pool.
      Parameters:
        `idletime` - maximum idle time.
        `tunit` - time unit.

    - #### closeExpired

          public void closeExpired()

      Closes expired connections and evicts them from the pool.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2005–2013 The Apache Software Foundation. All rights reserved.