Class AgePruneStrategy

All Implemented Interfaces:
Consumer<Supplier<Iterator<PooledConnectionProxy>>>, Freezable, PruneStrategy
Direct Known Subclasses:
IdlePruneStrategy

public class AgePruneStrategy extends AbstractPruneStrategy
Removes connections from the pool based on how long they have existed. By default, this implementation executes every 30 minutes and prunes connections that have existed for more than 1 hour. Setting an age time of zero means that no connections will be pruned by this strategy. This strategy will prune available connections below the minimum pool size. This strategy will also only prune connections that have a higher priority if prunePriority is set. The higher the priority the quicker the connection will be removed.
  • Field Details

    • DEFAULT_AGE_TIME

      private static final Duration DEFAULT_AGE_TIME
      Default age time. Value is 1 hour.
    • ageTime

      private Duration ageTime
      Age time.
    • prunePriority

      private int prunePriority
      Threshold at which to prune connections based on their priority. Connections with a priority >= to this value will be pruned.
    • prunePriorityFactor

      private int prunePriorityFactor
      Factor to apply to LdapURL.getPriority() in order to provide inverse backoff of the ageTime based on priority.
  • Constructor Details

    • AgePruneStrategy

      public AgePruneStrategy()
      Creates a new age prune strategy.
    • AgePruneStrategy

      public AgePruneStrategy(Duration age)
      Creates a new age prune strategy. Sets the prune period to half of the supplied age time.
      Parameters:
      age - time at which a connection should be pruned
    • AgePruneStrategy

      public AgePruneStrategy(Duration period, Duration age)
      Creates a new age prune strategy.
      Parameters:
      period - to execute the prune task
      age - time at which a connection should be pruned
  • Method Details

    • getPruneConditions

      public List<Predicate<PooledConnectionProxy>> getPruneConditions()
      Description copied from class: AbstractPruneStrategy
      Returns the predicates used by this prune strategy. Each predicate will be invoked for every connection to be pruned.
      Specified by:
      getPruneConditions in class AbstractPruneStrategy
      Returns:
      List of predicates that are evaluated in order. Connections are removed from the pool immediately upon predicate returning true; subsequent predicates operate on a reduced pool.
    • getStatisticsSize

      public int getStatisticsSize()
      Description copied from interface: PruneStrategy
      Returns the number of statistics to store for this prune strategy. See PooledConnectionStatistics.
      Returns:
      number of statistics to store
    • getAgeTime

      public Duration getAgeTime()
      Returns the age time.
      Returns:
      age time
    • setAgeTime

      public void setAgeTime(Duration time)
      Sets the age time.
      Parameters:
      time - since a connection has been created and should be pruned
    • getPrunePriority

      public int getPrunePriority()
      Returns the prune priority.
      Returns:
      priority value at which to prune
    • setPrunePriority

      public void setPrunePriority(int i)
      Sets the prune priority.
      Parameters:
      i - priority value at which to prune
    • getPrunePriorityFactor

      public int getPrunePriorityFactor()
      Returns the prune priority factor.
      Returns:
      factor to multiply by URL priority for inverse backoff of ageTime
    • setPrunePriorityFactor

      public void setPrunePriorityFactor(int i)
      Sets the prune priority factor.
      Parameters:
      i - prune priority factor
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • builder

      public static AgePruneStrategy.Builder builder()
      Creates a builder for this class.
      Returns:
      new builder