net.shibboleth.utilities.java.support.httpclient
Class IdleConnectionSweeper

java.lang.Object
  extended by 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 a HttpClient.


Field Summary
private  HttpClient client
          Client whose connections will be swept.
private  boolean createdTimer
          Whether this sweeper created a TimerTask to use and thus should destroy when destroy() is invoked.
private  boolean destroyed
          Whether this sweeper has been destroyed.
private  TimerTask sweeper
          Sweeping task executed by the timer.
private  Timer taskTimer
          Timer used to schedule and execute the sweeping task.
 
Constructor Summary
IdleConnectionSweeper(HttpClient httpClient, long idleTimeout, long sweepInterval)
          Constructor.
IdleConnectionSweeper(HttpClient httpClient, long idleTimeout, long sweepInterval, Timer backgroundTimer)
          Constructor.
 
Method Summary
 void destroy()
          Destroys the component.
 boolean isDestroyed()
          Gets whether this component has been destroyed.
 long scheduledExecutionTime()
          Gets the time, in milliseconds since the epoch, when the sweeper last executed or, if it has not yet executed, when it was first scheduled to run.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

destroyed

private boolean destroyed
Whether this sweeper has been destroyed.


createdTimer

private boolean createdTimer
Whether this sweeper created a TimerTask to use and thus should destroy when destroy() is invoked.


client

private final HttpClient client
Client whose connections will be swept.


taskTimer

private final Timer taskTimer
Timer used to schedule and execute the sweeping task.


sweeper

private final TimerTask sweeper
Sweeping task executed by the timer.

Constructor Detail

IdleConnectionSweeper

public IdleConnectionSweeper(@Nonnull
                             HttpClient httpClient,
                             long idleTimeout,
                             long sweepInterval)
Constructor. This method will create a daemon Timer and use it to periodically sweep connections.

Parameters:
httpClient - client whose connections will be swept
idleTimeout - length of time, in milliseconds, connection may be idle before being closed down
sweepInterval - length of time, in milliseconds, between sweeps

IdleConnectionSweeper

public IdleConnectionSweeper(@Nonnull
                             HttpClient httpClient,
                             long idleTimeout,
                             long sweepInterval,
                             @Nonnull
                             Timer backgroundTimer)
Constructor.

Parameters:
httpClient - client whose connections will be swept
idleTimeout - length of time, in milliseconds, connection may be idle before being closed down
sweepInterval - length of time, in milliseconds, between sweeps
backgroundTimer - timer used to schedule the background sweeping task
Method Detail

scheduledExecutionTime

public long scheduledExecutionTime()
Gets the time, in milliseconds since the epoch, 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 is can not be used.

Specified by:
isDestroyed in interface DestructableComponent
Returns:
true if the component has been destroyed, false if not

destroy

public void destroy()
Destroys the component.

Specified by:
destroy in interface DestructableComponent


Copyright © 1999-2012. All Rights Reserved.