Class LazyPool

  • All Implemented Interfaces:

    
    public final class LazyPool<A extends Object>
    
                        

    A lazy pool of resources A.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      LazyPool(Function1<A, Unit> clear, Function1<A, Boolean> shouldReturnToPool, Integer bound, Function0<A> newInstance)
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final A borrow()
      final Unit release(A instance)
      final Iterable<A> close() Closes the pool.
      final <R extends Any> R run(Function1<A, R> withInstance)
      final <R extends Any> R reentrantRun(Function1<A, R> withInstance)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LazyPool

        LazyPool(Function1<A, Unit> clear, Function1<A, Boolean> shouldReturnToPool, Integer bound, Function0<A> newInstance)
        Parameters:
        clear - If specified this function will be run on each borrowed instance before handing it over.
        shouldReturnToPool - If specified this function will be run on each release to determine whether the instance should be returned to the pool for reuse.
        bound - If specified the pool will be bounded.
        newInstance - The function to call to lazily newInstance a pooled resource.
    • Method Detail

      • close

         final Iterable<A> close()

        Closes the pool. Note that all borrowed instances must have been released before calling this function, otherwise the returned iterable will be inaccurate.

      • run

         final <R extends Any> R run(Function1<A, R> withInstance)