Class IdleConnectionSweeper
- java.lang.Object
-
- net.shibboleth.utilities.java.support.httpclient.IdleConnectionSweeper
-
- All Implemented Interfaces:
Component,DestructableComponent
public class IdleConnectionSweeper extends Object implements DestructableComponent
A utility that periodically closes idle connections held by anHttpClientConnectionManager.
-
-
Field Summary
Fields Modifier and Type Field Description private org.apache.http.conn.HttpClientConnectionManagerconnectionManagerHttpClientConnectionManager whose connections will be swept.private booleancreatedTimerprivate booleandestroyedWhether this sweeper has been destroyed.private InstantexecutionTimeTime at which the sweeper last executed.private TimerTasksweeperSweeping task executed by the timer.private TimertaskTimerTimer used to schedule and execute the sweeping task.
-
Constructor Summary
Constructors Constructor Description IdleConnectionSweeper(org.apache.http.conn.HttpClientConnectionManager manager, Duration idleTimeout, Duration sweepInterval)Constructor.IdleConnectionSweeper(org.apache.http.conn.HttpClientConnectionManager manager, Duration idleTimeout, Duration sweepInterval, Timer backgroundTimer)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy()Destroys the component.booleanisDestroyed()Gets whether this component has been destroyed.InstantscheduledExecutionTime()Gets the time when the sweeper last executed or, if it has not yet executed, when it was first scheduled to run.
-
-
-
Field Detail
-
destroyed
private boolean destroyed
Whether this sweeper has been destroyed.
-
createdTimer
private boolean createdTimer
-
executionTime
@Nullable private Instant executionTime
Time at which the sweeper last executed.
-
connectionManager
@Nonnull private final org.apache.http.conn.HttpClientConnectionManager connectionManager
HttpClientConnectionManager whose connections will be swept.
-
taskTimer
@Nonnull private final Timer taskTimer
Timer used to schedule and execute the sweeping task.
-
sweeper
@Nonnull private final TimerTask sweeper
Sweeping task executed by the timer.
-
-
Constructor Detail
-
IdleConnectionSweeper
public IdleConnectionSweeper(@Nonnull org.apache.http.conn.HttpClientConnectionManager manager, @Nonnull Duration idleTimeout, @Nonnull Duration sweepInterval)Constructor. This method will create a daemonTimerand use it to periodically sweep connections.- Parameters:
manager- HTTP client connection manager whose connections will be sweptidleTimeout- length of time connection may be idle before being closed downsweepInterval- length of time between sweeps
-
IdleConnectionSweeper
public IdleConnectionSweeper(@Nonnull org.apache.http.conn.HttpClientConnectionManager manager, @Nonnull Duration idleTimeout, @Nonnull Duration sweepInterval, @Nonnull Timer backgroundTimer)Constructor.- Parameters:
manager- HTTP client connection manager whose connections will be sweptidleTimeout- length of time connection may be idle before being closed downsweepInterval- length of time between sweepsbackgroundTimer- timer used to schedule the background sweeping task
-
-
Method Detail
-
scheduledExecutionTime
@Nonnull public Instant scheduledExecutionTime()
Gets the time when the sweeper last executed or, if it has not yet executed, when it was first scheduled to run.- Returns:
- the time when the sweeper last executed or when it was first scheduled to run
-
isDestroyed
public boolean isDestroyed()
Gets whether this component has been destroyed. Normally, once a component has been destroyed it cannot be used.- Specified by:
isDestroyedin interfaceDestructableComponent- Returns:
- true iff the component has been destroyed
-
destroy
public void destroy()
Destroys the component.- Specified by:
destroyin interfaceDestructableComponent
-
-