Package reactor.pool
Interface PooledRef<POOLABLE>
public interface PooledRef<POOLABLE>
An abstraction over an object in a
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()).- Author:
- Simon Baslé
-
Method Summary
Modifier and TypeMethodDescriptionReturn aMonothat triggers the asynchronous invalidation of thePOOLABLEwhen subscribed.metadata()Returns aPooledRefMetadataobject that holds more information about the reference (rather than thepoolable()), like how many times it was acquired, its age (time since allocation), etc...poolable()Returns the wrappedPOOLABLE.release()Return aMonothat, once subscribed, will release thePOOLABLEback to the pool asynchronously.
-
Method Details
-
poolable
POOLABLE poolable()Returns the wrappedPOOLABLE. This method is not thread-safe and the poolable should NEVER be accessed concurrently.The reference is retained by the
PooledRefbut the object might be in an intermediate or invalid state when one of therelease()orinvalidate()methods have been previously called.- Returns:
- the poolable
-
metadata
PooledRefMetadata metadata()Returns aPooledRefMetadataobject that holds more information about the reference (rather than thepoolable()), like how many times it was acquired, its age (time since allocation), etc...Note that if
release()orinvalidate()have been invoked, this method might return stale information.- Returns:
- the
PooledRefMetadatafor thisPooledRef
-
invalidate
Return aMonothat triggers the asynchronous invalidation of thePOOLABLEwhen 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. -
release
Return aMonothat, once subscribed, will release thePOOLABLEback 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 underlyingpoolable()at this point,metadata()might become stale, and usage of bothinvalidate()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.- Returns:
- a
Monothat will complete empty when the object has been released. In case of an error the object is always discarded
-