Class AutoReturnableObjectPool<T>

  • Type Parameters:
    T - type of object to pool
    All Implemented Interfaces:
    Closeable, AutoCloseable, org.apache.commons.pool2.impl.GenericObjectPoolMXBean, org.apache.commons.pool2.ObjectPool<AutoReturnable<T>>, org.apache.commons.pool2.UsageTracking<AutoReturnable<T>>

    public final class AutoReturnableObjectPool<T>
    extends org.apache.commons.pool2.impl.GenericObjectPool<AutoReturnable<T>>
    Pool of object to be shared across parallel running tests. As long as a pooled object is borrowed it will not be borrowed to other running test. Borrowed pooled objects shall be returned as soon as possible in order not block other tests running in parallel.
    • Field Summary

      • Fields inherited from class org.apache.commons.pool2.impl.BaseGenericObjectPool

        abandonedConfig, MEAN_TIMING_STATS_CACHE_SIZE
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      AutoReturnable<T> borrowObject()
      Borrows a pooled object and marks it as pooled by this pool.
      static <T> AutoReturnableObjectPool<T> poolFor​(List<T> availableObjects)
      Initializes an object pool.
      static <T> AutoReturnableObjectPool<T> singletonPoolFor​(List<T> availableObjects)
      Initializes a singleton object pool.
      • Methods inherited from class org.apache.commons.pool2.impl.GenericObjectPool

        addObject, borrowObject, borrowObject, clear, close, evict, getFactory, getFactoryType, getMaxIdle, getMinIdle, getNumActive, getNumIdle, getNumWaiters, invalidateObject, invalidateObject, listAllObjects, preparePool, returnObject, setConfig, setMaxIdle, setMinIdle, toStringAppendFields, use
      • Methods inherited from class org.apache.commons.pool2.impl.BaseGenericObjectPool

        getBlockWhenExhausted, getBorrowedCount, getCreatedCount, getCreationStackTrace, getDestroyedByBorrowValidationCount, getDestroyedByEvictorCount, getDestroyedCount, getDurationBetweenEvictionRuns, getEvictionPolicy, getEvictionPolicyClassName, getEvictorShutdownTimeout, getEvictorShutdownTimeoutDuration, getEvictorShutdownTimeoutMillis, getFairness, getJmxName, getLifo, getLogAbandoned, getMaxBorrowWaitDuration, getMaxBorrowWaitTimeMillis, getMaxTotal, getMaxWaitDuration, getMaxWaitMillis, getMeanActiveDuration, getMeanActiveTimeMillis, getMeanBorrowWaitDuration, getMeanBorrowWaitTimeMillis, getMeanIdleDuration, getMeanIdleTimeMillis, getMessageStatistics, getMinEvictableIdleDuration, getMinEvictableIdleTime, getMinEvictableIdleTimeMillis, getNumTestsPerEvictionRun, getRemoveAbandonedOnBorrow, getRemoveAbandonedOnMaintenance, getRemoveAbandonedTimeout, getRemoveAbandonedTimeoutDuration, getReturnedCount, getSoftMinEvictableIdleDuration, getSoftMinEvictableIdleTime, getSoftMinEvictableIdleTimeMillis, getSwallowedExceptionListener, getTestOnBorrow, getTestOnCreate, getTestOnReturn, getTestWhileIdle, getTimeBetweenEvictionRuns, getTimeBetweenEvictionRunsMillis, isAbandonedConfig, isClosed, markReturningState, setAbandonedConfig, setBlockWhenExhausted, setConfig, setDurationBetweenEvictionRuns, setEvictionPolicy, setEvictionPolicyClassName, setEvictionPolicyClassName, setEvictorShutdownTimeout, setEvictorShutdownTimeoutMillis, setLifo, setMaxTotal, setMaxWait, setMaxWaitMillis, setMessagesStatistics, setMinEvictableIdle, setMinEvictableIdleDuration, setMinEvictableIdleTime, setMinEvictableIdleTimeMillis, setNumTestsPerEvictionRun, setSoftMinEvictableIdle, setSoftMinEvictableIdleDuration, setSoftMinEvictableIdleTime, setSoftMinEvictableIdleTimeMillis, setSwallowedExceptionListener, setTestOnBorrow, setTestOnCreate, setTestOnReturn, setTestWhileIdle, setTimeBetweenEvictionRuns, setTimeBetweenEvictionRunsMillis
      • Methods inherited from class org.apache.commons.pool2.BaseObject

        toString
      • Methods inherited from interface org.apache.commons.pool2.impl.GenericObjectPoolMXBean

        getBlockWhenExhausted, getBorrowedCount, getCreatedCount, getCreationStackTrace, getDestroyedByBorrowValidationCount, getDestroyedByEvictorCount, getDestroyedCount, getFairness, getLifo, getLogAbandoned, getMaxBorrowWaitTimeMillis, getMaxTotal, getMaxWaitMillis, getMeanActiveTimeMillis, getMeanBorrowWaitTimeMillis, getMeanIdleTimeMillis, getMinEvictableIdleTimeMillis, getNumTestsPerEvictionRun, getRemoveAbandonedOnBorrow, getRemoveAbandonedOnMaintenance, getRemoveAbandonedTimeout, getReturnedCount, getTestOnBorrow, getTestOnCreate, getTestOnReturn, getTestWhileIdle, getTimeBetweenEvictionRunsMillis, isAbandonedConfig, isClosed
      • Methods inherited from interface org.apache.commons.pool2.ObjectPool

        addObjects
    • Method Detail

      • poolFor

        public static <T> AutoReturnableObjectPool<T> poolFor​(List<T> availableObjects)
        Initializes an object pool.
        Type Parameters:
        T - type of objects to be pooled
        Parameters:
        availableObjects - list of available objects for pooling
        Returns:
        pool for specified type of available objects
        Throws:
        IllegalArgumentException - if list of available objects is empty
      • singletonPoolFor

        public static <T> AutoReturnableObjectPool<T> singletonPoolFor​(List<T> availableObjects)
        Initializes a singleton object pool. Available objects will be fixed at first call.
        Type Parameters:
        T - type of objects to be pooled
        Parameters:
        availableObjects - list of available objects for pooling
        Returns:
        singleton pool for specified type of available objects; further calls will return same pool with same available object as provided at first call
        Throws:
        IllegalArgumentException - if list of available objects is empty
      • borrowObject

        public AutoReturnable<T> borrowObject()
                                       throws Exception
        Borrows a pooled object and marks it as pooled by this pool.
        Specified by:
        borrowObject in interface org.apache.commons.pool2.ObjectPool<T>
        Overrides:
        borrowObject in class org.apache.commons.pool2.impl.GenericObjectPool<AutoReturnable<T>>
        Returns:
        a pooled object
        Throws:
        Exception - if failed to create new pooled object; see AutoReturnableObjectFactory.create()