tuwien.auto.calimero.buffer.cache
Class CacheSweeper

java.lang.Object
  extended by java.lang.Thread
      extended by tuwien.auto.calimero.buffer.cache.CacheSweeper
All Implemented Interfaces:
java.lang.Runnable

public final class CacheSweeper
extends java.lang.Thread

Used to remove expired entries from a cache.

The cache sweeper is running in its own thread, waking up for work every sweep time interval set by the user. Then Cache.removeExpired() is invoked on the specified cache.

See Also:
Cache

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
CacheSweeper(Cache cache, int sweepInterval)
          Creates a CacheSweeper for cache with the given sweepInterval.
 
Method Summary
 int getSweepInterval()
          Returns the time interval between Cache.removeExpired() calls used by this cache sweeper.
 void run()
           
 void setSweepInterval(int interval)
          Sets a new sweep interval.
 void stopSweeper()
          Stops the sweeper and quits the thread.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CacheSweeper

public CacheSweeper(Cache cache,
                    int sweepInterval)
Creates a CacheSweeper for cache with the given sweepInterval.

Parameters:
cache - the cache for which Cache.removeExpired() should be invoked
sweepInterval - lapse of time between sweeping in seconds
Method Detail

getSweepInterval

public int getSweepInterval()
Returns the time interval between Cache.removeExpired() calls used by this cache sweeper.

Returns:
the time in seconds

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

setSweepInterval

public void setSweepInterval(int interval)
Sets a new sweep interval.

If the cache sweeper is in waiting state for next sweep, the new interval is immediately applied and checked against elapsed time.

Parameters:
interval - new time interval between sweeping in seconds

stopSweeper

public void stopSweeper()
Stops the sweeper and quits the thread.