Interface AsyncObjectFactory<T>

  • Type Parameters:
    T - Type of element managed in this factory.

    public interface AsyncObjectFactory<T>
    An interface defining life-cycle methods for instances to be served by an pool.
    Since:
    5.1
    Author:
    Mark Paluch
    • Method Detail

      • create

        CompletableFuture<T> create()
        Create an instance that can be served by the pool and wrap it in a PooledObject to be managed by the pool.
        Returns:
        a PooledObject wrapping an instance that can be served by the pool
      • destroy

        CompletableFuture<Void> destroy​(T object)
        Destroys an instance no longer needed by the pool.

        It is important for implementations of this method to be aware that there is no guarantee about what state object will be in and the implementation should be prepared to handle unexpected errors.

        Also, an implementation must take in to consideration that instances lost to the garbage collector may never be destroyed.

        Parameters:
        object - a PooledObject wrapping the instance to be destroyed
        See Also:
        validate(T)
      • validate

        CompletableFuture<Boolean> validate​(T object)
        Ensures that the instance is safe to be returned by the pool.
        Parameters:
        object - a PooledObject wrapping the instance to be validated
        Returns:
        false if object is not valid and should be dropped from the pool, true otherwise.