Package org.ldaptive.pool
Class AgePruneStrategy
- java.lang.Object
-
- org.ldaptive.AbstractFreezable
-
- org.ldaptive.pool.AbstractPruneStrategy
-
- org.ldaptive.pool.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 ifprunePriority
is set. The higher the priority the quicker the connection will be removed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AgePruneStrategy.Builder
Age prune strategy builder.-
Nested classes/interfaces inherited from class org.ldaptive.pool.AbstractPruneStrategy
AbstractPruneStrategy.AbstractBuilder<B,T extends AbstractPruneStrategy>
-
-
Field Summary
Fields Modifier and Type Field Description private Duration
ageTime
Age time.private static Duration
DEFAULT_AGE_TIME
Default age time.private long
prunePriority
Threshold at which to prune connections based on their priority.-
Fields inherited from class org.ldaptive.pool.AbstractPruneStrategy
logger
-
-
Constructor Summary
Constructors Constructor Description AgePruneStrategy()
Creates a new age prune strategy.AgePruneStrategy(Duration age)
Creates a new age prune strategy.AgePruneStrategy(Duration period, Duration age)
Creates a new age prune strategy.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static AgePruneStrategy.Builder
builder()
Creates a builder for this class.Duration
getAgeTime()
Returns the age time.List<Predicate<PooledConnectionProxy>>
getPruneConditions()
Returns the predicates used by this prune strategy.long
getPrunePriority()
Returns the prune priority.int
getStatisticsSize()
Returns the number of statistics to store for this prune strategy.void
setAgeTime(Duration time)
Sets the age time.void
setPrunePriority(long l)
Sets the prune priority.String
toString()
-
Methods inherited from class org.ldaptive.pool.AbstractPruneStrategy
accept, getPrunePeriod, setPrunePeriod
-
Methods inherited from class org.ldaptive.AbstractFreezable
assertMutable, freeze, freeze, freeze, isFrozen
-
-
-
-
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
-
-
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 classAbstractPruneStrategy
- 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. SeePooledConnectionStatistics
.- 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
-
builder
public static AgePruneStrategy.Builder builder()
Creates a builder for this class.- Returns:
- new builder
-
-