Class Cleanup<K,V>
- java.lang.Object
-
- java.lang.Thread
-
- edu.uiuc.ncsa.security.core.cache.MyThread
-
- edu.uiuc.ncsa.security.core.cache.Cleanup<K,V>
-
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
LockingCleanup
public class Cleanup<K,V> extends MyThread
General utility for applying retention policies to maps (which covers all caching as well as stores). This may be used either directly by callingage()
or by running this as a thread.Use
Create an instance of this either
- as <
Identifiable
,CachedObject
> for caches - as <key, value> for a map or store.
RetentionPolicy
so that the cleanup knows when to expunge entries (there are several possible policies and you can have as many as you want, though it is up to you to ensure your policies make sense.) Start this in its own thread and it will quietly clean up ever so often. To stop the thread, call theMyThread.setStopThread(boolean)
to true and the thread will halt as soon as it wakes up. YOu can also kill the thread directly but generally that can do bad things if the thread is in the middle of, say, updating you store. Most web servers will wait until all threads exit of their own accord before finishing a shutdown, incidentally.Created by Jeff Gaynor
on 7/12/11 at 11:39 AM
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
-
Field Summary
Fields Modifier and Type Field Description static Identifier
lockID
-
Fields inherited from class edu.uiuc.ncsa.security.core.cache.MyThread
cleanupInterval
-
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description Cleanup(MyLoggingFacade logger, String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRetentionPolicy(RetentionPolicy retentionPolicy)
List<V>
age()
List<String>
getFailures()
List of failures.Map<K,V>
getMap()
List<RetentionPolicy>
getRetentionPolicies()
Set<K>
getSortedKeys()
Return all the keys for the map, sorted into a some order, usually by timestamp.Store
getStore()
void
info(List<V> removed)
Log the results of this.boolean
isEnabledLocking()
boolean
isFailOnError()
If this set true, then any failures cause the cleanup to stop.
If false, then this will attempt to remove all elements.protected List<V>
oldAge()
Clean out old entries by aging the elements, i.e., apply the retention policies.void
removeRetentionPolicy(RetentionPolicy retentionPolicy)
void
run()
void
setEnabledLocking(boolean enabledLocking)
void
setFailOnError(boolean failOnError)
void
setMap(Map<K,V> map)
void
setRetentionPolicies(LinkedList<RetentionPolicy> retentionPolicies)
void
setStore(Store store)
-
Methods inherited from class edu.uiuc.ncsa.security.core.cache.MyThread
debug, debug, getAlarms, getCleanupInterval, getNextSleepInterval, info, isStopThread, isTestMode, setAlarms, setCleanupInterval, setStopThread, setTestMode, warn
-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
lockID
public static Identifier lockID
-
-
Constructor Detail
-
Cleanup
public Cleanup(MyLoggingFacade logger, String name)
-
-
Method Detail
-
isFailOnError
public boolean isFailOnError()
If this set true, then any failures cause the cleanup to stop.
If false, then this will attempt to remove all elements. Failures are logged in thegetFailures()
list.- Returns:
-
setFailOnError
public void setFailOnError(boolean failOnError)
-
isEnabledLocking
public boolean isEnabledLocking()
-
setEnabledLocking
public void setEnabledLocking(boolean enabledLocking)
-
info
public void info(List<V> removed)
Log the results of this. Override this if you need more detailed output. It takes the list of removed entries. Actual writing to the log is done with the callMyThread.info(String)
.- Parameters:
removed
-
-
getFailures
public List<String> getFailures()
List of failures. Each entry is for the formid: message
- Returns:
-
getStore
public Store getStore()
-
setStore
public void setStore(Store store)
-
oldAge
protected List<V> oldAge()
Clean out old entries by aging the elements, i.e., apply the retention policies. Returns a list of the entries removed
-
getSortedKeys
public Set<K> getSortedKeys()
Return all the keys for the map, sorted into a some order, usually by timestamp. The default assumes that the keys are comparable and orders them. Override as needed.- Returns:
-
addRetentionPolicy
public void addRetentionPolicy(RetentionPolicy retentionPolicy)
-
removeRetentionPolicy
public void removeRetentionPolicy(RetentionPolicy retentionPolicy)
-
getRetentionPolicies
public List<RetentionPolicy> getRetentionPolicies()
-
setRetentionPolicies
public void setRetentionPolicies(LinkedList<RetentionPolicy> retentionPolicies)
-
-