Class IdleConnectionSweeper
java.lang.Object
net.shibboleth.utilities.java.support.httpclient.IdleConnectionSweeper
- All Implemented Interfaces:
Component
,DestructableComponent
A utility that periodically closes idle connections held by an
HttpClientConnectionManager
.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.apache.http.conn.HttpClientConnectionManager
HttpClientConnectionManager whose connections will be swept.private boolean
private boolean
Whether this sweeper has been destroyed.private Instant
Time at which the sweeper last executed.private final TimerTask
Sweeping task executed by the timer.private final Timer
Timer used to schedule and execute the sweeping task. -
Constructor Summary
ConstructorsConstructorDescriptionIdleConnectionSweeper
(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
Modifier and TypeMethodDescriptionvoid
destroy()
Destroys the component.boolean
Gets whether this component has been destroyed.Gets the time when the sweeper last executed or, if it has not yet executed, when it was first scheduled to run.
-
Field Details
-
destroyed
private boolean destroyedWhether this sweeper has been destroyed. -
createdTimer
private boolean createdTimer -
executionTime
Time at which the sweeper last executed. -
connectionManager
@Nonnull private final org.apache.http.conn.HttpClientConnectionManager connectionManagerHttpClientConnectionManager whose connections will be swept. -
taskTimer
Timer used to schedule and execute the sweeping task. -
sweeper
Sweeping task executed by the timer.
-
-
Constructor Details
-
IdleConnectionSweeper
public IdleConnectionSweeper(@Nonnull org.apache.http.conn.HttpClientConnectionManager manager, @Nonnull Duration idleTimeout, @Nonnull Duration sweepInterval) Constructor. This method will create a daemonTimer
and 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 Details
-
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:
isDestroyed
in interfaceDestructableComponent
- Returns:
- true iff the component has been destroyed
-
destroy
public void destroy()Destroys the component.- Specified by:
destroy
in interfaceDestructableComponent
-