public interface PooledRef<POOLABLE>
Pool
, which holds the underlying POOLABLE
object and allows one to
manually release()
it to the pool or invalidate()
it. Through its metadata()
,
the PooledRef
provides a few additional information about its lifecycle, like its age and the number of times
it has been acquired, so the Pool
may optionally use that information to automatically invalidate
the object, and provide a simplified acquire mechanism where the PooledRef
is not directly exposed (see
Pool.withPoolable(Function)
vs Pool.acquire()
).Modifier and Type | Method and Description |
---|---|
Mono<Void> |
invalidate()
Return a
Mono that triggers the asynchronous invalidation of the POOLABLE when subscribed. |
PooledRefMetadata |
metadata()
Returns a
PooledRefMetadata object that holds more information about the reference (rather
than the poolable() ), like how many times it was acquired, its age (time since allocation), etc... |
POOLABLE |
poolable()
Returns the wrapped
POOLABLE . |
Mono<Void> |
release()
Return a
Mono that, once subscribed, will release the POOLABLE back to the pool asynchronously. |
POOLABLE poolable()
POOLABLE
. This method is not thread-safe and the poolable should NEVER be accessed
concurrently.
The reference is retained by the PooledRef
but the object might be in an intermediate or invalid state
when one of the release()
or invalidate()
methods have been previously called.
PooledRefMetadata metadata()
PooledRefMetadata
object that holds more information about the reference (rather
than the poolable()
), like how many times it was acquired, its age (time since allocation), etc...
Note that if release()
or invalidate()
have been invoked, this method might return stale information.
PooledRefMetadata
for this PooledRef
Mono<Void> invalidate()
Mono
that triggers the asynchronous invalidation of the POOLABLE
when subscribed.
The object is always discarded by the pool and not further reused.
This is useful when the unhealthy state of the resource (or lack of re-usability) is detected through the usage of the resource, as opposed to its exposed state.
Note that if release()
has been invoked, this method should be no-op.
Mono<Void> release()
Mono
that, once subscribed, will release the POOLABLE
back to the pool asynchronously.
Once released, a reference is considered out of the control of the user and shouldn't be usable anymore.
It is discouraged to use the underlying poolable()
at this point, metadata()
might become stale,
and usage of both invalidate()
and release() should be no-op.
This method is idempotent (subsequent subscriptions to the same Mono, or re-invocations of the method
are NO-OP). It is also no-op if invalidate()
has previously been invoked.
Mono
that will complete empty when the object has been released. In case of an error the object
is always discarded