Interface PoolObjectFactory<T>

Type Parameters:
T - the type of objects held in the client object pool

public interface PoolObjectFactory<T>
Defines the interface that will be implemented by the factory used by the object pools defined in the package, in order to control the lifecycle of the objects in the pools.
Author:
Simeon Malchev
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new object for the calling object pool.
    void
    destroy(T obj)
    A method which will be called when an object from the object pool needs to be destroyed, which is when the readyToTake(T) or readyToRestore(T) methods have returned false, or when the pool is shrinking its size (via calling reduceCreatedBy/To), or when the pool is terminating.
    boolean
    A validation/passivation hook which will be called by the restore methods of ConcurrentPool when an object taken before that from the object pool is about to be restored (returned back) to the pool.
    boolean
    A validation/activation hook which will be called by the take... methods of ConcurrentPool when an object from the object pool is requested by the application.
  • Method Details

    • create

      T create()
      Creates a new object for the calling object pool. This object is presumed to be ready (and valid) for immediate use. Should never return null.

      This method will be called by the constructors of ConcurrentPool, and by any of its take... methods if they were able to obtain a permit from the counting Semaphore guarding the pool, but there was no ready and valid object in the pool. I.e., this is the case when a new object is created lazily in the pool upon request.

      Returns:
      a new object for this object pool
    • readyToTake

      boolean readyToTake(T obj)
      A validation/activation hook which will be called by the take... methods of ConcurrentPool when an object from the object pool is requested by the application. This is an optional operation which concrete implementation may simply always return true.

      If there is a particular activation or validation which needs to be done for the taken from the pool object, this is the ideal place where it can be done.

      Parameters:
      obj - an object which is taken from the object pool and which is to be given to the calling application
      Returns:
      true if the validation/activation is successful, false otherwise
      See Also:
    • readyToRestore

      boolean readyToRestore(T obj)
      A validation/passivation hook which will be called by the restore methods of ConcurrentPool when an object taken before that from the object pool is about to be restored (returned back) to the pool. This is an optional operation which concrete implementation may simply always return true.

      If there is a particular passivation or validation which needs to be done for the restored to the pool object, this is the ideal place where it can be done.

      Parameters:
      obj - an object which has been taken before that from this object pool and which is now to be restored to the pool
      Returns:
      true if the validation/passivation is successful, false otherwise
      See Also:
    • destroy

      void destroy(T obj)
      A method which will be called when an object from the object pool needs to be destroyed, which is when the readyToTake(T) or readyToRestore(T) methods have returned false, or when the pool is shrinking its size (via calling reduceCreatedBy/To), or when the pool is terminating. The simplest implementation of this method may simply do nothing, however if there are any allocated resources associated with the to-be-destroyed object, like network connections or similar, this is the ideal place where they can be de-allocated.
      Parameters:
      obj - an object from the pool which needs to be destroyed