Class ReusableObjectFactory<T>

java.lang.Object
com.pnfsoftware.jeb.util.base.ReusableObjectFactory<T>

public class ReusableObjectFactory<T> extends Object
Unbounded, concurrency-friendly object factory for objects that can be used, released, and re-used.
  • Constructor Details

    • ReusableObjectFactory

      public ReusableObjectFactory(Supplier<T> supplier)
      Create a factory.
      Parameters:
      supplier - object creator, must support concurrency (the supplier may be requested to create object by multiple threads at the same time)
  • Method Details

    • getSuppliedCount

      public int getSuppliedCount()
      Get the number of times the supplier created a new object.
      Returns:
      the number of created objects
    • get

      public T get()
      Retrieve or create an object. If all objects created by this factory are in-use, a new object is created.
      Returns:
      an object
    • release

      public void release(T o)
      Release an object provided by ths factory, making it usable by other callers.
      Parameters:
      o - an object provided by get()
    • list

      public List<T> list()
      Get a copy of the list of all objects (in-use and available) created by this factory.
      Returns: