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 Type
    Method
    Description
    Return a Mono that triggers the asynchronous invalidation of the POOLABLE when subscribed.
    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...
    Returns the wrapped POOLABLE.
    Return a Mono that, once subscribed, will release the POOLABLE back to the pool asynchronously.
  • Method Details

    • poolable

      POOLABLE poolable()
      Returns the wrapped 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.

      Returns:
      the poolable
    • metadata

      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...

      Note that if release() or invalidate() have been invoked, this method might return stale information.

      Returns:
      the PooledRefMetadata for this PooledRef
    • invalidate

      Mono<Void> invalidate()
      Return a 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.

    • release

      Mono<Void> release()
      Return a 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.

      Returns:
      a Mono that will complete empty when the object has been released. In case of an error the object is always discarded