Package org.ldaptive.pool
Class IdlePruneStrategy
- java.lang.Object
-
- org.ldaptive.AbstractFreezable
-
- org.ldaptive.pool.AbstractPruneStrategy
-
- org.ldaptive.pool.AgePruneStrategy
-
- org.ldaptive.pool.IdlePruneStrategy
-
- All Implemented Interfaces:
Consumer<Supplier<Iterator<PooledConnectionProxy>>>
,Freezable
,PruneStrategy
public class IdlePruneStrategy extends AgePruneStrategy
Removes connections from the pool based on how long they have been idle in the available queue. By default, this implementation executes every 5 minutes and prunes connections that have been idle for more than 10 minutes. This strategy will not prune available connections below the minimum pool size unless an age time is configured. Connections will be pruned by age before they are pruned by idle time.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
IdlePruneStrategy.Builder
Idle 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 static Duration
DEFAULT_IDLE_TIME
Default idle time.private Duration
idleTime
Idle time.-
Fields inherited from class org.ldaptive.pool.AbstractPruneStrategy
logger
-
-
Constructor Summary
Constructors Constructor Description IdlePruneStrategy()
Creates a new idle prune strategy.IdlePruneStrategy(Duration idle)
Creates a new idle prune strategy.IdlePruneStrategy(Duration period, Duration idle)
Creates a new idle prune strategy.IdlePruneStrategy(Duration period, Duration idle, Duration age)
Creates a new idle prune strategy.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static IdlePruneStrategy.Builder
builder()
Creates a builder for this class.Duration
getIdleTime()
Returns the idle time.List<Predicate<PooledConnectionProxy>>
getPruneConditions()
Returns the predicates used by this prune strategy.int
getStatisticsSize()
Returns the number of statistics to store for this prune strategy.void
setIdleTime(Duration time)
Sets the idle time.String
toString()
-
Methods inherited from class org.ldaptive.pool.AgePruneStrategy
getAgeTime, getPrunePriority, setAgeTime, setPrunePriority
-
Methods inherited from class org.ldaptive.pool.AbstractPruneStrategy
accept, getPrunePeriod, setPrunePeriod
-
Methods inherited from class org.ldaptive.AbstractFreezable
assertMutable, freeze, freeze, freeze, isFrozen
-
-
-
-
Constructor Detail
-
IdlePruneStrategy
public IdlePruneStrategy()
Creates a new idle prune strategy.
-
IdlePruneStrategy
public IdlePruneStrategy(Duration idle)
Creates a new idle prune strategy. Sets the prune period to half of the supplied idle time.- Parameters:
idle
- time at which a connection should be pruned
-
IdlePruneStrategy
public IdlePruneStrategy(Duration period, Duration idle)
Creates a new idle prune strategy.- Parameters:
period
- to execute the prune taskidle
- 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.- Overrides:
getPruneConditions
in classAgePruneStrategy
- 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
.- Specified by:
getStatisticsSize
in interfacePruneStrategy
- Overrides:
getStatisticsSize
in classAgePruneStrategy
- Returns:
- number of statistics to store
-
getIdleTime
public Duration getIdleTime()
Returns the idle time.- Returns:
- idle time
-
setIdleTime
public void setIdleTime(Duration time)
Sets the idle time.- Parameters:
time
- that a connection has been idle and should be pruned
-
toString
public String toString()
- Overrides:
toString
in classAgePruneStrategy
-
builder
public static IdlePruneStrategy.Builder builder()
Creates a builder for this class.- Returns:
- new builder
-
-