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 Detail

      • 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 long prunePriority
        Threshold at which to prune connections based on their priority. Connections with a priority >= to this value will be pruned.
    • Constructor Detail

      • 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 Detail

      • 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 long getPrunePriority()
        Returns the prune priority.
        Returns:
        priority value at which to prune
      • setPrunePriority

        public void setPrunePriority​(long l)
        Sets the prune priority.
        Parameters:
        l - priority value at which to prune