Interface ConnectionProvider.AllocationStrategy<A extends ConnectionProvider.AllocationStrategy<A>>

All Known Implementing Classes:
Http2AllocationStrategy
Enclosing interface:
ConnectionProvider

public static interface ConnectionProvider.AllocationStrategy<A extends ConnectionProvider.AllocationStrategy<A>>
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns a deep copy of this instance.
    int
    Best-effort peek at the state of the strategy which indicates roughly how many more connections can currently be allocated.
    int
    getPermits(int desired)
    Try to get the permission to allocate a desired positive number of new connections.
    int
    Returns the best estimate of the number of permits currently granted, between 0 and Integer.MAX_VALUE.
    int
    Returns the maximum number of permits this strategy can grant in total, or Integer.MAX_VALUE for unbounded.
    int
    Return the minimum number of permits this strategy tries to maintain granted (reflecting a minimal size for the pool), or 0 for scale-to-zero.
    void
    returnPermits(int returned)
    Update the strategy to indicate that N connections were discarded, potentially leaving space for N new ones to be allocated.
  • Method Details

    • copy

      A copy()
      Returns a deep copy of this instance.
      Returns:
      a deep copy of this instance
    • estimatePermitCount

      int estimatePermitCount()
      Best-effort peek at the state of the strategy which indicates roughly how many more connections can currently be allocated. Should be paired with getPermits(int) for an atomic permission.
      Returns:
      an ESTIMATED count of how many more connections can currently be allocated
    • getPermits

      int getPermits(int desired)
      Try to get the permission to allocate a desired positive number of new connections. Returns the permissible number of connections which MUST be created (otherwise the internal live counter of the strategy might be off). This permissible number might be zero, and it can also be a greater number than desired. Once a connection is discarded from the pool, it must update the strategy using returnPermits(int) (which can happen in batches or with value 1).
      Parameters:
      desired - the desired number of new connections
      Returns:
      the actual number of new connections that MUST be created, can be 0 and can be more than desired
    • permitGranted

      int permitGranted()
      Returns the best estimate of the number of permits currently granted, between 0 and Integer.MAX_VALUE.
      Returns:
      the best estimate of the number of permits currently granted, between 0 and Integer.MAX_VALUE
    • permitMinimum

      int permitMinimum()
      Return the minimum number of permits this strategy tries to maintain granted (reflecting a minimal size for the pool), or 0 for scale-to-zero.
      Returns:
      the minimum number of permits this strategy tries to maintain, or 0
    • permitMaximum

      int permitMaximum()
      Returns the maximum number of permits this strategy can grant in total, or Integer.MAX_VALUE for unbounded.
      Returns:
      the maximum number of permits this strategy can grant in total, or Integer.MAX_VALUE for unbounded
    • returnPermits

      void returnPermits(int returned)
      Update the strategy to indicate that N connections were discarded, potentially leaving space for N new ones to be allocated. Users MUST ensure that this method isn't called with a value greater than the number of held permits it has.

      Some strategy MIGHT throw an IllegalArgumentException if it can be determined the number of returned permits is not consistent with the strategy's limits and delivered permits.