- 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 Summary
Modifier and Type Method Description CompletableFuture<T>create()Create an instance that can be served by the pool and wrap it in aPooledObjectto be managed by the pool.CompletableFuture<Void>destroy(T object)Destroys an instance no longer needed by the pool.CompletableFuture<Boolean>validate(T object)Ensures that the instance is safe to be returned by the pool.
-
Method Details
-
create
CompletableFuture<T> create()Create an instance that can be served by the pool and wrap it in aPooledObjectto be managed by the pool.- Returns:
- a
PooledObjectwrapping an instance that can be served by the pool
-
destroy
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
objectwill 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- aPooledObjectwrapping the instance to be destroyed- See Also:
validate(T)
-
validate
Ensures that the instance is safe to be returned by the pool.- Parameters:
object- aPooledObjectwrapping the instance to be validated- Returns:
falseifobjectis not valid and should be dropped from the pool,trueotherwise.
-